Skip to content

Commit a0dc614

Browse files
Copilotalexr00
andauthored
Avoid associating branches with stale closed PRs (#8727)
* Initial plan * Fix stale PR association for branches tracking a base branch upstream Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/c9502930-8af9-4e4b-b72f-ad7cdd228e8d Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Remove incomplete issue URL from comment Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/c9502930-8af9-4e4b-b72f-ad7cdd228e8d Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Re-check GitHub for open PR even when local metadata exists Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/dea2457f-3b57-4756-a349-7bd07b19d340 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Remove upstream branch name guard per review feedback Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/ffe794e4-1828-489c-9ee8-12e97a16d4b4 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Restore previous getPullRequestForBranch behavior Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/64270c6c-f0b3-401d-ab68-314f7ccd6cf5 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent a0d196e commit a0dc614

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/view/reviewManager.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,21 @@ export class ReviewManager extends Disposable {
584584
}
585585

586586
let matchingPullRequestMetadata = await this._folderRepoManager.getMatchingPullRequestMetadataForBranch();
587-
588587
if (!matchingPullRequestMetadata) {
589588
Logger.appendLine(`No matching pull request metadata found locally for current branch ${branch.name}`, this.id);
590-
if (this._cachedBranchName !== branch.name || await this.hasNewPullRequests()) {
591-
matchingPullRequestMetadata = await this.checkGitHubForPrBranch(branch);
592-
} else {
593-
Logger.appendLine(`Skipping GitHub check for branch ${branch.name}: no new PRs since last check`, this.id);
589+
}
590+
591+
// Always check GitHub for a matching open PR (subject to the new-PRs/branch-change cache),
592+
// even when local metadata already exists. If GitHub returns a result, it overwrites the
593+
// local metadata via associateBranchWithPullRequest. This allows branches whose local
594+
// metadata points to a stale closed PR to recover automatically once an open PR exists.
595+
if (this._cachedBranchName !== branch.name || await this.hasNewPullRequests() || !matchingPullRequestMetadata) {
596+
const metadataFromGithub = await this.checkGitHubForPrBranch(branch);
597+
if (metadataFromGithub) {
598+
matchingPullRequestMetadata = metadataFromGithub;
594599
}
600+
} else {
601+
Logger.appendLine(`Skipping GitHub check for branch ${branch.name}: no new PRs since last check`, this.id);
595602
}
596603
this._cachedBranchName = branch.name;
597604

0 commit comments

Comments
 (0)