Skip to content

Commit 1f1e0c3

Browse files
committed
Unifies autolink enrichment keys for integrations
in order to avoid referencing the exact integration type outside of integratin class. Updates the autolink enrichment workflow to consistently use a pair of values (id and key) when resolving issues or pull requests across integrations. This removes provider-specific logic for constructing enrichment keys and centralizes the approach, simplifying maintenance and reducing errors when linking to external systems. Renames and refactors relevant methods in integration classes to reflect this unified signature. Enhances consistency and clarity in how autolinked items are identified and retrieved across supported providers.
1 parent cd6cef6 commit 1f1e0c3

File tree

10 files changed

+36
-37
lines changed

10 files changed

+36
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ images/settings
1111
gitlens-*.vsix
1212
product.json
1313
tsconfig*.tsbuildinfo
14+
localdev*.instructions.md

src/autolinks/autolinksProvider.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { ConfigurationChangeEvent } from 'vscode';
22
import { Disposable } from 'vscode';
33
import { GlyphChars } from '../constants';
44
import type { IntegrationIds } from '../constants.integrations';
5-
import { IssuesCloudHostIntegrationId } from '../constants.integrations';
65
import type { Container } from '../container';
76
import type { GitRemote } from '../git/models/remote';
87
import type { RemoteProvider, RemoteProviderId } from '../git/remotes/remoteProvider';
@@ -177,16 +176,11 @@ export class AutolinksProvider implements Disposable {
177176
return getAutolinks(message, refsets);
178177
}
179178

180-
getAutolinkEnrichableId(autolink: Autolink): string {
181-
// TODO: this should return linking key for all types of providers: such as TST-123 or #89 or PR 89 (or a pair: key+id).
182-
// Each provider should form whatever ID they need in their specific getIssueOrPullRequest() method.
183-
switch (autolink.provider?.id) {
184-
case IssuesCloudHostIntegrationId.Jira:
185-
case IssuesCloudHostIntegrationId.Linear:
186-
return `${autolink.prefix}${autolink.id}`;
187-
default:
188-
return autolink.id;
189-
}
179+
getAutolinkEnrichableId(autolink: Autolink): { id: string; key: string } {
180+
return {
181+
id: autolink.id,
182+
key: `${autolink.prefix}${autolink.id}`,
183+
};
190184
}
191185

192186
async getEnrichedAutolinks(
@@ -258,15 +252,19 @@ export class AutolinksProvider implements Disposable {
258252
integration != null &&
259253
integrationId === integration.id &&
260254
link.provider?.domain === integration.domain
261-
? integration.getIssueOrPullRequest(
255+
? integration.getLinkedIssueOrPullRequest(
262256
link.descriptor ?? remote.provider.repoDesc,
263257
this.getAutolinkEnrichableId(link),
264258
{ type: link.type },
265259
)
266260
: link.descriptor != null
267-
? linkIntegration?.getIssueOrPullRequest(link.descriptor, this.getAutolinkEnrichableId(link), {
268-
type: link.type,
269-
})
261+
? linkIntegration?.getLinkedIssueOrPullRequest(
262+
link.descriptor,
263+
this.getAutolinkEnrichableId(link),
264+
{
265+
type: link.type,
266+
},
267+
)
270268
: undefined;
271269
enrichedAutolinks.set(id, [issueOrPullRequestPromise, link]);
272270
}

src/plus/integrations/models/integration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ export abstract class IntegrationBase<
499499
): Promise<IssueShape[] | undefined>;
500500

501501
@debug()
502-
async getIssueOrPullRequest(
502+
async getLinkedIssueOrPullRequest(
503503
resource: T,
504-
id: string,
504+
link: { id: string; key: string },
505505
options?: { expiryOverride?: boolean | number; type?: IssueOrPullRequestType },
506506
): Promise<IssueOrPullRequest | undefined> {
507507
const scope = getLogScope();
@@ -512,17 +512,17 @@ export abstract class IntegrationBase<
512512
await this.refreshSessionIfExpired(scope);
513513

514514
const issueOrPR = this.container.cache.getIssueOrPullRequest(
515-
id,
515+
link.key,
516516
options?.type,
517517
resource,
518518
this,
519519
() => ({
520520
value: (async () => {
521521
try {
522-
const result = await this.getProviderIssueOrPullRequest(
522+
const result = await this.getProviderLinkedIssueOrPullRequest(
523523
this._session!,
524524
resource,
525-
id,
525+
link,
526526
options?.type,
527527
);
528528
this.resetRequestExceptionCount('getIssueOrPullRequest');
@@ -538,10 +538,10 @@ export abstract class IntegrationBase<
538538
return issueOrPR;
539539
}
540540

541-
protected abstract getProviderIssueOrPullRequest(
541+
protected abstract getProviderLinkedIssueOrPullRequest(
542542
session: ProviderAuthenticationSession,
543543
resource: T,
544-
id: string,
544+
link: { id: string; key: string },
545545
type: undefined | IssueOrPullRequestType,
546546
): Promise<IssueOrPullRequest | undefined>;
547547

src/plus/integrations/providers/azureDevOps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ export abstract class AzureDevOpsIntegrationBase<
259259
return Promise.resolve(undefined);
260260
}
261261

262-
protected override async getProviderIssueOrPullRequest(
262+
protected override async getProviderLinkedIssueOrPullRequest(
263263
{ accessToken }: AuthenticationSession,
264264
repo: AzureRepositoryDescriptor,
265-
id: string,
265+
{ id }: { id: string; key: string },
266266
type: undefined | IssueOrPullRequestType,
267267
): Promise<IssueOrPullRequest | undefined> {
268268
return (await this.container.azure)?.getIssueOrPullRequest(this, accessToken, repo.owner, repo.name, id, {

src/plus/integrations/providers/bitbucket-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export class BitbucketServerIntegration extends GitHostIntegration<
105105
return Promise.resolve(undefined);
106106
}
107107

108-
protected override async getProviderIssueOrPullRequest(
108+
protected override async getProviderLinkedIssueOrPullRequest(
109109
{ accessToken }: AuthenticationSession,
110110
repo: BitbucketRepositoryDescriptor,
111-
id: string,
111+
{ id }: { id: string; key: string },
112112
type: undefined | IssueOrPullRequestType,
113113
): Promise<IssueOrPullRequest | undefined> {
114114
if (type === 'issue') {

src/plus/integrations/providers/bitbucket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ export class BitbucketIntegration extends GitHostIntegration<
8787
return Promise.resolve(undefined);
8888
}
8989

90-
protected override async getProviderIssueOrPullRequest(
90+
protected override async getProviderLinkedIssueOrPullRequest(
9191
{ accessToken }: AuthenticationSession,
9292
repo: BitbucketRepositoryDescriptor,
93-
id: string,
93+
{ id }: { id: string; key: string },
9494
type: undefined | IssueOrPullRequestType,
9595
): Promise<IssueOrPullRequest | undefined> {
9696
return (await this.container.bitbucket)?.getIssueOrPullRequest(

src/plus/integrations/providers/github.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> extends Gi
8383
});
8484
}
8585

86-
protected override async getProviderIssueOrPullRequest(
86+
protected override async getProviderLinkedIssueOrPullRequest(
8787
{ accessToken }: AuthenticationSession,
8888
repo: GitHubRepositoryDescriptor,
89-
id: string,
89+
{ id }: { id: string; key: string },
9090
): Promise<IssueOrPullRequest | undefined> {
9191
return (await this.container.github)?.getIssueOrPullRequest(
9292
this,

src/plus/integrations/providers/gitlab.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ abstract class GitLabIntegrationBase<ID extends GitLabIntegrationIds> extends Gi
8787
});
8888
}
8989

90-
protected override async getProviderIssueOrPullRequest(
90+
protected override async getProviderLinkedIssueOrPullRequest(
9191
{ accessToken }: AuthenticationSession,
9292
repo: GitLabRepositoryDescriptor,
93-
id: string,
93+
{ id }: { id: string; key: string },
9494
): Promise<IssueOrPullRequest | undefined> {
9595
return (await this.container.gitlab)?.getIssueOrPullRequest(
9696
this,

src/plus/integrations/providers/jira.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ export class JiraIntegration extends IssuesIntegration<IssuesCloudHostIntegratio
272272
return results;
273273
}
274274

275-
protected override async getProviderIssueOrPullRequest(
275+
protected override async getProviderLinkedIssueOrPullRequest(
276276
session: AuthenticationSession,
277277
resource: JiraOrganizationDescriptor,
278-
id: string,
278+
{ key }: { id: string; key: string },
279279
): Promise<IssueOrPullRequest | undefined> {
280280
const api = await this.getProvidersApi();
281281
const issue = await api.getIssue(
282282
this.id,
283-
{ resourceId: resource.id, number: id },
283+
{ resourceId: resource.id, number: key },
284284
{ accessToken: session.accessToken },
285285
);
286286
return issue != null ? toIssueShape(issue, this) : undefined;

src/plus/integrations/providers/linear.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ export class LinearIntegration extends IssuesIntegration<IssuesCloudHostIntegrat
210210
}
211211
return issues;
212212
}
213-
protected override async getProviderIssueOrPullRequest(
213+
protected override async getProviderLinkedIssueOrPullRequest(
214214
session: ProviderAuthenticationSession,
215215
resource: ResourceDescriptor,
216-
id: string,
216+
{ id }: { id: string; key: string },
217217
_type: undefined | IssueOrPullRequestType,
218218
): Promise<IssueOrPullRequest | undefined> {
219219
const issue = await this.getRawProviderIssue(session, resource, id);

0 commit comments

Comments
 (0)