Skip to content

Commit 28a5220

Browse files
committed
Generates create Bitbucket PR URLs
(#4142, #4143)
1 parent 9ee38b0 commit 28a5220

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Diff for: src/git/remotes/bitbucket.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Range, Uri } from 'vscode';
22
import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks/models/autolinks';
3+
import type { RepositoryDescriptor } from '../../plus/integrations/integration';
34
import type { Brand, Unbrand } from '../../system/brand';
45
import type { Repository } from '../models/repository';
56
import type { GkProviderId } from '../models/repositoryIdentities';
@@ -10,7 +11,7 @@ import { RemoteProvider } from './remoteProvider';
1011
const fileRegex = /^\/([^/]+)\/([^/]+?)\/src(.+)$/i;
1112
const rangeRegex = /^lines-(\d+)(?::(\d+))?$/;
1213

13-
export class BitbucketRemote extends RemoteProvider {
14+
export class BitbucketRemote extends RemoteProvider<RepositoryDescriptor> {
1415
constructor(domain: string, path: string, protocol?: string, name?: string, custom: boolean = false) {
1516
super(domain, path, protocol, name, custom);
1617
}
@@ -142,8 +143,18 @@ export class BitbucketRemote extends RemoteProvider {
142143
return this.encodeUrl(`${this.baseUrl}/commits/${sha}`);
143144
}
144145

145-
protected override getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string {
146-
return this.encodeUrl(`${this.baseUrl}/branches/compare/${base}%0D${compare}`).replace('%250D', '%0D');
146+
protected override getUrlForComparison(base: string, head: string, _notation: '..' | '...'): string {
147+
return `${this.encodeUrl(`${this.baseUrl}/branches/compare/${head}\r${base}`)}#diff`;
148+
}
149+
150+
protected override getUrlForCreatePullRequest(
151+
base: { branch?: string; remote: { path: string; url: string } },
152+
head: { branch: string; remote: { path: string; url: string } },
153+
_options?: { title?: string; description?: string },
154+
): string | undefined {
155+
const { owner, name } = this.repoDesc;
156+
const query = new URLSearchParams({ source: head.branch, dest: `${owner}/${name}::${base.branch ?? ''}` });
157+
return `${this.encodeUrl(`${this.getRepoBaseUrl(head.remote.path)}/pull-requests/new`)}?${query.toString()}`;
147158
}
148159

149160
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {

0 commit comments

Comments
 (0)