Skip to content

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

Closed
Copilot wants to merge 7 commits intomainfrom
copilot/fix-pr-branch-recognition
Closed

Fix PR created on GitHub website not linked to local branch#8665
Copilot wants to merge 7 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. ReviewManager.validateState() does discover the PR via GitHub API and writes the metadata via checkGitHubForPrBranch()associateBranchWithPullRequest(), but the local PR tree cache in PrsTreeModel is never invalidated afterward, so the tree never picks up the newly-associated branch.

Change

ReviewManager.validateState() cache invalidation: After checkGitHubForPrBranch() discovers a new branch-PR association and writes the git config metadata, call invalidateLocalPRCache() on PrsTreeModel to clear the stale local PR cache entry for the folder and trigger a targeted folder-level refresh. This causes the tree data provider to re-fetch the local PR list from getLocalPullRequests(), which now picks up the branch that was just associated.

  • PrsTreeModel.invalidateLocalPRCache(folderRepoManager): New public method that clears the PRType.LocalPullRequest cache entry for the given folder and fires a folder-level onDidChangeData event to trigger a refresh.
  • ReviewManager.validateState(): After checkGitHubForPrBranch returns a successful match, calls invalidateLocalPRCache to ensure the tree picks up the newly-associated branch.

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
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'm still not confident this is the right solution. Shouldn't validateState in ReviewManager figure this out?

Copilot AI and others added 2 commits April 17, 2026 11:02
…ranch-PR association

When validateState discovers a PR for the current branch via
checkGitHubForPrBranch (which writes git config metadata), invalidate
the local PR tree cache so the tree re-queries and picks up the
newly-associated branch under "Local Pull Request Branches".

Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/faa71328-7879-45c0-84f3-d9d1efb039e4

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

Copilot AI commented Apr 17, 2026

@copilot I'm still not confident this is the right solution. Shouldn't validateState in ReviewManager figure this out?

You're right — validateState already handles the detection and metadata writing via checkGitHubForPrBranch. The only missing piece was that the tree's local PR cache wasn't refreshed afterward. Reverted the getLocalPullRequests change and moved the fix to validateState in commit 6f70973. Now when checkGitHubForPrBranch successfully discovers a new association, invalidateLocalPRCache is called to clear the stale local PR cache entry and trigger a targeted folder refresh.

Copilot AI requested a review from alexr00 April 17, 2026 11:06
@alexr00 alexr00 closed this Apr 17, 2026
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