Skip to content

Fix PR created on GitHub website not linked to local branch#8665

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-pr-branch-recognition
Draft

Fix PR created on GitHub website not linked to local branch#8665
Copilot wants to merge 5 commits intomainfrom
copilot/fix-pr-branch-recognition

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

When a PR is created on the GitHub website (not via VS Code UI), the local branch is not recognized under "Local Pull Request Branches" — it only appears under "Created by me". This prevents applying suggestions and viewing inline comments on the local copy.

Root cause: getLocalPullRequests() only checks git config metadata (branch.<name>.github-pr-owner-number), which is only written when the PR is created or checked out through the extension. For branches where the PR was created on the GitHub website, this metadata is never written, so the branch is never included in the local PR list.

Change

FolderRepositoryManager.getLocalPullRequests() fallback: After the main metadata-based loop, for the current HEAD branch, if it has an upstream but wasn't found in the results (no PR metadata in git config), query GitHub via getMatchingPullRequestMetadataFromGitHub() to find an associated PR. On a match, write the git config metadata via associateBranchWithPullRequest() so subsequent calls find it directly, and include the PR in the returned results. This is a single API call that makes the local PR tree immediately correct.

Copilot AI changed the title [WIP] Fix issue with PR not linking to existing branch Fix PR created on GitHub website not linked to local branch Apr 14, 2026
Copilot AI requested a review from alexr00 April 14, 2026 11:03
Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@copilot continue

When a PR is created on the GitHub website (not via VS Code UI), the
ReviewManager discovers it via checkGitHubForPrBranch() and associates
the local branch with the PR. However, the local PR tree cache in
PrsTreeModel was never invalidated afterward, so the "Local Pull Request
Branches" category never showed the newly-associated branch.

Fix: In PrsTreeModel's onDidChangeActivePullRequest handler, when the
new active PR is not already in the cached PR set, delete the
LocalPullRequest cache entry and fire a full folder refresh (which
triggers refreshRepo() in the tree data provider) instead of the narrow
PR-level refresh (which only updates existing PR nodes via
refreshPullRequests()).

Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/a016c47c-ed2e-432f-b461-f678d8ab62c8

Co-authored-by: alexr00 <[email protected]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot continue

Implemented the fix in commit a84a532.

In PrsTreeModel's onDidChangeActivePullRequest handler, when the new active PR is not already in _allCachedPRs, the LocalPullRequest cache entry is deleted and a full folder refresh is fired (_onDidChangeData.fire(manager)) instead of the narrow PR-level refresh. This causes the tree to re-fetch the local PR list via getLocalPullRequests(), which now picks up the branch that was just associated by ReviewManager.checkGitHubForPrBranch().

Copilot AI requested a review from alexr00 April 15, 2026 16:59
Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@copilot I don't think that's the correct fix. Instead, we need to detect that the current branch is associated with a PR and update the git config metadata.

Copilot AI and others added 2 commits April 16, 2026 10:05
When a PR is created on the GitHub website (not via VS Code UI), the
local branch has no git config metadata (branch.<name>.github-pr-owner-number)
since associateBranchWithPullRequest was never called.

For the current HEAD branch, if it has an upstream but no PR metadata,
query GitHub via getMatchingPullRequestMetadataFromGitHub() and write
the git config metadata via associateBranchWithPullRequest(). This is a
single API call that makes the local PR tree immediately correct.

Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/001ddef0-6d36-4dcc-96f7-ed3f3d2901e5

Co-authored-by: alexr00 <[email protected]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot I don't think that's the correct fix. Instead, we need to detect that the current branch is associated with a PR and update the git config metadata.

Reverted the PrsTreeModel cache approach and moved the fix to getLocalPullRequests() in commit 682a3bc.

Now, for the current HEAD branch, if it has an upstream but no PR metadata in git config, we query GitHub via getMatchingPullRequestMetadataFromGitHub() and write the metadata via associateBranchWithPullRequest(). This persists the association so subsequent calls find it directly — matching the existing pattern used by ReviewManager.checkGitHubForPrBranch().

Copilot AI requested a review from alexr00 April 16, 2026 10:11
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.

PR made without the UI is not linked to the existing branch

2 participants