|
@ -1,5 +1,5 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
import { env, Uri } from 'vscode'; |
|
|
|
|
|
|
|
|
import { env, Uri, window } from 'vscode'; |
|
|
import { |
|
|
import { |
|
|
Command, |
|
|
Command, |
|
|
command, |
|
|
command, |
|
@ -9,9 +9,12 @@ import { |
|
|
isCommandContextViewNodeHasFileCommit, |
|
|
isCommandContextViewNodeHasFileCommit, |
|
|
} from './common'; |
|
|
} from './common'; |
|
|
import { Container } from '../container'; |
|
|
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 { |
|
|
export interface OpenPullRequestOnRemoteCommandArgs { |
|
|
|
|
|
clipboard?: boolean; |
|
|
ref?: string; |
|
|
ref?: string; |
|
|
repoPath?: string; |
|
|
repoPath?: string; |
|
|
pr?: { url: string }; |
|
|
pr?: { url: string }; |
|
@ -20,19 +23,24 @@ export interface OpenPullRequestOnRemoteCommandArgs { |
|
|
@command() |
|
|
@command() |
|
|
export class OpenPullRequestOnRemoteCommand extends Command { |
|
|
export class OpenPullRequestOnRemoteCommand extends Command { |
|
|
constructor() { |
|
|
constructor() { |
|
|
super([Commands.OpenPullRequestOnRemote, Commands.OpenAssociatedPullRequestOnRemote]); |
|
|
|
|
|
|
|
|
super([ |
|
|
|
|
|
Commands.OpenPullRequestOnRemote, |
|
|
|
|
|
Commands.CopyRemotePullRequestUrl, |
|
|
|
|
|
Commands.OpenAssociatedPullRequestOnRemote, |
|
|
|
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected preExecute(context: CommandContext, args?: OpenPullRequestOnRemoteCommandArgs) { |
|
|
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); |
|
|
return this.execute(args); |
|
@ -52,6 +60,24 @@ export class OpenPullRequestOnRemoteCommand extends Command { |
|
|
args.pr = pr; |
|
|
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)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |