浏览代码

Adds copy PR url command

main
Eric Amodio 4 年前
父节点
当前提交
9c780580d3
共有 3 个文件被更改,包括 55 次插入13 次删除
  1. +16
    -1
      package.json
  2. +1
    -0
      src/commands/common.ts
  3. +38
    -12
      src/commands/openPullRequestOnRemote.ts

+ 16
- 1
package.json 查看文件

@ -154,6 +154,7 @@
"onCommand:gitlens.openFileRevision",
"onCommand:gitlens.openFileRevisionFrom",
"onCommand:gitlens.openPullRequestOnRemote",
"onCommand:gitlens.copyRemotePullRequestUrl",
"onCommand:gitlens.openAssociatedPullRequestOnRemote",
"onCommand:gitlens.openRepoOnRemote",
"onCommand:gitlens.copyRemoteRepositoryUrl",
@ -3142,6 +3143,15 @@
"icon": "$(globe)"
},
{
"command": "gitlens.copyRemotePullRequestUrl",
"title": "Copy Pull Request Url",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openAssociatedPullRequestOnRemote",
"title": "Open Associated Pull Request",
"category": "GitLens",
@ -4712,6 +4722,10 @@
"when": "false"
},
{
"command": "gitlens.copyRemotePullRequestUrl",
"when": "false"
},
{
"command": "gitlens.openAssociatedPullRequestOnRemote",
"when": "gitlens:activeFileStatus =~ /blameable/ && gitlens:activeFileStatus =~ /remotes/"
},
@ -6842,7 +6856,8 @@
{
"command": "gitlens.openPullRequestOnRemote",
"when": "viewItem =~ /gitlens:pullrequest\\b/",
"group": "inline@99"
"group": "inline@99",
"alt": "gitlens.copyRemotePullRequestUrl"
},
{
"command": "gitlens.views.addRemote",

+ 1
- 0
src/commands/common.ts 查看文件

@ -39,6 +39,7 @@ export enum Commands {
CopyRemoteBranchUrl = 'gitlens.copyRemoteBranchUrl',
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemotePullRequestUrl = 'gitlens.copyRemotePullRequestUrl',
CopyRemoteRepositoryUrl = 'gitlens.copyRemoteRepositoryUrl',
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
DiffDirectory = 'gitlens.diffDirectory',

+ 38
- 12
src/commands/openPullRequestOnRemote.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import { env, Uri } from 'vscode';
import { env, Uri, window } from 'vscode';
import {
Command,
command,
@ -9,9 +9,12 @@ import {
isCommandContextViewNodeHasFileCommit,
} from './common';
import { Container } from '../container';
import { PullRequestNode } from '../views/nodes/pullRequestNode';
import { PullRequestNode } from '../views/nodes';
import { Logger } from '../logger';
import { Messages } from '../messages';
export interface OpenPullRequestOnRemoteCommandArgs {
clipboard?: boolean;
ref?: string;
repoPath?: string;
pr?: { url: string };
@ -20,19 +23,24 @@ export interface OpenPullRequestOnRemoteCommandArgs {
@command()
export class OpenPullRequestOnRemoteCommand extends Command {
constructor() {
super([Commands.OpenPullRequestOnRemote, Commands.OpenAssociatedPullRequestOnRemote]);
super([
Commands.OpenPullRequestOnRemote,
Commands.CopyRemotePullRequestUrl,
Commands.OpenAssociatedPullRequestOnRemote,
]);
}
protected preExecute(context: CommandContext, args?: OpenPullRequestOnRemoteCommandArgs) {
if (context.command === Commands.OpenPullRequestOnRemote) {
if (context.type === 'viewItem' && context.node instanceof PullRequestNode) {
args = {
...args,
pr: { url: context.node.pullRequest.url },
};
if (context.command === Commands.OpenAssociatedPullRequestOnRemote) {
if (isCommandContextViewNodeHasCommit(context) || isCommandContextViewNodeHasFileCommit(context)) {
args = { ...args, ref: context.node.commit.sha, repoPath: context.node.commit.repoPath };
}
} else if (isCommandContextViewNodeHasCommit(context) || isCommandContextViewNodeHasFileCommit(context)) {
args = { ...args, ref: context.node.commit.sha, repoPath: context.node.commit.repoPath };
} else if (context.type === 'viewItem' && context.node instanceof PullRequestNode) {
args = {
...args,
pr: { url: context.node.pullRequest.url },
clipboard: context.command === Commands.CopyRemotePullRequestUrl,
};
}
return this.execute(args);
@ -52,6 +60,24 @@ export class OpenPullRequestOnRemoteCommand extends Command {
args.pr = pr;
}
void env.openExternal(Uri.parse(args.pr.url));
if (args.clipboard) {
try {
void (await env.clipboard.writeText(args.pr.url));
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg.includes("Couldn't find the required `xsel` binary")) {
void window.showErrorMessage(
'Unable to copy remote url, xsel is not installed. Please install it via your package manager, e.g. `sudo apt install xsel`',
);
return;
}
Logger.error(ex, 'CopyRemotePullRequestCommand');
void Messages.showGenericErrorMessage('Unable to copy pull request url');
}
} else {
void env.openExternal(Uri.parse(args.pr.url));
}
}
}

正在加载...
取消
保存