Skip to content

Commit d8ac382

Browse files
eamodiosergeibbb
authored andcommitted
Adds create pr urls for other providers
(#4142, #4143)
1 parent f0f6f67 commit d8ac382

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
3030
- Fixes large commit messages work poorly on Commit Graph ([#4100](https://github.com/gitkraken/vscode-gitlens/issues/4100))
3131
- Fixes _Show \* View_ commands fail intermittently ([#4127](https://github.com/gitkraken/vscode-gitlens/issues/4127))
3232
- Load more not working on incoming changes in Commits/Repositories views ([#4154](https://github.com/gitkraken/vscode-gitlens/issues/4154))
33+
- Fixes _Create Pull Request_ feature ([#4142](https://github.com/gitkraken/vscode-gitlens/issues/4142))
3334

3435
## [16.3.3] - 2025-03-13
3536

src/git/remotes/custom.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,23 @@ export class CustomRemote extends RemoteProvider {
5858
return this.getUrl(this.urls.commit, this.getContext({ id: sha }));
5959
}
6060

61-
protected override getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string | undefined {
61+
protected override getUrlForComparison(base: string, head: string, notation: '..' | '...'): string | undefined {
6262
if (this.urls.comparison == null) return undefined;
6363

64-
return this.getUrl(this.urls.comparison, this.getContext({ ref1: base, ref2: compare, notation: notation }));
64+
return this.getUrl(this.urls.comparison, this.getContext({ ref1: base, ref2: head, notation: notation }));
65+
}
66+
67+
protected override getUrlForCreatePullRequest(
68+
base: { branch?: string; remote: { path: string; url: string } },
69+
compare: { branch: string; remote: { path: string; url: string } },
70+
_options?: { title?: string; description?: string },
71+
): string | undefined {
72+
if (this.urls.createPullRequest == null) return undefined;
73+
74+
return this.getUrl(
75+
this.urls.createPullRequest,
76+
this.getContext({ base: base.branch ?? '', head: compare.branch }),
77+
);
6578
}
6679

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

src/git/remotes/gerrit.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ export class GerritRemote extends RemoteProvider {
193193
return this.encodeUrl(`${this.baseReviewUrl}/q/${base}${notation}${head}`);
194194
}
195195

196+
protected override getUrlForCreatePullRequest(
197+
base: { branch?: string; remote: { path: string; url: string } },
198+
head: { branch: string; remote: { path: string; url: string } },
199+
_options?: { title?: string; description?: string },
200+
): string | undefined {
201+
const query = new URLSearchParams({ sourceBranch: head.branch, targetBranch: base.branch ?? '' });
202+
203+
return this.encodeUrl(`${this.baseReviewUrl}/createPullRequest?${query.toString()}`);
204+
}
205+
196206
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
197207
const line = range != null ? `#${range.start.line}` : '';
198208

src/git/remotes/gitea.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,23 @@ export class GiteaRemote extends RemoteProvider {
139139
return this.encodeUrl(`${this.baseUrl}/commit/${sha}`);
140140
}
141141

142-
protected override getUrlForComparison(ref1: string, ref2: string, _notation: '..' | '...'): string {
143-
return this.encodeUrl(`${this.baseUrl}/compare/${ref1}...${ref2}`);
142+
protected override getUrlForComparison(base: string, head: string, _notation: '..' | '...'): string {
143+
return this.encodeUrl(`${this.baseUrl}/compare/${base}...${head}`);
144+
}
145+
146+
protected override getUrlForCreatePullRequest(
147+
base: { branch?: string; remote: { path: string; url: string } },
148+
head: { branch: string; remote: { path: string; url: string } },
149+
options?: { title?: string; description?: string },
150+
): string | undefined {
151+
const query = new URLSearchParams({ head: head.branch, base: base.branch ?? '' });
152+
if (options?.title) {
153+
query.set('title', options.title);
154+
}
155+
if (options?.description) {
156+
query.set('body', options.description);
157+
}
158+
return `${this.encodeUrl(`${this.baseUrl}/pulls/new`)}?${query.toString()}`;
144159
}
145160

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

src/git/remotes/remoteProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDesc
132132
return this.getUrlForComparison(resource.base, resource.compare, resource.notation ?? '...');
133133
}
134134
case RemoteResourceType.CreatePullRequest: {
135-
return this.getUrlForCreatePullRequest?.(resource.base, resource.compare);
135+
return this.getUrlForCreatePullRequest(resource.base, resource.compare);
136136
}
137137
case RemoteResourceType.File:
138138
return this.getUrlForFile(
@@ -190,7 +190,7 @@ export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDesc
190190
return Promise.resolve(true);
191191
}
192192

193-
protected getUrlForCreatePullRequest?(
193+
protected abstract getUrlForCreatePullRequest(
194194
base: { branch?: string; remote: { path: string; url: string } },
195195
head: { branch: string; remote: { path: string; url: string } },
196196
options?: { title?: string; description?: string },

0 commit comments

Comments
 (0)