Skip to content

Commit 9877724

Browse files
committed
Adds support for comparison and create pull request URLs in remote services
Adds configuration options for comparison and create pull request URLs to support custom remote services. Updates the relevant interfaces and abstract methods to include these new URL types. (#4142, #4143)
1 parent fef314b commit 9877724

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -3903,6 +3903,14 @@
39033903
"type": "string",
39043904
"markdownDescription": "Specifies the format of a commit URL for the custom remote service\n\nAvailable tokens\\\n`${repo}` — repository path\\\n`${id}` — commit SHA"
39053905
},
3906+
"comparison": {
3907+
"type": "string",
3908+
"markdownDescription": "Specifies the format of a comparison URL for the custom remote service\n\nAvailable tokens\\\n`${repo}` — repository path\\\n`${ref1}` — ref 1\\\n`${ref2}` — ref 2\\\n`${notation}` — notation"
3909+
},
3910+
"createPullRequest": {
3911+
"type": "string",
3912+
"markdownDescription": "Specifies the format of a create pull request URL for the custom remote service\n\nAvailable tokens\\\n`${repo}` — repository path\\\n`${base}` — base branch\\\n`${compare}` — compare branch"
3913+
},
39063914
"file": {
39073915
"type": "string",
39083916
"markdownDescription": "Specifies the format of a file URL for the custom remote service\n\nAvailable tokens\\\n`${repo}` — repository path\\\n`${file}` — file name\\\n`${line}` — formatted line information"

src/commands/createPullRequestOnRemote.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { GlCommandBase } from './commandBase';
1212
import type { OpenOnRemoteCommandArgs } from './openOnRemote';
1313

1414
export interface CreatePullRequestOnRemoteCommandArgs {
15-
base?: string;
15+
base: string | undefined;
1616
compare: string;
1717
remote: string;
1818
repoPath: string;

src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ export interface RemotesUrlsConfig {
638638
readonly branch: string;
639639
readonly commit: string;
640640
readonly comparison?: string;
641+
readonly createPullRequest?: string;
641642
readonly file: string;
642643
readonly fileInBranch: string;
643644
readonly fileInCommit: string;

src/git/models/remoteResource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type RemoteResource =
3434
| {
3535
type: RemoteResourceType.CreatePullRequest;
3636
base: {
37-
branch?: string;
37+
branch: string | undefined;
3838
remote: { path: string; url: string };
3939
};
4040
compare: {

src/git/remotes/gerrit.ts

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ export class GerritRemote extends RemoteProvider {
189189
return this.encodeUrl(`${this.baseReviewUrl}/q/${sha}`);
190190
}
191191

192+
protected override getUrlForComparison(base: string, head: string, notation: '..' | '...'): string | undefined {
193+
return this.encodeUrl(`${this.baseReviewUrl}/q/${base}${notation}${head}`);
194+
}
195+
192196
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
193197
const line = range != null ? `#${range.start.line}` : '';
194198

src/git/remotes/remoteProvider.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDesc
129129
case RemoteResourceType.Commit:
130130
return this.getUrlForCommit(resource.sha);
131131
case RemoteResourceType.Comparison: {
132-
return this.getUrlForComparison?.(resource.base, resource.compare, resource.notation ?? '...');
132+
return this.getUrlForComparison(resource.base, resource.compare, resource.notation ?? '...');
133133
}
134134
case RemoteResourceType.CreatePullRequest: {
135135
return this.getUrlForCreatePullRequest?.(resource.base, resource.compare);
@@ -180,11 +180,12 @@ export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDesc
180180

181181
protected abstract getUrlForCommit(sha: string): string;
182182

183-
protected getUrlForComparison?(base: string, compare: string, notation: '..' | '...'): string | undefined;
183+
protected abstract getUrlForComparison(base: string, head: string, notation: '..' | '...'): string | undefined;
184184

185185
protected getUrlForCreatePullRequest?(
186186
base: { branch?: string; remote: { path: string; url: string } },
187-
compare: { branch: string; remote: { path: string; url: string } },
187+
head: { branch: string; remote: { path: string; url: string } },
188+
options?: { title?: string; description?: string },
188189
): string | undefined;
189190

190191
protected abstract getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string;

0 commit comments

Comments
 (0)