Skip to content

Commit 887040b

Browse files
committed
Tries new branch autolinks on commit graph
1 parent 5932178 commit 887040b

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

src/plus/webviews/graph/graphWebview.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CancellationToken, ColorTheme, ConfigurationChangeEvent, Uri } from 'vscode';
22
import { CancellationTokenSource, Disposable, env, window } from 'vscode';
3+
import { Autolink } from '../../../annotations/autolinks';
34
import type { CreatePullRequestActionContext, OpenPullRequestActionContext } from '../../../api/gitlens';
45
import { getAvatarUri } from '../../../avatars';
56
import { parseCommandContext } from '../../../commands/base';
@@ -98,7 +99,7 @@ import { gate } from '../../../system/decorators/gate';
9899
import { debug, log } from '../../../system/decorators/log';
99100
import type { Deferrable } from '../../../system/function';
100101
import { debounce, disposableInterval } from '../../../system/function';
101-
import { count, find, last, map } from '../../../system/iterable';
102+
import { count, find, flatMap, last, map } from '../../../system/iterable';
102103
import { updateRecordValue } from '../../../system/object';
103104
import {
104105
getSettledValue,
@@ -2354,26 +2355,38 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
23542355
const branch = getSettledValue(branchResult);
23552356
if (branch != null) {
23562357
branchState = { ...branch.state };
2358+
const [remoteResult] = await Promise.allSettled([branch.getRemote()]);
2359+
const remote = getSettledValue(remoteResult);
2360+
2361+
if (remote?.provider != null) {
2362+
branchState.provider = {
2363+
name: remote.provider.name,
2364+
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
2365+
url: remote.provider.url({ type: RemoteResourceType.Repo }),
2366+
};
2367+
}
2368+
const autolinks = await this.container.autolinks.getAutolinks(branch.name, remote, {
2369+
isBranchName: true,
2370+
});
2371+
if (autolinks.size) {
2372+
const tm = new Map<string, string>();
2373+
branchState.issueLinks = [
2374+
...flatMap(autolinks, ([, { url, id, prefix, title, type, tokenize }]) => [
2375+
{ url: url, type: type, title: tokenize?.(id, 'markdown', tm) ?? prefix + id, tooltip: title },
2376+
]),
2377+
];
2378+
console.log({ tm: tm });
2379+
}
23572380

23582381
if (branch.upstream != null) {
23592382
branchState.upstream = branch.upstream.name;
23602383

23612384
const cancellation = this.createCancellation('state');
23622385

2363-
const [remoteResult, prResult] = await Promise.allSettled([
2364-
branch.getRemote(),
2386+
const [prResult] = await Promise.allSettled([
23652387
pauseOnCancelOrTimeout(branch.getAssociatedPullRequest(), cancellation.token, 100),
23662388
]);
23672389

2368-
const remote = getSettledValue(remoteResult);
2369-
if (remote?.provider != null) {
2370-
branchState.provider = {
2371-
name: remote.provider.name,
2372-
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
2373-
url: remote.provider.url({ type: RemoteResourceType.Repo }),
2374-
};
2375-
}
2376-
23772390
const maybePr = getSettledValue(prResult);
23782391
if (maybePr?.paused) {
23792392
const updatedBranchState = { ...branchState };

src/plus/webviews/graph/protocol.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export interface BranchState extends GitTrackingState {
135135
icon?: string;
136136
url?: string;
137137
};
138+
issueLinks?: {
139+
url: string;
140+
type?: string;
141+
title: string;
142+
tooltip?: string;
143+
}[];
138144
pr?: PullRequestShape;
139145
}
140146

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,8 @@ export function GraphWrapper({
11291129
);
11301130
};
11311131

1132+
console.log({ branchState: branchState });
1133+
11321134
return (
11331135
<>
11341136
<header className="titlebar graph-app__header">
@@ -1191,6 +1193,16 @@ export function GraphWrapper({
11911193
<span>
11921194
<span className="codicon codicon-chevron-right"></span>
11931195
</span>
1196+
{branchState?.issueLinks?.length && (
1197+
<GlPopover placement="bottom">
1198+
<button slot="anchor" type="button" className="action-button">
1199+
<a href={branchState?.issueLinks[0].url}>
1200+
{branchState?.issueLinks[0].title}
1201+
</a>
1202+
</button>
1203+
<div slot="content">{branchState?.issueLinks[0].tooltip}</div>
1204+
</GlPopover>
1205+
)}
11941206
{branchState?.pr && (
11951207
<GlPopover placement="bottom">
11961208
<button slot="anchor" type="button" className="action-button">

0 commit comments

Comments
 (0)