Browse Source

Improves PR nodes icon & hover

main
Eric Amodio 3 years ago
parent
commit
a65b894b4e
5 changed files with 103 additions and 54 deletions
  1. +16
    -5
      package.json
  2. +3
    -3
      src/git/formatters/commitFormatter.ts
  3. +34
    -0
      src/git/models/pullRequest.ts
  4. +49
    -31
      src/views/nodes/pullRequestNode.ts
  5. +1
    -15
      src/views/viewBase.ts

+ 16
- 5
package.json View File

@ -3232,7 +3232,7 @@
"description": "Specifies the icon color of closed pull requests in the GitLens views",
"defaults": {
"dark": "#f85149",
"light": "#f85149",
"light": "#cf222e",
"highContrast": "#ff544b"
}
},
@ -3240,8 +3240,8 @@
"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"
}
},
@ -3249,8 +3249,8 @@
"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"
}
},
@ -8481,6 +8481,17 @@
"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/",
"group": "inline@1"

+ 3
- 3
src/git/formatters/commitFormatter.ts View File

@ -523,9 +523,9 @@ export class CommitFormatter extends Formatter {
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()}`,
);

+ 34
- 0
src/git/models/pullRequest.ts View File

@ -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';
@ -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: {

+ 49
- 31
src/views/nodes/pullRequestNode.ts View File

@ -1,25 +1,41 @@
'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 {
@ -27,7 +43,7 @@ export class PullRequestNode extends ViewNode {
}
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[] {
@ -39,30 +55,32 @@ export class PullRequestNode extends ViewNode {
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;
}

+ 1
- 15
src/views/viewBase.ts View File

@ -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;

Loading…
Cancel
Save