Skip to content

Commit cbe7717

Browse files
authored
Add logging around finding upstream branc on GitHub (#6778)
Part of #6378
1 parent 8808721 commit cbe7717

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,8 @@ export class FolderRepositoryManager extends Disposable {
22372237
async getMatchingPullRequestMetadataFromGitHubWithUrl(branch: Branch, remoteUrl?: string, upstreamBranchName?: string): Promise<
22382238
(PullRequestMetadata & { model: PullRequestModel }) | null
22392239
> {
2240+
Logger.debug(`Searching GitHub for a PR with branch ${upstreamBranchName} and remote ${remoteUrl}`, this.id);
2241+
22402242
if (!remoteUrl) {
22412243
return null;
22422244
}
@@ -2262,6 +2264,7 @@ export class FolderRepositoryManager extends Disposable {
22622264
async getMatchingPullRequestMetadataFromGitHubWithRemoteName(remoteName?: string, upstreamBranchName?: string): Promise<
22632265
(PullRequestMetadata & { model: PullRequestModel }) | null
22642266
> {
2267+
Logger.debug(`Searching GitHub for a PR with branch ${upstreamBranchName} and remote ${remoteName}`, this.id);
22652268
if (!remoteName) {
22662269
return null;
22672270
}

src/view/reviewManager.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,28 +345,37 @@ export class ReviewManager extends Disposable {
345345
return false;
346346
}
347347

348-
private async getUpstreamUrlAndName(branch: Branch): Promise<{ url: string | undefined, branchName: string | undefined, remoteName: string | undefined }> {
348+
private async getUpstreamUrlAndName(branch: Branch): Promise<{ remoteUrl: string | undefined, upstreamBranchName: string | undefined, remoteName: string | undefined }> {
349349
if (branch.upstream) {
350-
return { remoteName: branch.upstream.remote, branchName: branch.upstream.name, url: undefined };
350+
Logger.debug(`Upstream for branch ${branch.name} is ${branch.upstream.remote}/${branch.upstream.name}`, this.id);
351+
return { remoteName: branch.upstream.remote, upstreamBranchName: branch.upstream.name, remoteUrl: undefined };
351352
} else {
352353
try {
353-
const url = await this.repository.getConfig(`branch.${branch.name}.remote`);
354+
const remoteUrl = await this.repository.getConfig(`branch.${branch.name}.remote`);
354355
const upstreamBranch = await this.repository.getConfig(`branch.${branch.name}.merge`);
355-
let branchName: string | undefined;
356+
let upstreamBranchName: string | undefined;
356357
if (upstreamBranch) {
357-
branchName = upstreamBranch.substring('refs/heads/'.length);
358+
upstreamBranchName = upstreamBranch.substring('refs/heads/'.length);
358359
}
359-
return { url, branchName, remoteName: undefined };
360+
Logger.debug(`Upstream for branch ${branch.name} is ${upstreamBranchName} at ${remoteUrl}`, this.id);
361+
return { remoteUrl: remoteUrl, upstreamBranchName, remoteName: undefined };
360362
} catch (e) {
361363
Logger.appendLine(`Failed to get upstream for branch ${branch.name} from git config.`, this.id);
362-
return { url: undefined, branchName: undefined, remoteName: undefined };
364+
return { remoteUrl: undefined, upstreamBranchName: undefined, remoteName: undefined };
363365
}
364366
}
365367
}
366368

367369
private async checkGitHubForPrBranch(branch: Branch): Promise<(PullRequestMetadata & { model: PullRequestModel }) | undefined> {
368-
const { url, branchName, remoteName } = await this.getUpstreamUrlAndName(this._repository.state.HEAD!);
369-
const metadataFromGithub = await this._folderRepoManager.getMatchingPullRequestMetadataFromGitHub(branch, remoteName, url, branchName);
370+
371+
let branchToCheck: Branch;
372+
if (this._repository.state.HEAD && (branch.name === this._repository.state.HEAD.name)) {
373+
branchToCheck = this._repository.state.HEAD;
374+
} else {
375+
branchToCheck = branch;
376+
}
377+
const { remoteUrl: url, upstreamBranchName, remoteName } = await this.getUpstreamUrlAndName(branchToCheck);
378+
const metadataFromGithub = await this._folderRepoManager.getMatchingPullRequestMetadataFromGitHub(branchToCheck, remoteName, url, upstreamBranchName);
370379
if (metadataFromGithub) {
371380
Logger.appendLine(`Found matching pull request metadata on GitHub for current branch ${branch.name}. Repo: ${metadataFromGithub.owner}/${metadataFromGithub.repositoryName} PR: ${metadataFromGithub.prNumber}`, this.id);
372381
await PullRequestGitHelper.associateBranchWithPullRequest(

0 commit comments

Comments
 (0)