Merge pull request #3372 from tobyjwebb/bitbucket-branch-url

Fix opening remote branch on BitBucket repos
This commit is contained in:
Kiril Videlov 2024-03-29 20:32:27 +01:00 committed by GitHub
commit 4e7a6755a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -288,11 +288,11 @@ export class BaseBranch {
}
commitUrl(commitId: string): string | undefined {
// if repoBaseUrl is bitbucket, then the commit url is different
if (this.repoBaseUrl.includes('bitbucket.org')) {
// Different Git providers use different paths for the commit url:
if (this.isBitBucket) {
return `${this.repoBaseUrl}/commits/${commitId}`;
}
if (this.repoBaseUrl.includes('gitlab.com')) {
if (this.isGitlab) {
return `${this.repoBaseUrl}/-/commit/${commitId}`;
}
return `${this.repoBaseUrl}/commit/${commitId}`;
@ -306,6 +306,18 @@ export class BaseBranch {
if (!upstreamBranchName) return undefined;
const baseBranchName = this.branchName.split('/')[1];
const branchName = upstreamBranchName.split('/').slice(3).join('/');
if (this.isBitBucket) {
return `${this.repoBaseUrl.trim()}/branch/${branchName}?dest=${baseBranchName}`;
}
// The following branch path is good for at least Gitlab and Github:
return `${this.repoBaseUrl.trim()}/compare/${baseBranchName}...${branchName}`;
}
private get isBitBucket(): boolean {
return this.repoBaseUrl.includes('bitbucket.org');
}
private get isGitlab(): boolean {
return this.repoBaseUrl.includes('gitlab.com');
}
}