Skip to content

Commit bf2d1d5

Browse files
committed
Generates create GitHub PR URLs
(#4142, #4143)
1 parent e53c6fb commit bf2d1d5

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/git/remotes/github.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,33 @@ export class GitHubRemote extends RemoteProvider<GitHubRepositoryDescriptor> {
276276
return this.encodeUrl(`${this.baseUrl}/commit/${sha}`);
277277
}
278278

279-
protected override getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string {
280-
return this.encodeUrl(`${this.baseUrl}/compare/${base}${notation}${compare}`);
279+
protected override getUrlForComparison(base: string, head: string, notation: '..' | '...'): string {
280+
return this.encodeUrl(`${this.baseUrl}/compare/${base}${notation}${head}`);
281281
}
282282

283283
protected override getUrlForCreatePullRequest(
284284
base: { branch?: string; remote: { path: string; url: string } },
285-
compare: { branch: string; remote: { path: string; url: string } },
285+
head: { branch: string; remote: { path: string; url: string } },
286+
options?: { title?: string; description?: string },
286287
): string | undefined {
287-
if (base.remote.url === compare.remote.url) {
288-
return this.encodeUrl(`${this.baseUrl}/pull/new/${base.branch ?? 'HEAD'}...${compare.branch}`);
288+
const query = new URLSearchParams();
289+
if (options?.title) {
290+
query.set('title', options.title);
291+
}
292+
if (options?.description) {
293+
query.set('body', options.description);
294+
}
295+
296+
if (base.remote.url === head.remote.url) {
297+
return `${this.encodeUrl(
298+
`${this.baseUrl}/pull/new/${base.branch ?? 'HEAD'}...${head.branch}`,
299+
)}?${query.toString()}`;
289300
}
290301

291-
const [owner] = compare.remote.path.split('/', 1);
292-
return this.encodeUrl(`${this.baseUrl}/pull/new/${base.branch ?? 'HEAD'}...${owner}:${compare.branch}`);
302+
const [owner] = head.remote.path.split('/', 1);
303+
return `${this.encodeUrl(
304+
`${this.baseUrl}/pull/new/${base.branch ?? 'HEAD'}...${owner}:${head.branch}`,
305+
)}?${query.toString()}`;
293306
}
294307

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

0 commit comments

Comments
 (0)