Skip to content

Commit 4d68cff

Browse files
committed
Ensures proper metadata types
1 parent 0141523 commit 4d68cff

File tree

2 files changed

+106
-24
lines changed

2 files changed

+106
-24
lines changed

src/webviews/plus/graph/graphWebview.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ import {
143143
isGraphItemRefContext,
144144
isGraphItemRefGroupContext,
145145
isGraphItemTypedContext,
146+
toGraphHostingServiceType,
146147
toGraphIssueTrackerType,
147-
} from './graphWebviewUtils';
148+
} from './graphWebview.utils';
148149
import type {
149150
BranchState,
150151
DidChangeRefsVisibilityParams,
@@ -163,20 +164,17 @@ import type {
163164
GraphExcludedRef,
164165
GraphExcludeRefs,
165166
GraphExcludeTypes,
166-
GraphHostingServiceType,
167167
GraphIncludeOnlyRef,
168168
GraphIncludeOnlyRefs,
169169
GraphItemContext,
170170
GraphMinimapMarkerTypes,
171171
GraphMissingRefsMetadataType,
172-
GraphPullRequestMetadata,
173172
GraphRefMetadata,
174173
GraphRefMetadataType,
175174
GraphRepository,
176175
GraphScrollMarkerTypes,
177176
GraphSearchResults,
178177
GraphSelectedRows,
179-
GraphUpstreamMetadata,
180178
GraphWorkingTreeStats,
181179
OpenPullRequestDetailsParams,
182180
SearchOpenInViewParams,
@@ -1331,9 +1329,14 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
13311329
continue;
13321330
}
13331331

1334-
const prMetadata: GraphPullRequestMetadata = {
1335-
// TODO@eamodio: This is iffy, but works right now since `github` and `gitlab` are the only values possible currently
1336-
hostingServiceType: pr.provider.id as GraphHostingServiceType,
1332+
const hostingService = toGraphHostingServiceType(pr.provider.id);
1333+
if (hostingService == null) {
1334+
debugger;
1335+
continue;
1336+
}
1337+
1338+
const prMetadata: NonNullable<NonNullable<GraphRefMetadata>['pullRequest']>[number] = {
1339+
hostingServiceType: hostingService,
13371340
id: Number.parseInt(pr.id) || 0,
13381341
title: pr.title,
13391342
author: pr.author.name,
@@ -1376,7 +1379,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
13761379
continue;
13771380
}
13781381

1379-
const upstreamMetadata: GraphUpstreamMetadata = {
1382+
const upstreamMetadata: NonNullable<GraphRefMetadata>['upstream'] = {
13801383
name: getBranchNameWithoutRemote(upstream.name),
13811384
owner: getRemoteNameFromBranchName(upstream.name),
13821385
ahead: branch.upstream?.state.ahead ?? 0,
@@ -1405,9 +1408,10 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
14051408
this.container,
14061409
branch,
14071410
).then(issues => issues.value);
1408-
if (issues == null || issues.length === 0) {
1411+
if (!issues?.length) {
14091412
issues = await branch.getEnrichedAutolinks().then(async enrichedAutolinks => {
14101413
if (enrichedAutolinks == null) return undefined;
1414+
14111415
return (
14121416
await Promise.all(
14131417
[...enrichedAutolinks.values()].map(async ([issueOrPullRequestPromise]) =>
@@ -1421,27 +1425,30 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
14211425
);
14221426
});
14231427

1424-
if (issues == null || issues.length === 0) {
1428+
if (!issues?.length) {
14251429
metadata.issue = null;
14261430
this._refsMetadata.set(id, metadata);
14271431
continue;
14281432
}
14291433
}
14301434

1431-
const issuesMetadata = [];
1435+
const issuesMetadata: NonNullable<NonNullable<GraphRefMetadata>['issue']>[number][] = [];
14321436
for (const issue of issues) {
14331437
const issueTracker = toGraphIssueTrackerType(issue.provider.id);
1434-
if (issueTracker == null) continue;
1438+
if (issueTracker == null) {
1439+
debugger;
1440+
continue;
1441+
}
1442+
14351443
issuesMetadata.push({
1444+
issueTrackerType: issueTracker,
14361445
displayId: issue.id,
14371446
id: issue.nodeId ?? issue.id,
14381447
// TODO: This is a hack/workaround because the graph component doesn't support this in the tooltip.
14391448
// Update this once that is fixed.
14401449
title: `${issue.title}\nDouble-click to open issue on ${issue.provider.name}`,
1441-
issueTrackerType: issueTracker,
1442-
url: issue.url,
14431450
context: serializeWebviewItemContext<GraphItemContext>({
1444-
webviewItem: `gitlens:issue`,
1451+
webviewItem: 'gitlens:issue',
14451452
webviewItemValue: {
14461453
type: 'issue',
14471454
id: issue.id,

src/webviews/plus/graph/graphWebviewUtils.ts renamed to src/webviews/plus/graph/graphWebview.utils.ts

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { HostingIntegrationId, IssueIntegrationId } from '../../../constants.integrations';
1+
import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
22
import type { GitReference } from '../../../git/models/reference';
33
import { RemoteResourceType } from '../../../git/models/remoteResource';
44
import type { Repository } from '../../../git/models/repository';
5+
import type { GkProviderId } from '../../../git/models/repositoryIdentities';
6+
import type { RemoteProviderId } from '../../../git/remotes/remoteProvider';
57
import { isGitReference } from '../../../git/utils/reference.utils';
68
import { remoteProviderIdToIntegrationId } from '../../../plus/integrations/integrationService';
9+
import type { Unbrand } from '../../../system/brand';
710
import { getSettledValue } from '../../../system/promise';
811
import { isWebviewItemContext, isWebviewItemGroupContext } from '../../../system/webview';
912
import type {
1013
GraphBranchContextValue,
1114
GraphCommitContextValue,
1215
GraphContributorContextValue,
16+
GraphHostingServiceType,
1317
GraphIssueContextValue,
1418
GraphIssueTrackerType,
1519
GraphItemContext,
@@ -139,22 +143,93 @@ export function hasGitReference(o: unknown): o is { ref: GitReference } {
139143
return isGitReference(o.ref);
140144
}
141145

146+
export function toGraphHostingServiceType(id: string): GraphHostingServiceType | undefined {
147+
switch (id) {
148+
case 'github' satisfies RemoteProviderId:
149+
case 'github' satisfies Unbrand<GkProviderId>:
150+
case HostingIntegrationId.GitHub:
151+
return 'github';
152+
153+
case 'cloud-github-enterprise' satisfies RemoteProviderId:
154+
case 'githubEnterprise' satisfies Unbrand<GkProviderId>:
155+
case SelfHostedIntegrationId.CloudGitHubEnterprise:
156+
return 'githubEnterprise';
157+
158+
case 'gitlab' satisfies RemoteProviderId:
159+
case 'gitlab' satisfies Unbrand<GkProviderId>:
160+
case HostingIntegrationId.GitLab:
161+
return 'gitlab';
162+
163+
case 'cloud-gitlab-self-hosted' satisfies RemoteProviderId:
164+
case 'gitlabSelfHosted' satisfies Unbrand<GkProviderId>:
165+
case SelfHostedIntegrationId.CloudGitLabSelfHosted:
166+
return 'gitlabSelfHosted';
167+
168+
case 'azure-devops' satisfies RemoteProviderId:
169+
case 'azureDevops' satisfies Unbrand<GkProviderId>:
170+
case 'azure':
171+
case HostingIntegrationId.AzureDevOps:
172+
return 'azureDevops';
173+
174+
case 'bitbucket' satisfies RemoteProviderId:
175+
case 'bitbucket' satisfies Unbrand<GkProviderId>:
176+
case HostingIntegrationId.Bitbucket:
177+
return 'bitbucket';
178+
179+
case 'bitbucket-server' satisfies RemoteProviderId:
180+
case 'bitbucketServer' satisfies Unbrand<GkProviderId>:
181+
case SelfHostedIntegrationId.BitbucketServer:
182+
return 'bitbucketServer';
183+
184+
default:
185+
return undefined;
186+
}
187+
}
188+
142189
export function toGraphIssueTrackerType(id: string): GraphIssueTrackerType | undefined {
143190
switch (id) {
191+
case 'github' satisfies RemoteProviderId:
192+
case 'github' satisfies Unbrand<GkProviderId>:
144193
case HostingIntegrationId.GitHub:
145194
return 'github';
195+
196+
case 'cloud-github-enterprise' satisfies RemoteProviderId:
197+
case 'githubEnterprise' satisfies Unbrand<GkProviderId>:
198+
case SelfHostedIntegrationId.CloudGitHubEnterprise:
199+
return 'githubEnterprise';
200+
201+
case 'gitlab' satisfies RemoteProviderId:
202+
case 'gitlab' satisfies Unbrand<GkProviderId>:
146203
case HostingIntegrationId.GitLab:
147204
return 'gitlab';
205+
206+
case 'cloud-gitlab-self-hosted' satisfies RemoteProviderId:
207+
case 'gitlabSelfHosted' satisfies Unbrand<GkProviderId>:
208+
case SelfHostedIntegrationId.CloudGitLabSelfHosted:
209+
return 'gitlabSelfHosted';
210+
211+
case 'azure-devops' satisfies RemoteProviderId:
212+
case 'azureDevops' satisfies Unbrand<GkProviderId>:
213+
case 'azure':
214+
case HostingIntegrationId.AzureDevOps:
215+
return 'azureDevops';
216+
217+
case 'bitbucket' satisfies RemoteProviderId:
218+
case 'bitbucket' satisfies Unbrand<GkProviderId>:
219+
case HostingIntegrationId.Bitbucket:
220+
return 'bitbucket';
221+
222+
// case 'bitbucket-server' satisfies RemoteProviderId:
223+
// case 'bitbucketServer' satisfies Unbrand<GkProviderId>:
224+
// case SelfHostedIntegrationId.BitbucketServer:
225+
// return 'bitbucketServer';
226+
148227
case IssueIntegrationId.Jira:
149228
return 'jiraCloud';
150-
case HostingIntegrationId.AzureDevOps:
151-
case 'azure':
152-
case 'azure-devops':
153-
// TODO: Remove the casting once this is officially recognized by the component
154-
return 'azureDevops' as GraphIssueTrackerType;
155-
case 'bitbucket':
156-
// TODO: Remove the casting once this is officially recognized by the component
157-
return HostingIntegrationId.Bitbucket as GraphIssueTrackerType;
229+
230+
// case IssueIntegrationId.JiraServer:
231+
// return 'jiraServer';
232+
158233
default:
159234
return undefined;
160235
}

0 commit comments

Comments
 (0)