Skip to content

Commit

Permalink
Fixes #1222 - open associated pr wasnt implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 1, 2020
1 parent 659a216 commit a66e5d8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
39 changes: 39 additions & 0 deletions src/commands/openAssociatedPullRequestOnRemote.ts
Original file line number Diff line number Diff line change
@@ -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<OpenPullRequestOnRemoteCommandArgs>(Commands.OpenPullRequestOnRemote, {
clipboard: false,
ref: blame.commit.sha,
repoPath: blame.commit.repoPath,
});
} catch (ex) {
Logger.error(ex, 'OpenAssociatedPullRequestOnRemoteCommand', `getBlameForLine(${blameline})`);
}
}
}
21 changes: 3 additions & 18 deletions src/commands/openPullRequestOnRemote.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 },
Expand Down

0 comments on commit a66e5d8

Please sign in to comment.