Skip to content

Commit

Permalink
Improves PR nodes icon & hover
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 16, 2021
1 parent 0da1c30 commit a65b894
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 54 deletions.
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3232,25 +3232,25 @@
"description": "Specifies the icon color of closed pull requests in the GitLens views",
"defaults": {
"dark": "#f85149",
"light": "#f85149",
"light": "#cf222e",
"highContrast": "#ff544b"
}
},
{
"id": "gitlens.openPullRequestIconColor",
"description": "Specifies the icon color of open pull requests in the GitLens views",
"defaults": {
"dark": "#56d364",
"light": "#56d364",
"dark": "#3fb950",
"light": "#1a7f37",
"highContrast": "#68ff79"
}
},
{
"id": "gitlens.mergedPullRequestIconColor",
"description": "Specifies the icon color of merged pull requests in the GitLens views",
"defaults": {
"dark": "#995dff",
"light": "#995dff",
"dark": "#a371f7",
"light": "#8250df",
"highContrast": "#8945ff"
}
},
Expand Down Expand Up @@ -8480,6 +8480,17 @@
"group": "inline@99",
"alt": "gitlens.copyRemotePullRequestUrl"
},
{
"command": "gitlens.views.openPullRequest",
"when": "gitlens:action:openPullRequest > 1 && viewItem =~ /gitlens:pullrequest\\b/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.openPullRequestOnRemote",
"when": "viewItem =~ /gitlens:pullrequest\\b/",
"group": "1_gitlens_actions@99",
"alt": "gitlens.copyRemotePullRequestUrl"
},
{
"command": "gitlens.views.addRemote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remotes\\b/",
Expand Down
6 changes: 3 additions & 3 deletions src/git/formatters/commitFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
const index = this._options.footnotes.size + 1;
this._options.footnotes.set(
index,
`[**$(git-pull-request) ${prTitle}**](${pr.url} "Open Pull Request \\#${pr.id} on ${
pr.provider.name
}")\\\n${GlyphChars.Space.repeat(4)} #${
`${PullRequest.getMarkdownIcon(pr)} [**${prTitle}**](${pr.url} "Open Pull Request \\#${
pr.id
} on ${pr.provider.name}")\\\n${GlyphChars.Space.repeat(4)} #${
pr.id
} ${pr.state.toLocaleLowerCase()} ${pr.formatDateFromNow()}`,
);
Expand Down
34 changes: 34 additions & 0 deletions src/git/models/pullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
import { ColorThemeKind, ThemeColor, ThemeIcon, window } from 'vscode';
import { configuration, DateStyle } from '../../configuration';
import { Colors } from '../../constants';
import { Dates, memoize } from '../../system';
import { RemoteProviderReference } from './remoteProvider';

Expand All @@ -24,6 +26,38 @@ export class PullRequest {
return pr instanceof PullRequest;
}

static getMarkdownIcon(pullRequest: PullRequest): string {
switch (pullRequest.state) {
case PullRequestState.Open:
return `<span style="color:${
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#3fb950' : '#1a7f37'
};">$(git-pull-request)</span>`;
case PullRequestState.Closed:
return `<span style="color:${
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#f85149' : '#cf222e'
};">$(git-pull-request-closed)</span>`;
case PullRequestState.Merged:
return `<span style="color:${
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#a371f7' : '#8250df'
};">$(git-merge)</span>`;
default:
return '$(git-pull-request)';
}
}

static getThemeIcon(pullRequest: PullRequest): ThemeIcon {
switch (pullRequest.state) {
case PullRequestState.Open:
return new ThemeIcon('git-pull-request', new ThemeColor(Colors.OpenPullRequestIconColor));
case PullRequestState.Closed:
return new ThemeIcon('git-pull-request-closed', new ThemeColor(Colors.ClosedPullRequestIconColor));
case PullRequestState.Merged:
return new ThemeIcon('git-merge', new ThemeColor(Colors.MergedPullRequestIconColor));
default:
return new ThemeIcon('git-pull-request');
}
}

constructor(
public readonly provider: RemoteProviderReference,
public readonly author: {
Expand Down
80 changes: 49 additions & 31 deletions src/views/nodes/pullRequestNode.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
'use strict';
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Colors } from '../../constants';
import { MarkdownString, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GitBranch, GitCommit, PullRequest, PullRequestState } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { ViewsWithPullRequests } from '../viewBase';
import { ViewsWithCommits } from '../viewBase';
import { RepositoryNode } from './repositoryNode';
import { ContextValues, ViewNode } from './viewNode';

export class PullRequestNode extends ViewNode<ViewsWithPullRequests> {
export class PullRequestNode extends ViewNode<ViewsWithCommits> {
static key = ':pullrequest';
static getId(repoPath: string, id: string, ref: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${id}):${ref}`;
static getId(repoPath: string, id: string, refOrParent: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${id}):${refOrParent}`;
}

public readonly pullRequest: PullRequest;
private readonly branchOrCommit?: GitBranch | GitCommit;
private readonly repoPath: string;

constructor(
view: ViewsWithPullRequests,
view: ViewsWithCommits,
parent: ViewNode,
public readonly pullRequest: PullRequest,
public readonly branchOrCommit: GitBranch | GitCommit,
pullRequest: PullRequest,
branchOrCommitOrRepoPath: GitBranch | GitCommit | string,
) {
super(GitUri.fromRepoPath(branchOrCommit.repoPath), view, parent);
let branchOrCommit;
let repoPath;
if (typeof branchOrCommitOrRepoPath === 'string') {
repoPath = branchOrCommitOrRepoPath;
} else {
repoPath = branchOrCommitOrRepoPath.repoPath;
branchOrCommit = branchOrCommitOrRepoPath;
}

super(GitUri.fromRepoPath(repoPath), view, parent);

this.branchOrCommit = branchOrCommit;
this.pullRequest = pullRequest;
this.repoPath = repoPath;
}

override toClipboard(): string {
return this.pullRequest.url;
}

override get id(): string {
return PullRequestNode.getId(this.branchOrCommit.repoPath, this.pullRequest.id, this.branchOrCommit.ref);
return PullRequestNode.getId(this.repoPath, this.pullRequest.id, this.branchOrCommit?.ref ?? this.parent!.id!);
}

getChildren(): ViewNode[] {
Expand All @@ -39,30 +55,32 @@ export class PullRequestNode extends ViewNode<ViewsWithPullRequests> {
item.id = this.id;
item.contextValue = ContextValues.PullRequest;
item.description = `${this.pullRequest.state}, ${this.pullRequest.formatDateFromNow()}`;
item.iconPath = new ThemeIcon(
'git-pull-request',
new ThemeColor(
this.pullRequest.state === PullRequestState.Closed
? Colors.ClosedPullRequestIconColor
: this.pullRequest.state === PullRequestState.Merged
? Colors.MergedPullRequestIconColor
: Colors.OpenPullRequestIconColor,
),
);
item.tooltip = `${this.pullRequest.title}\n#${this.pullRequest.id} by ${this.pullRequest.author.name} was ${
this.pullRequest.state === PullRequestState.Open ? 'opened' : this.pullRequest.state.toLowerCase()
} ${this.pullRequest.formatDateFromNow()}`;
item.iconPath = PullRequest.getThemeIcon(this.pullRequest);

const tooltip = new MarkdownString('', true);
tooltip.supportHtml = true;
tooltip.isTrusted = true;

if (this.branchOrCommit instanceof GitCommit) {
item.tooltip = `Commit ${this.branchOrCommit.shortSha} was introduced by PR #${this.pullRequest.id}\n${item.tooltip}`;
tooltip.appendMarkdown(
`Commit \`$(git-commit) ${this.branchOrCommit.shortSha}\` was introduced by $(git-pull-request) PR #${this.pullRequest.id}\n\n`,
);
}

// item.tooltip = `Open Pull Request #${this.pullRequest.number} on ${this.pullRequest.provider}`;
// item.command = {
// title: 'Open Pull Request',
// command: Commands.OpenPullRequestOnRemote,
// arguments: [this],
// };
const linkTitle = ` "Open Pull Request \\#${this.pullRequest.id} on ${this.pullRequest.provider.name}"`;
tooltip.appendMarkdown(
`${PullRequest.getMarkdownIcon(this.pullRequest)} [**${this.pullRequest.title}**](${
this.pullRequest.url
}${linkTitle}) \\\n[#${this.pullRequest.id}](${this.pullRequest.url}${linkTitle}) by [@${
this.pullRequest.author.name
}](${this.pullRequest.author.url} "Open @${this.pullRequest.author.name} on ${
this.pullRequest.provider.name
}") was ${
this.pullRequest.state === PullRequestState.Open ? 'opened' : this.pullRequest.state.toLowerCase()
} ${this.pullRequest.formatDateFromNow()}`,
);

item.tooltip = tooltip;

return item;
}
Expand Down
16 changes: 1 addition & 15 deletions src/views/viewBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,7 @@ export type View =
| SearchAndCompareView
| StashesView
| TagsView;
export type ViewsWithCommits =
| BranchesView
| CommitsView
| ContributorsView
| RemotesView
| RepositoriesView
| SearchAndCompareView
| TagsView;
export type ViewsWithPullRequests =
| BranchesView
| CommitsView
| ContributorsView
| RemotesView
| RepositoriesView
| SearchAndCompareView;
export type ViewsWithCommits = Exclude<View, FileHistoryView | LineHistoryView | StashesView>;

export interface TreeViewNodeCollapsibleStateChangeEvent<T> extends TreeViewExpansionEvent<T> {
state: TreeItemCollapsibleState;
Expand Down

0 comments on commit a65b894

Please sign in to comment.