Skip to content

Commit cc933ca

Browse files
committed
Refactors autolinks configuration
- Updates autolink interfaces for better type safety - Enhances autolink configuration with explicit boolean flags - Adjusts remote providers to use updated autolink structure
1 parent b1e5b92 commit cc933ca

File tree

22 files changed

+111
-86
lines changed

22 files changed

+111
-86
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,7 @@
34103410
"properties": {
34113411
"prefix": {
34123412
"type": "string",
3413-
"description": "Specifies the short prefix to use to generate autolinks for the external resource"
3413+
"description": "Specifies the short prefix to match to generate autolinks for the external resource, e.g. `GH-` or `JIRA-`"
34143414
},
34153415
"title": {
34163416
"type": [

src/annotations/autolinks.ts renamed to src/autolinks.ts

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
11
import type { ConfigurationChangeEvent } from 'vscode';
22
import { Disposable } from 'vscode';
3-
import type { AutolinkReference, AutolinkType } from '../config';
4-
import { GlyphChars } from '../constants';
5-
import type { IntegrationId } from '../constants.integrations';
6-
import { IssueIntegrationId } from '../constants.integrations';
7-
import type { Container } from '../container';
8-
import type { IssueOrPullRequest } from '../git/models/issue';
9-
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/models/issue';
10-
import type { GitRemote } from '../git/models/remote';
11-
import type { ProviderReference } from '../git/models/remoteProvider';
12-
import type { ResourceDescriptor } from '../plus/integrations/integration';
13-
import { fromNow } from '../system/date';
14-
import { debug } from '../system/decorators/log';
15-
import { encodeUrl } from '../system/encoding';
16-
import { join, map } from '../system/iterable';
17-
import { Logger } from '../system/logger';
18-
import { escapeMarkdown } from '../system/markdown';
19-
import type { MaybePausedResult } from '../system/promise';
20-
import { capitalize, encodeHtmlWeak, escapeRegex, getSuperscript } from '../system/string';
21-
import { configuration } from '../system/vscode/configuration';
3+
import { GlyphChars } from './constants';
4+
import type { IntegrationId } from './constants.integrations';
5+
import { IssueIntegrationId } from './constants.integrations';
6+
import type { Container } from './container';
7+
import type { IssueOrPullRequest } from './git/models/issue';
8+
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from './git/models/issue';
9+
import type { GitRemote } from './git/models/remote';
10+
import type { ProviderReference } from './git/models/remoteProvider';
11+
import type { ResourceDescriptor } from './plus/integrations/integration';
12+
import { fromNow } from './system/date';
13+
import { debug } from './system/decorators/log';
14+
import { encodeUrl } from './system/encoding';
15+
import { join, map } from './system/iterable';
16+
import { Logger } from './system/logger';
17+
import { escapeMarkdown } from './system/markdown';
18+
import type { MaybePausedResult } from './system/promise';
19+
import { capitalize, encodeHtmlWeak, escapeRegex, getSuperscript } from './system/string';
20+
import { configuration } from './system/vscode/configuration';
2221

2322
const emptyAutolinkMap = Object.freeze(new Map<string, Autolink>());
2423

2524
const numRegex = /<num>/g;
2625

27-
export interface Autolink {
26+
export type AutolinkType = 'issue' | 'pullrequest';
27+
28+
export interface AutolinkReference {
29+
/** Short prefix to match to generate autolinks for the external resource */
30+
readonly prefix: string;
31+
/** URL of the external resource to link to */
32+
readonly url: string;
33+
/** Whether alphanumeric characters should be allowed in `<num>` */
34+
readonly alphanumeric: boolean;
35+
/** Whether case should be ignored when matching the prefix */
36+
readonly ignoreCase: boolean;
37+
readonly title: string | undefined;
38+
39+
readonly type?: AutolinkType;
40+
readonly description?: string;
41+
readonly descriptor?: ResourceDescriptor;
42+
}
43+
44+
export interface Autolink extends AutolinkReference {
2845
provider?: ProviderReference;
2946
id: string;
30-
prefix: string;
31-
title?: string;
32-
url: string;
33-
alphanumeric?: boolean
34-
type?: AutolinkType;
35-
description?: string;
36-
37-
descriptor?: ResourceDescriptor;
47+
3848
tokenize?:
3949
| ((
4050
text: string,
@@ -69,8 +79,10 @@ export function serializeAutolink(value: Autolink): Autolink {
6979
: undefined,
7080
id: value.id,
7181
prefix: value.prefix,
72-
title: value.title,
7382
url: value.url,
83+
alphanumeric: value.alphanumeric,
84+
ignoreCase: value.ignoreCase,
85+
title: value.title,
7486
type: value.type,
7587
description: value.description,
7688
descriptor: value.descriptor,
@@ -140,18 +152,12 @@ export class Autolinks implements Disposable {
140152
this._references =
141153
autolinks
142154
?.filter(a => a.prefix && a.url)
143-
/**
144-
* Only allow properties defined by {@link AutolinkReference}
145-
*/
146155
?.map(a => ({
147156
prefix: a.prefix,
148157
url: a.url,
149-
title: a.title,
150-
alphanumeric: a.alphanumeric,
151-
ignoreCase: a.ignoreCase,
152-
type: a.type,
153-
description: a.description,
154-
descriptor: a.descriptor,
158+
alphanumeric: a.alphanumeric ?? false,
159+
ignoreCase: a.ignoreCase ?? false,
160+
title: a.title ?? undefined,
155161
})) ?? [];
156162
}
157163
}
@@ -237,8 +243,9 @@ export class Autolinks implements Disposable {
237243
id: num,
238244
prefix: ref.prefix,
239245
url: ref.url?.replace(numRegex, num),
240-
title: ref.title?.replace(numRegex, num),
241246
alphanumeric: ref.alphanumeric,
247+
ignoreCase: ref.ignoreCase,
248+
title: ref.title?.replace(numRegex, num),
242249
type: ref.type,
243250
description: ref.description?.replace(numRegex, num),
244251
descriptor: ref.descriptor,

src/config.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { SupportedAIModels, VSCodeAIModels } from './constants.ai';
2-
import type { ResourceDescriptor } from './plus/integrations/integration';
32
import type { DateTimeFormat } from './system/date';
43
import type { LogLevel } from './system/logger.constants';
54

@@ -18,7 +17,7 @@ export interface Config {
1817
};
1918
};
2019
};
21-
readonly autolinks: AutolinkReference[] | null;
20+
readonly autolinks: AutolinkConfig[] | null;
2221
readonly blame: {
2322
readonly avatars: boolean;
2423
readonly compact: boolean;
@@ -251,18 +250,17 @@ export interface Config {
251250
}
252251

253252
export type AnnotationsToggleMode = 'file' | 'window';
254-
export type AutolinkType = 'issue' | 'pullrequest';
255253

256-
export interface AutolinkReference {
254+
export interface AutolinkConfig {
255+
/** Short prefix to match to generate autolinks for the external resource */
257256
readonly prefix: string;
257+
/** URL of the external resource to link to */
258258
readonly url: string;
259-
readonly title?: string;
260-
readonly alphanumeric?: boolean;
261-
readonly ignoreCase?: boolean;
262-
263-
readonly type?: AutolinkType;
264-
readonly description?: string;
265-
readonly descriptor?: ResourceDescriptor;
259+
/** Whether alphanumeric characters should be allowed in `<num>` */
260+
readonly alphanumeric: boolean;
261+
/** Whether case should be ignored when matching the prefix */
262+
readonly ignoreCase: boolean;
263+
readonly title: string | null;
266264
}
267265

268266
export type BlameHighlightLocations = 'gutter' | 'line' | 'overview';

src/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { getSupportedGitProviders, getSupportedRepositoryPathMappingProvider } f
22
import type { ConfigurationChangeEvent, Disposable, Event, ExtensionContext } from 'vscode';
33
import { EventEmitter, ExtensionMode, Uri } from 'vscode';
44
import type { AIProviderService } from './ai/aiProviderService';
5-
import { Autolinks } from './annotations/autolinks';
65
import { FileAnnotationController } from './annotations/fileAnnotationController';
76
import { LineAnnotationController } from './annotations/lineAnnotationController';
87
import { ActionRunners } from './api/actionRunners';
8+
import { Autolinks } from './autolinks';
99
import { setDefaultGravatarsStyle } from './avatars';
1010
import { CacheProvider } from './cache';
1111
import { GitCodeLensController } from './codelens/codeLensController';

src/git/formatters/commitFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Uri } from 'vscode';
2-
import type { MaybeEnrichedAutolink } from '../../annotations/autolinks';
32
import type {
43
Action,
54
ActionContext,
65
HoverCommandsActionContext,
76
OpenPullRequestActionContext,
87
} from '../../api/gitlens';
8+
import type { MaybeEnrichedAutolink } from '../../autolinks';
99
import { getPresenceDataUri } from '../../avatars';
1010
import { Command } from '../../commands/base';
1111
import { DiffWithCommand } from '../../commands/diffWith';

src/git/models/commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Uri } from 'vscode';
2-
import type { EnrichedAutolink } from '../../annotations/autolinks';
2+
import type { EnrichedAutolink } from '../../autolinks';
33
import { getAvatarUri, getCachedAvatarUri } from '../../avatars';
44
import type { GravatarDefaultStyle } from '../../config';
55
import { GlyphChars } from '../../constants';

src/git/remotes/azure-devops.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Range, Uri } from 'vscode';
2-
import type { DynamicAutolinkReference } from '../../annotations/autolinks';
3-
import type { AutolinkReference } from '../../config';
2+
import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks';
43
import type { GkProviderId } from '../../gk/models/repositoryIdentities';
54
import type { Brand, Unbrand } from '../../system/brand';
65
import type { Repository } from '../models/repository';
@@ -65,6 +64,8 @@ export class AzureDevOpsRemote extends RemoteProvider {
6564
{
6665
prefix: '#',
6766
url: `${workUrl}/_workitems/edit/<num>`,
67+
alphanumeric: false,
68+
ignoreCase: false,
6869
title: `Open Work Item #<num> on ${this.name}`,
6970

7071
type: 'issue',
@@ -74,6 +75,8 @@ export class AzureDevOpsRemote extends RemoteProvider {
7475
// Default Pull request message when merging a PR in ADO. Will not catch commits & pushes following a different pattern.
7576
prefix: 'PR ',
7677
url: `${this.baseUrl}/pullrequest/<num>`,
78+
alphanumeric: false,
79+
ignoreCase: false,
7780
title: `Open Pull Request #<num> on ${this.name}`,
7881

7982
type: 'pullrequest',

src/git/remotes/bitbucket-server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Range, Uri } from 'vscode';
2-
import type { DynamicAutolinkReference } from '../../annotations/autolinks';
3-
import type { AutolinkReference } from '../../config';
2+
import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks';
43
import type { GkProviderId } from '../../gk/models/repositoryIdentities';
54
import type { Brand, Unbrand } from '../../system/brand';
65
import { isSha } from '../models/reference';
@@ -23,13 +22,16 @@ export class BitbucketServerRemote extends RemoteProvider {
2322
{
2423
prefix: 'issue #',
2524
url: `${this.baseUrl}/issues/<num>`,
25+
alphanumeric: false,
26+
ignoreCase: true,
2627
title: `Open Issue #<num> on ${this.name}`,
2728

2829
type: 'issue',
2930
description: `${this.name} Issue #<num>`,
3031
},
3132
{
3233
prefix: 'pull request #',
34+
alphanumeric: false,
3335
ignoreCase: true,
3436
url: `${this.baseUrl}/pull-requests/<num>`,
3537
title: `Open Pull Request #<num> on ${this.name}`,

src/git/remotes/bitbucket.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Range, Uri } from 'vscode';
2-
import type { DynamicAutolinkReference } from '../../annotations/autolinks';
3-
import type { AutolinkReference } from '../../config';
2+
import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks';
43
import type { GkProviderId } from '../../gk/models/repositoryIdentities';
54
import type { Brand, Unbrand } from '../../system/brand';
65
import { isSha } from '../models/reference';
@@ -23,6 +22,8 @@ export class BitbucketRemote extends RemoteProvider {
2322
{
2423
prefix: 'issue #',
2524
url: `${this.baseUrl}/issues/<num>`,
25+
alphanumeric: false,
26+
ignoreCase: true,
2627
title: `Open Issue #<num> on ${this.name}`,
2728

2829
type: 'issue',
@@ -31,6 +32,8 @@ export class BitbucketRemote extends RemoteProvider {
3132
{
3233
prefix: 'pull request #',
3334
url: `${this.baseUrl}/pull-requests/<num>`,
35+
alphanumeric: false,
36+
ignoreCase: true,
3437
title: `Open Pull Request #<num> on ${this.name}`,
3538

3639
type: 'pullrequest',

src/git/remotes/gerrit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Range, Uri } from 'vscode';
2-
import type { DynamicAutolinkReference } from '../../annotations/autolinks';
3-
import type { AutolinkReference } from '../../config';
2+
import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks';
43
import type { GkProviderId } from '../../gk/models/repositoryIdentities';
54
import { isSha } from '../models/reference';
65
import type { Repository } from '../models/repository';
@@ -41,8 +40,9 @@ export class GerritRemote extends RemoteProvider {
4140
{
4241
prefix: 'Change-Id: ',
4342
url: `${this.baseReviewUrl}/q/<num>`,
44-
title: `Open Change #<num> on ${this.name}`,
4543
alphanumeric: true,
44+
ignoreCase: true,
45+
title: `Open Change #<num> on ${this.name}`,
4646

4747
description: `${this.name} Change #<num>`,
4848
},

0 commit comments

Comments
 (0)