Skip to content

Commit 682a3bc

Browse files
Copilotalexr00
andauthored
Add GitHub API fallback for HEAD branch in getLocalPullRequests
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 <38270282+alexr00@users.noreply.github.com>
1 parent f327253 commit 682a3bc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,35 @@ export class FolderRepositoryManager extends Disposable {
963963
})));
964964
}
965965

966-
return models.filter(value => value !== undefined) as PullRequestModel[];
966+
const result = models.filter(value => value !== undefined) as PullRequestModel[];
967+
968+
// For the current HEAD branch, if it has an upstream but no PR metadata,
969+
// query GitHub to find an associated PR. This handles PRs created on the
970+
// GitHub website that haven't been checked out through the extension.
971+
const head = this.repository.state.HEAD;
972+
if (head?.name && head.upstream && !result.find(pr => pr.localBranchName === head.name)) {
973+
try {
974+
const metadata = await this.getMatchingPullRequestMetadataFromGitHub(
975+
head,
976+
head.upstream.remote,
977+
undefined,
978+
head.upstream.name,
979+
);
980+
if (metadata) {
981+
await PullRequestGitHelper.associateBranchWithPullRequest(
982+
this.repository,
983+
metadata.model,
984+
head.name,
985+
);
986+
metadata.model.localBranchName = head.name;
987+
result.push(metadata.model);
988+
}
989+
} catch (e) {
990+
Logger.debug(`Error checking GitHub for PR on HEAD branch ${head.name}: ${e}`, this.id);
991+
}
992+
}
993+
994+
return result;
967995
}
968996

969997
/**

0 commit comments

Comments
 (0)