Skip to content

Commit e731faa

Browse files
committed
Adds provider icon for home active section
1 parent 3499119 commit e731faa

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

src/webviews/apps/plus/home/components/active-work.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import '../../../shared/components/card/card';
2020
import '../../../shared/components/commit/commit-stats';
2121
import '../../../shared/components/menu/menu-item';
2222
import '../../../shared/components/overlays/popover';
23+
import '../../../shared/components/overlays/tooltip';
2324
import '../../../shared/components/pills/tracking';
2425
import '../../../shared/components/rich/pr-icon';
2526

@@ -43,6 +44,12 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
4344
--button-padding: 0.1rem 0.2rem 0;
4445
margin-block: -1rem;
4546
}
47+
.section-heading-provider {
48+
color: inherit;
49+
}
50+
.tooltip {
51+
text-transform: none;
52+
}
4653
`,
4754
];
4855

@@ -103,9 +110,7 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
103110

104111
return html`
105112
<gl-section>
106-
<span slot="heading"
107-
><code-icon icon="repo" class="heading-icon"></code-icon> ${overview!.repository.name}</span
108-
>
113+
<span slot="heading">${this.renderRepositoryIcon(repo.provider)} ${repo.name}</span>
109114
<span slot="heading-actions"
110115
><gl-button
111116
aria-busy="${ifDefined(isFetching)}"
@@ -138,6 +143,29 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
138143
`;
139144
}
140145

146+
private renderRepositoryIcon(provider?: { name: string; icon?: string; url?: string }) {
147+
if (!provider) {
148+
return html`<code-icon icon="repo" class="heading-icon"></code-icon>`;
149+
}
150+
151+
let icon = 'repo';
152+
if (provider.icon != null) {
153+
icon = provider.icon === 'cloud' ? 'cloud' : `gl-provider-${provider.icon}`;
154+
}
155+
156+
return html`<gl-tooltip>
157+
${when(
158+
provider.url != null,
159+
() =>
160+
html`<a href=${provider.url} class="section-heading-provider"
161+
><code-icon icon=${icon} class="heading-icon"></code-icon
162+
></a>`,
163+
() => html`<code-icon icon=${icon} class="heading-icon"></code-icon>`,
164+
)}
165+
<span slot="content" class="tooltip">Open repository on ${provider.name}</span>
166+
</gl-tooltip>`;
167+
}
168+
141169
private renderRepoBranchCard(branch: GetOverviewBranch, repo: string, isFetching: boolean) {
142170
const { name, pr, state, workingTreeState, upstream } = branch;
143171
return html`

src/webviews/home/homeWebview.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { sortBranches } from '../../git/models/branch';
1616
import type { PullRequest } from '../../git/models/pullRequest';
1717
import { getComparisonRefsForPullRequest } from '../../git/models/pullRequest';
1818
import { getReferenceFromBranch } from '../../git/models/reference';
19+
import { RemoteResourceType } from '../../git/models/remoteResource';
1920
import type { Repository } from '../../git/models/repository';
2021
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../git/models/repository';
2122
import type { GitStatus } from '../../git/models/status';
@@ -506,17 +507,43 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
506507
this._invalidateOverview = undefined;
507508
if (overviewBranches == null) return undefined;
508509

510+
const formattedRepo = await this.formatRepository(repo);
511+
509512
const result: GetOverviewResponse = {
510513
repository: {
511-
name: repo.commonRepositoryName ?? repo.name,
512-
path: repo.path,
514+
...formattedRepo,
513515
branches: overviewBranches,
514516
},
515517
};
516518

517519
return result;
518520
}
519521

522+
private async formatRepository(repo: Repository): Promise<{
523+
name: string;
524+
path: string;
525+
provider?: {
526+
name: string;
527+
icon?: string;
528+
url?: string;
529+
};
530+
}> {
531+
const remotes = await repo.git.getBestRemotesWithProviders();
532+
const remote = remotes.find(r => r.hasIntegration()) ?? remotes[0];
533+
534+
return {
535+
name: repo.commonRepositoryName ?? repo.name,
536+
path: repo.path,
537+
provider: remote?.provider
538+
? {
539+
name: remote.provider.name,
540+
icon: remote.provider.icon === 'remote' ? 'cloud' : remote.provider.icon,
541+
url: remote.provider.url({ type: RemoteResourceType.Repo }),
542+
}
543+
: undefined,
544+
};
545+
}
546+
520547
private _repositorySubscription: RepositorySubscription | undefined;
521548
private selectRepository(repoPath?: string) {
522549
let repo: Repository | undefined;

src/webviews/home/protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ export type GetOverviewResponse =
116116
repository: {
117117
name: string;
118118
path: string;
119+
provider?: {
120+
name: string;
121+
icon?: string;
122+
url?: string;
123+
};
119124
branches: GetOverviewBranches;
120125
};
121126
}

0 commit comments

Comments
 (0)