Skip to content

Add issue linkage tracking to PR analysis reports using GitHub GraphQL API#5

Merged
ChrisTimperley merged 4 commits into
mainfrom
copilot/fix-00f704f3-5016-438d-aac7-0fe9f8aad487
Sep 26, 2025
Merged

Add issue linkage tracking to PR analysis reports using GitHub GraphQL API#5
ChrisTimperley merged 4 commits into
mainfrom
copilot/fix-00f704f3-5016-438d-aac7-0fe9f8aad487

Conversation

Copilot AI commented Sep 26, 2025

Copy link
Copy Markdown
Contributor
  • Add linkedIssue field to PullRequestAnalysis interface (number | null)
  • Create utility function to extract issue numbers from PR body text REMOVED
  • Modify GitHubService.analyzePullRequest() to detect linked issues IMPROVED
  • Use GitHub GraphQL API closingIssuesReferences field instead of parsing PR body
  • Update README documentation to show the new field in sample output
  • Test the changes with GraphQL implementation
  • Build and lint to ensure no regressions
  • Fix code formatting issues with Prettier

Summary of Changes

Replaced the PR body parsing approach with GitHub's GraphQL API as suggested in the code review comments. This is much more reliable and comprehensive:

What Changed

  • Removed extractLinkedIssue() function that used regex to parse PR descriptions
  • Added getLinkedIssues() method that uses GitHub GraphQL API
  • Modified analyzePullRequest() to call the GraphQL API alongside other data fetching
  • Fixed code formatting issues with Prettier

Benefits of GraphQL Approach

  • More reliable: Uses GitHub's native issue linking detection
  • Comprehensive: Captures issues linked via keywords AND manual UI linking
  • Handles edge cases: No regex parsing means fewer false positives/negatives
  • Future-proof: Automatically benefits from GitHub's linking improvements

GraphQL Query Used

query($owner: String!, $repo: String!, $number: Int!) {
  repository(owner: $owner, name: $repo) {
    pullRequest(number: $number) {
      closingIssuesReferences(first: 1) {
        nodes {
          number
        }
      }
    }
  }
}

The linkedIssue field now contains the first closing issue number from GitHub's native closingIssuesReferences, or null if no issues will be closed by the PR.

All linting and formatting checks now pass successfully.

Original prompt

This section details on the original issue you should resolve

<issue_title>Each PR description should record that PR is linked to an issue</issue_title>
<issue_description>If the PR is linked to an issue, the issue number should be given. Otherwise it should be null.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #4

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: ChrisTimperley <523560+ChrisTimperley@users.noreply.github.com>
Copilot AI changed the title [WIP] Each PR description should record that PR is linked to an issue Add issue linkage tracking to PR analysis reports Sep 26, 2025

@ChrisTimperley ChrisTimperley left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's double check to see whether we can use the GraphQL to solve this problem rather than trying to parse the body of the PR.

Comment thread src/services/github.ts Outdated
hasReviews: reviews.data.length > 0,
hasComments: comments.data.length > 0,
ciStatus,
linkedIssue: extractLinkedIssue(pr.body),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the GitHub GraphQL API not automatically expose this information?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you take a look into this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the GitHub GraphQL API has a closingIssuesReferences field that automatically exposes linked issues. This is much better than parsing PR body text as it captures both keyword-based links and manual UI linking. I'll switch to using GraphQL for this.

Copilot AI commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Let's double check to see whether we can use the GraphQL to solve this problem rather than trying to parse the body of the PR.

You're absolutely right! The GitHub GraphQL API has a closingIssuesReferences field that provides this information directly without needing to parse PR body text. This would be much more reliable and would capture issues linked through both keywords and the GitHub UI. I'll implement this GraphQL-based approach.

Co-authored-by: ChrisTimperley <523560+ChrisTimperley@users.noreply.github.com>
Copilot AI changed the title Add issue linkage tracking to PR analysis reports Add issue linkage tracking to PR analysis reports using GitHub GraphQL API Sep 26, 2025

@ChrisTimperley ChrisTimperley left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Overall, this looks great. Just fix up the linting issue (you need to format the code) and we're good to merge.

Co-authored-by: ChrisTimperley <523560+ChrisTimperley@users.noreply.github.com>

Copilot AI commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Overall, this looks great. Just fix up the linting issue (you need to format the code) and we're good to merge.

Fixed the code formatting with Prettier. The issue was a long line that needed to be broken up. All linting and formatting checks now pass. (commit: ef5c3c0)

@ChrisTimperley
ChrisTimperley marked this pull request as ready for review September 26, 2025 23:39
@ChrisTimperley
ChrisTimperley merged commit 5c62c08 into main Sep 26, 2025
1 check passed
@ChrisTimperley
ChrisTimperley deleted the copilot/fix-00f704f3-5016-438d-aac7-0fe9f8aad487 branch September 26, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Each PR description should record that PR is linked to an issue

2 participants