Skip to content

Latest commit

 

History

History
180 lines (131 loc) · 4.99 KB

File metadata and controls

180 lines (131 loc) · 4.99 KB

Enhanced Comment Resolution with GraphQL + REST API

This document explains the enhanced comment resolution feature that combines both GitHub's REST API and GraphQL API for comprehensive comment resolution functionality.

Overview

The enhanced solution provides two levels of comment resolution:

  1. Visual Resolution (REST API): Updates the comment content to show it's been resolved
  2. Native Resolution (GraphQL API): Actually resolves the conversation thread in GitHub's UI

How It Works

Step 1: Visual Resolution (REST API)

  • Fetches the original comment content
  • Appends a resolution notice with the LLM's reasoning
  • Updates the comment body using GitHub's REST API

Step 2: Native Thread Resolution (GraphQL API)

  • Queries GitHub's GraphQL API to find review threads
  • Locates the specific thread containing the resolved comment
  • Uses the resolveReviewThread mutation to mark the conversation as resolved

Implementation Details

REST API Component

// Update comment content to show resolution
await this.octokit.pulls.updateReviewComment({
  owner: this.config.owner,
  repo: this.config.repo,
  comment_id: commentId,
  body: resolvedBody, // Original content + resolution notice
});

GraphQL API Component

// Find the review thread
const findThreadQuery = `
  query FindReviewThread($owner: String!, $repo: String!, $prNumber: Int!) {
    repository(owner: $owner, name: $repo) {
      pullRequest(number: $prNumber) {
        reviewThreads(first: 100) {
          nodes {
            id
            isResolved
            comments(first: 1) {
              nodes {
                databaseId
              }
            }
          }
        }
      }
    }
  }
`;

// Resolve the thread
const graphqlQuery = `
  mutation ResolveReviewThread($threadId: ID!) {
    resolveReviewThread(input: { threadId: $threadId }) {
      thread {
        id
        isResolved
      }
    }
  }
`;

Benefits of This Approach

1. Complete User Experience

  • Comments show clear resolution notices with reasoning
  • Threads are properly collapsed in GitHub's UI
  • Native "resolved" badges appear in the GitHub interface

2. Backward Compatibility

  • Works with existing GitHub review workflows
  • Preserves original comment content
  • Maintains audit trail of resolution reasoning

3. Developer Friendly

  • Resolved conversations are hidden from active discussions
  • Clear visual indicators of what was resolved and why
  • Follows GitHub's native UX patterns

Example Resolution Notice

When a comment is resolved, it gets updated to show:

Consider adding input validation here

---**Resolved by CodePress Review**

> Input validation was added in lines 45-52 using Joi schema validation

And the conversation thread gets natively resolved in GitHub's UI.

Error Handling

The implementation includes comprehensive error handling:

  • Rate Limiting: Automatic retry with exponential backoff
  • GraphQL Errors: Graceful fallback if thread resolution fails
  • Comment Updates: Separate error handling for content updates
  • Thread Discovery: Safe handling when threads can't be found

Technical Notes

GraphQL Thread Discovery

  • Uses databaseId to match REST API comment IDs with GraphQL comment nodes
  • Handles pagination by looping through all review threads to find the containing thread
  • Only resolves threads that aren't already resolved

Rate Limiting

  • Both REST and GraphQL calls respect GitHub's rate limits
  • Uses existing rate limit handler for retry logic
  • Batches operations efficiently

Performance Considerations

  • Efficient pagination for fetching review threads
  • Minimal API calls per resolution
  • Efficient thread matching algorithm

Usage in Review Service

The enhanced resolution is automatically used when the LLM identifies resolved comments:

for (const resolvedComment of agentResponse.resolvedComments) {
  try {
    await this.githubClient.resolveReviewComment(
      this.config.pr,
      parseInt(resolvedComment.commentId, 10),
      resolvedComment.reason,
    );
  } catch (error) {
    console.error(
      `Failed to resolve comment ${resolvedComment.commentId}:`,
      error,
    );
  }
}

Future Enhancements

Potential improvements to consider:

  1. Bulk Operations: Resolve multiple threads in a single GraphQL mutation
  2. Thread Metadata: Store additional resolution metadata
  3. Unresolve Capability: Add ability to unresolve comments if needed
  4. Resolution Types: Different resolution types (fixed, won't fix, duplicate, etc.)

Conclusion

This enhanced approach provides the best of both worlds:

  • Visual clarity through updated comment content
  • Native functionality through proper thread resolution
  • Complete integration with GitHub's review workflow

The solution ensures that resolved comments are properly handled both visually and functionally, providing a seamless experience for developers using the CodePress Review system.