Skip to content

Commit e4eb1cf

Browse files
committed
Adds common repository shape
1 parent a346d83 commit e4eb1cf

File tree

10 files changed

+69
-75
lines changed

10 files changed

+69
-75
lines changed

src/git/models/repositoryShape.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { SupportedCloudIntegrationIds } from '../../constants.integrations';
2+
import type { RemoteProviderSupportedFeatures } from '../remotes/remoteProvider';
3+
4+
export interface RepositoryShape {
5+
id: string;
6+
name: string;
7+
path: string;
8+
uri: string;
9+
virtual: boolean;
10+
11+
provider?: {
12+
name: string;
13+
icon?: string;
14+
integration?: { id: SupportedCloudIntegrationIds; connected: boolean };
15+
supportedFeatures: RemoteProviderSupportedFeatures;
16+
url?: string;
17+
};
18+
}

src/git/utils/-webview/repository.utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import { convertRemoteProviderIdToIntegrationId } from '../../../plus/integrations/utils/-webview/integration.utils';
12
import { configuration } from '../../../system/-webview/configuration';
23
import { formatDate, fromNow } from '../../../system/date';
34
import { map } from '../../../system/iterable';
5+
import type { GitRemote } from '../../models/remote';
6+
import { RemoteResourceType } from '../../models/remoteResource';
47
import type { Repository } from '../../models/repository';
8+
import type { RepositoryShape } from '../../models/repositoryShape';
9+
import type { RemoteProvider } from '../../remotes/remoteProvider';
510
import { millisecondsPerDay } from '../fetch.utils';
611

712
export function formatLastFetched(lastFetched: number, short: boolean = true): string {
@@ -57,3 +62,30 @@ export async function groupRepositories(repositories: Repository[]): Promise<Map
5762

5863
return new Map(map(result, ([, r]) => [r.repo, r.worktrees]));
5964
}
65+
66+
export function toRepositoryShape(repo: Repository): RepositoryShape {
67+
return { id: repo.id, name: repo.name, path: repo.path, uri: repo.uri.toString(), virtual: repo.virtual };
68+
}
69+
70+
export async function toRepositoryShapeWithProvider(
71+
repo: Repository,
72+
remote: GitRemote<RemoteProvider> | undefined,
73+
): Promise<RepositoryShape> {
74+
let provider: RepositoryShape['provider'] | undefined;
75+
if (remote?.provider != null) {
76+
provider = {
77+
name: remote.provider.name,
78+
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
79+
integration: remote.supportsIntegration()
80+
? {
81+
id: convertRemoteProviderIdToIntegrationId(remote.provider.id)!,
82+
connected: remote.maybeIntegrationConnected ?? false,
83+
}
84+
: undefined,
85+
supportedFeatures: remote.provider.supportedFeatures,
86+
url: await remote.provider.url({ type: RemoteResourceType.Repo }),
87+
};
88+
}
89+
90+
return { ...toRepositoryShape(repo), provider: provider };
91+
}

src/webviews/apps/plus/graph/graph-header.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
704704
?disabled=${!this.hostState.repositories || this.hostState.repositories.length < 2}
705705
@click=${() => this.handleChooseRepository()}
706706
>
707-
<span class="action-button__truncated">${repo?.formattedName ?? 'none selected'}</span
708-
>${when(
707+
<span class="action-button__truncated">${repo?.name ?? 'none selected'}</span>${when(
709708
this.hostState.repositories && this.hostState.repositories.length > 1,
710709
() => html`
711710
<code-icon
@@ -931,11 +930,11 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
931930
hoist
932931
>
933932
<code-icon icon="chevron-down" slot="expand-icon"></code-icon>
934-
<sl-option value="all" ?disabled=${repo?.isVirtual}> All Branches </sl-option>
935-
<sl-option value="smart" ?disabled=${repo?.isVirtual}>
933+
<sl-option value="all" ?disabled=${repo?.virtual}> All Branches </sl-option>
934+
<sl-option value="smart" ?disabled=${repo?.virtual}>
936935
Smart Branches
937936
${when(
938-
!repo?.isVirtual,
937+
!repo?.virtual,
939938
() => html`
940939
<gl-tooltip placement="right" slot="suffix">
941940
<code-icon icon="info"></code-icon>
@@ -1040,7 +1039,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
10401039
<div slot="content">
10411040
<menu-label>Graph Filters</menu-label>
10421041
${when(
1043-
repo?.isVirtual !== true,
1042+
repo?.virtual !== true,
10441043
() => html`
10451044
<menu-item role="none">
10461045
<gl-tooltip

src/webviews/apps/plus/graph/sidebar/sidebar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class GlGraphSideBar extends LitElement {
7777

7878
get include(): undefined | IconTypes[] {
7979
const repo = this._state.repositories?.find(item => item.path === this._state.selectedRepository);
80-
return repo?.isVirtual
80+
return repo?.virtual
8181
? (['branches', 'remotes', 'tags'] as const)
8282
: (['branches', 'remotes', 'tags', 'stashes', 'worktrees'] as const);
8383
}

src/webviews/home/homeWebview.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type { GitWorktree } from '../../git/models/worktree';
3939
import { getAssociatedIssuesForBranch } from '../../git/utils/-webview/branch.issue.utils';
4040
import { getBranchMergeTargetInfo } from '../../git/utils/-webview/branch.utils';
4141
import { getReferenceFromBranch } from '../../git/utils/-webview/reference.utils';
42+
import { toRepositoryShapeWithProvider } from '../../git/utils/-webview/repository.utils';
4243
import { sortBranches } from '../../git/utils/-webview/sorting';
4344
import { getOpenedWorktreesByBranch, groupWorktreesByBranch } from '../../git/utils/-webview/worktree.utils';
4445
import { getBranchNameWithoutRemote } from '../../git/utils/branch.utils';
@@ -956,19 +957,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
956957
private async formatRepository(repo: Repository): Promise<OverviewRepository> {
957958
const remotes = await repo.git.remotes.getBestRemotesWithProviders();
958959
const remote = remotes.find(r => r.supportsIntegration()) ?? remotes[0];
959-
960-
return {
961-
name: repo.commonRepositoryName ?? repo.name,
962-
path: repo.path,
963-
provider: remote?.provider
964-
? {
965-
name: remote.provider.name,
966-
supportedFeatures: remote.provider.supportedFeatures,
967-
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
968-
url: await remote.provider.url({ type: RemoteResourceType.Repo }),
969-
}
970-
: undefined,
971-
};
960+
return toRepositoryShapeWithProvider(repo, remote);
972961
}
973962

974963
private _repositorySubscription: SubscriptionManager<Repository> | undefined;

src/webviews/home/protocol.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Issue } from '../../git/models/issue';
77
import type { MergeConflict } from '../../git/models/mergeConflict';
88
import type { GitPausedOperationStatus } from '../../git/models/pausedOperationStatus';
99
import type { GitBranchReference } from '../../git/models/reference';
10+
import type { RepositoryShape } from '../../git/models/repositoryShape';
1011
import type { RemoteProviderSupportedFeatures } from '../../git/remotes/remoteProvider';
1112
import type { AIModel } from '../../plus/ai/models/model';
1213
import type { Subscription } from '../../plus/gk/models/subscription';
@@ -205,16 +206,7 @@ export interface GetOverviewBranch {
205206
};
206207
}
207208

208-
export interface OverviewRepository {
209-
name: string;
210-
path: string;
211-
provider?: {
212-
name: string;
213-
icon?: string;
214-
url?: string;
215-
supportedFeatures: RemoteProviderSupportedFeatures;
216-
};
217-
}
209+
export type OverviewRepository = RepositoryShape;
218210

219211
// TODO: look at splitting off selected repo
220212
export type GetActiveOverviewResponse =

src/webviews/plus/graph/graphWebview.utils.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import {
44
IssuesCloudHostIntegrationId,
55
} from '../../../constants.integrations';
66
import type { GitReference } from '../../../git/models/reference';
7-
import { RemoteResourceType } from '../../../git/models/remoteResource';
87
import type { Repository } from '../../../git/models/repository';
98
import type { GkProviderId } from '../../../git/models/repositoryIdentities';
109
import type { RemoteProviderId } from '../../../git/remotes/remoteProvider';
10+
import { toRepositoryShapeWithProvider } from '../../../git/utils/-webview/repository.utils';
1111
import { isGitReference } from '../../../git/utils/reference.utils';
12-
import { convertRemoteProviderIdToIntegrationId } from '../../../plus/integrations/utils/-webview/integration.utils';
1312
import type { Unbrand } from '../../../system/brand';
1413
import { getSettledValue } from '../../../system/promise';
1514
import { isWebviewItemContext, isWebviewItemGroupContext } from '../../../system/webview';
@@ -34,33 +33,14 @@ import type {
3433
} from './protocol';
3534

3635
export async function formatRepositories(repositories: Repository[]): Promise<GraphRepository[]> {
37-
if (repositories.length === 0) return Promise.resolve([]);
36+
if (!repositories.length) return [];
3837

3938
const result = await Promise.allSettled(
4039
repositories.map<Promise<GraphRepository>>(async repo => {
4140
const remotes = await repo.git.remotes.getBestRemotesWithProviders();
4241
const remote = remotes.find(r => r.supportsIntegration()) ?? remotes[0];
4342

44-
return {
45-
formattedName: repo.name,
46-
id: repo.id,
47-
name: repo.name,
48-
path: repo.path,
49-
provider: remote?.provider
50-
? {
51-
name: remote.provider.name,
52-
integration: remote.supportsIntegration()
53-
? {
54-
id: convertRemoteProviderIdToIntegrationId(remote.provider.id)!,
55-
connected: remote.maybeIntegrationConnected ?? false,
56-
}
57-
: undefined,
58-
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
59-
url: await remote.provider.url({ type: RemoteResourceType.Repo }),
60-
}
61-
: undefined,
62-
isVirtual: repo.provider.virtual,
63-
};
43+
return toRepositoryShapeWithProvider(repo, remote);
6444
}),
6545
);
6646
return result.map(r => getSettledValue(r)).filter(r => r != null);

src/webviews/plus/graph/protocol.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type {
2424
WorkDirStats,
2525
} from '@gitkraken/gitkraken-components';
2626
import type { Config, DateStyle, GraphBranchesVisibility } from '../../../config';
27-
import type { SupportedCloudIntegrationIds } from '../../../constants.integrations';
2827
import type { SearchQuery } from '../../../constants.search';
2928
import type { FeaturePreview } from '../../../features';
3029
import type { RepositoryVisibility } from '../../../git/gitProvider';
@@ -39,6 +38,7 @@ import type {
3938
GitTagReference,
4039
} from '../../../git/models/reference';
4140
import type { ProviderReference } from '../../../git/models/remoteProvider';
41+
import type { RepositoryShape } from '../../../git/models/repositoryShape';
4242
import type { GitGraphSearchResultData } from '../../../git/search';
4343
import type { Subscription } from '../../../plus/gk/models/subscription';
4444
import type { DateTimeFormat } from '../../../system/date';
@@ -156,22 +156,7 @@ export interface GraphPaging {
156156
hasMore: boolean;
157157
}
158158

159-
export interface GraphRepository {
160-
formattedName: string;
161-
id: string;
162-
name: string;
163-
path: string;
164-
isVirtual: boolean;
165-
provider?: {
166-
name: string;
167-
integration?: {
168-
id: SupportedCloudIntegrationIds;
169-
connected: boolean;
170-
};
171-
icon?: string;
172-
url?: string;
173-
};
174-
}
159+
export type GraphRepository = RepositoryShape;
175160

176161
export interface GraphCommitIdentity {
177162
name: string;

src/webviews/plus/timeline/protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Uri } from 'vscode';
22
import type { FeatureAccess } from '../../../features';
33
import type { GitReference } from '../../../git/models/reference';
4+
import type { RepositoryShape } from '../../../git/models/repositoryShape';
45
import type { Serialized } from '../../../system/serialize';
56
import type { IpcScope, WebviewState } from '../../protocol';
67
import { IpcCommand, IpcNotification, IpcRequest } from '../../protocol';
@@ -20,7 +21,7 @@ export interface State extends WebviewState {
2021
};
2122

2223
scope: TimelineScopeSerialized | undefined;
23-
repository: { id: string; name: string; ref: GitReference | undefined; uri: string; virtual: boolean } | undefined;
24+
repository: (RepositoryShape & { ref: GitReference | undefined }) | undefined;
2425

2526
access: FeatureAccess;
2627
}

src/webviews/plus/timeline/timelineWebview.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
2424
import { uncommitted } from '../../../git/models/revision';
2525
import { getReference } from '../../../git/utils/-webview/reference.utils';
26+
import { toRepositoryShape } from '../../../git/utils/-webview/repository.utils';
2627
import { getPseudoCommitsWithStats } from '../../../git/utils/-webview/statusFile.utils';
2728
import { getChangedFilesCount } from '../../../git/utils/commit.utils';
2829
import { createReference } from '../../../git/utils/reference.utils';
@@ -653,10 +654,7 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
653654
const { uri } = scope;
654655
const relativePath = git.getRelativePath(uri, repo.uri);
655656
const ref = getReference(await repo.git.branches.getBranch());
656-
const repository: State['repository'] =
657-
repo != null
658-
? { id: repo.id, name: repo.name, ref: ref, uri: repo.uri.toString(), virtual: repo.virtual }
659-
: undefined;
657+
const repository: State['repository'] = repo != null ? { ...toRepositoryShape(repo), ref: ref } : undefined;
660658

661659
scope.head ??= ref;
662660
if (scope.base == null) {

0 commit comments

Comments
 (0)