diff --git a/CHANGELOG.md b/CHANGELOG.md index 91fe9b7..31bda05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#1222](https://github.com/eamodio/vscode-gitlens/issues/1222) - GitLens: Open Associated Pull Request doesn't work - Fixes [#1223](https://github.com/eamodio/vscode-gitlens/issues/1223) - commit pane, ${tips} does not show tags - Fixes [#1225](https://github.com/eamodio/vscode-gitlens/issues/1225) - Changes hover is wrong if the original/new line number doesn't match - Fixes [#1045](https://github.com/eamodio/vscode-gitlens/issues/1045) - View File History not working - absolute path used — thanks to [PR #1209](https://github.com/eamodio/vscode-gitlens/pull/1209) by Mike Surcouf ([@mikes-gh](https://github.com/mikes-gh)) diff --git a/src/commands.ts b/src/commands.ts index fc74411..290b141 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -20,6 +20,7 @@ export * from './commands/diffWithWorking'; export * from './commands/externalDiff'; export * from './commands/gitCommands'; export * from './commands/inviteToLiveShare'; +export * from './commands/openAssociatedPullRequestOnRemote'; export * from './commands/openBranchesOnRemote'; export * from './commands/openBranchOnRemote'; export * from './commands/openChangedFiles'; diff --git a/src/commands/openAssociatedPullRequestOnRemote.ts b/src/commands/openAssociatedPullRequestOnRemote.ts new file mode 100644 index 0000000..db47ea2 --- /dev/null +++ b/src/commands/openAssociatedPullRequestOnRemote.ts @@ -0,0 +1,39 @@ +'use strict'; +import { TextEditor, Uri } from 'vscode'; +import { ActiveEditorCommand, command, Commands, executeCommand, getCommandUri } from './common'; +import { Container } from '../container'; +import { Logger } from '../logger'; +import { GitUri } from '../git/gitUri'; +import { OpenPullRequestOnRemoteCommandArgs } from './openPullRequestOnRemote'; + +@command() +export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorCommand { + constructor() { + super(Commands.OpenAssociatedPullRequestOnRemote); + } + + async execute(editor?: TextEditor, uri?: Uri) { + if (editor == null) return; + + uri = getCommandUri(uri, editor); + if (uri == null) return; + + const gitUri = await GitUri.fromUri(uri); + + const blameline = editor.selection.active.line; + if (blameline < 0) return; + + try { + const blame = await Container.git.getBlameForLine(gitUri, blameline); + if (blame == null) return; + + await executeCommand(Commands.OpenPullRequestOnRemote, { + clipboard: false, + ref: blame.commit.sha, + repoPath: blame.commit.repoPath, + }); + } catch (ex) { + Logger.error(ex, 'OpenAssociatedPullRequestOnRemoteCommand', `getBlameForLine(${blameline})`); + } + } +} diff --git a/src/commands/openPullRequestOnRemote.ts b/src/commands/openPullRequestOnRemote.ts index a9a22da..c09352c 100644 --- a/src/commands/openPullRequestOnRemote.ts +++ b/src/commands/openPullRequestOnRemote.ts @@ -1,13 +1,6 @@ 'use strict'; import { env, Uri, window } from 'vscode'; -import { - Command, - command, - CommandContext, - Commands, - isCommandContextViewNodeHasCommit, - isCommandContextViewNodeHasFileCommit, -} from './common'; +import { Command, command, CommandContext, Commands } from './common'; import { Container } from '../container'; import { PullRequestNode } from '../views/nodes'; import { Logger } from '../logger'; @@ -23,19 +16,11 @@ export interface OpenPullRequestOnRemoteCommandArgs { @command() export class OpenPullRequestOnRemoteCommand extends Command { constructor() { - super([ - Commands.OpenPullRequestOnRemote, - Commands.CopyRemotePullRequestUrl, - Commands.OpenAssociatedPullRequestOnRemote, - ]); + super([Commands.OpenPullRequestOnRemote, Commands.CopyRemotePullRequestUrl]); } protected preExecute(context: CommandContext, args?: OpenPullRequestOnRemoteCommandArgs) { - if (context.command === Commands.OpenAssociatedPullRequestOnRemote) { - 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) { + if (context.type === 'viewItem' && context.node instanceof PullRequestNode) { args = { ...args, pr: { url: context.node.pullRequest.url },