Fix PR created on GitHub website not linked to local branch#8665
Fix PR created on GitHub website not linked to local branch#8665
Conversation
Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/bb36d2e5-e24d-4ab1-a80a-db9e9f8744f0 Co-authored-by: alexr00 <[email protected]>
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]>
Implemented the fix in commit a84a532. In |
Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/001ddef0-6d36-4dcc-96f7-ed3f3d2901e5 Co-authored-by: alexr00 <[email protected]>
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]>
Reverted the PrsTreeModel cache approach and moved the fix to Now, for the current HEAD branch, if it has an upstream but no PR metadata in git config, we query GitHub via |
…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]>
You're right — |
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 viacheckGitHubForPrBranch()→associateBranchWithPullRequest(), but the local PR tree cache inPrsTreeModelis never invalidated afterward, so the tree never picks up the newly-associated branch.Change
ReviewManager.validateState()cache invalidation: AftercheckGitHubForPrBranch()discovers a new branch-PR association and writes the git config metadata, callinvalidateLocalPRCache()onPrsTreeModelto 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 fromgetLocalPullRequests(), which now picks up the branch that was just associated.PrsTreeModel.invalidateLocalPRCache(folderRepoManager): New public method that clears thePRType.LocalPullRequestcache entry for the given folder and fires a folder-levelonDidChangeDataevent to trigger a refresh.ReviewManager.validateState(): AftercheckGitHubForPrBranchreturns a successful match, callsinvalidateLocalPRCacheto ensure the tree picks up the newly-associated branch.