Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds autolinked issues to comparisons
- Loading branch information
Showing
11 changed files
with
345 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
import { env, Uri } from 'vscode'; | ||
import { AutolinkedItemNode } from '../views/nodes/autolinkedItemNode'; | ||
import { Command, command, CommandContext, Commands } from './common'; | ||
|
||
export interface OpenIssueOnRemoteCommandArgs { | ||
clipboard?: boolean; | ||
issue: { url: string }; | ||
} | ||
|
||
@command() | ||
export class OpenIssueOnRemoteCommand extends Command { | ||
constructor() { | ||
super([Commands.OpenIssueOnRemote, Commands.CopyRemoteIssueUrl]); | ||
} | ||
|
||
protected override preExecute(context: CommandContext, args: OpenIssueOnRemoteCommandArgs) { | ||
if (context.type === 'viewItem' && context.node instanceof AutolinkedItemNode) { | ||
args = { | ||
...args, | ||
issue: { url: context.node.issue.url }, | ||
clipboard: context.command === Commands.CopyRemotePullRequestUrl, | ||
}; | ||
} | ||
|
||
return this.execute(args); | ||
} | ||
|
||
async execute(args: OpenIssueOnRemoteCommandArgs) { | ||
if (args.clipboard) { | ||
void (await env.clipboard.writeText(args.issue.url)); | ||
} else { | ||
void env.openExternal(Uri.parse(args.issue.url)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,58 @@ | ||
'use strict'; | ||
import { ColorThemeKind, ThemeColor, ThemeIcon, window } from 'vscode'; | ||
import { Colors } from '../../constants'; | ||
import { RemoteProviderReference } from './remoteProvider'; | ||
|
||
export const enum IssueOrPullRequestType { | ||
Issue = 'Issue', | ||
PullRequest = 'PullRequest', | ||
} | ||
|
||
export interface IssueOrPullRequest { | ||
type: 'Issue' | 'PullRequest'; | ||
type: IssueOrPullRequestType; | ||
provider: RemoteProviderReference; | ||
id: number; | ||
id: string; | ||
date: Date; | ||
title: string; | ||
closed: boolean; | ||
closedDate?: Date; | ||
url: string; | ||
} | ||
|
||
export namespace IssueOrPullRequest { | ||
export function getMarkdownIcon(issue: IssueOrPullRequest): string { | ||
if (issue.type === IssueOrPullRequestType.PullRequest) { | ||
if (issue.closed) { | ||
return `<span style="color:${ | ||
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#a371f7' : '#8250df' | ||
};">$(git-pull-request)</span>`; | ||
} | ||
return `<span style="color:${ | ||
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#3fb950' : '#1a7f37' | ||
};">$(git-pull-request)</span>`; | ||
} | ||
|
||
if (issue.closed) { | ||
return `<span style="color:${ | ||
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#a371f7' : '#8250df' | ||
};">$(pass)</span>`; | ||
} | ||
return `<span style="color:${ | ||
window.activeColorTheme.kind === ColorThemeKind.Dark ? '#3fb950' : '#1a7f37' | ||
};">$(issue)</span>`; | ||
} | ||
|
||
export function getThemeIcon(issue: IssueOrPullRequest): ThemeIcon { | ||
if (issue.type === IssueOrPullRequestType.PullRequest) { | ||
if (issue.closed) { | ||
return new ThemeIcon('git-pull-request', new ThemeColor(Colors.MergedPullRequestIconColor)); | ||
} | ||
return new ThemeIcon('git-pull-request', new ThemeColor(Colors.OpenPullRequestIconColor)); | ||
} | ||
|
||
if (issue.closed) { | ||
return new ThemeIcon('pass', new ThemeColor(Colors.MergedPullRequestIconColor)); | ||
} | ||
return new ThemeIcon('issues', new ThemeColor(Colors.OpenPullRequestIconColor)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
import { MarkdownString, TreeItem, TreeItemCollapsibleState } from 'vscode'; | ||
import { GitFile, IssueOrPullRequest, IssueOrPullRequestType } from '../../git/git'; | ||
import { GitUri } from '../../git/gitUri'; | ||
import { Dates } from '../../system'; | ||
import { ViewsWithCommits } from '../viewBase'; | ||
import { ContextValues, ViewNode } from './viewNode'; | ||
|
||
export interface FilesQueryResults { | ||
label: string; | ||
files: GitFile[] | undefined; | ||
filtered?: { | ||
filter: 'left' | 'right'; | ||
files: GitFile[]; | ||
}; | ||
} | ||
|
||
export class AutolinkedItemNode extends ViewNode<ViewsWithCommits> { | ||
constructor( | ||
view: ViewsWithCommits, | ||
parent: ViewNode, | ||
public readonly repoPath: string, | ||
public readonly issue: IssueOrPullRequest, | ||
) { | ||
super(GitUri.fromRepoPath(repoPath), view, parent); | ||
} | ||
|
||
override toClipboard(): string { | ||
return this.issue.url; | ||
} | ||
|
||
override get id(): string { | ||
return `${this.parent!.id!}:item(${this.issue.id})`; | ||
} | ||
|
||
getChildren(): ViewNode[] { | ||
return []; | ||
} | ||
|
||
getTreeItem(): TreeItem { | ||
const formatter = Dates.getFormatter(this.issue.closedDate ?? this.issue.date); | ||
|
||
const item = new TreeItem(`${this.issue.id}: ${this.issue.title}`, TreeItemCollapsibleState.None); | ||
item.description = formatter.fromNow(); | ||
item.iconPath = IssueOrPullRequest.getThemeIcon(this.issue); | ||
item.contextValue = | ||
this.issue.type === IssueOrPullRequestType.PullRequest | ||
? ContextValues.PullRequest | ||
: ContextValues.AutolinkedIssue; | ||
|
||
const linkTitle = ` "Open ${ | ||
this.issue.type === IssueOrPullRequestType.PullRequest ? 'Pull Request' : 'Issue' | ||
} \\#${this.issue.id} on ${this.issue.provider.name}"`; | ||
const tooltip = new MarkdownString( | ||
`${IssueOrPullRequest.getMarkdownIcon(this.issue)} [**${this.issue.title}**](${ | ||
this.issue.url | ||
}${linkTitle}) \\\n[#${this.issue.id}](${this.issue.url}${linkTitle}) was ${ | ||
this.issue.closed ? 'closed' : 'opened' | ||
} ${formatter.fromNow()}`, | ||
true, | ||
); | ||
tooltip.supportHtml = true; | ||
tooltip.isTrusted = true; | ||
|
||
item.tooltip = tooltip; | ||
|
||
return item; | ||
} | ||
} |
Oops, something went wrong.