Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 

38 rader
1.2 KiB

import { TextEditor, Uri } from 'vscode';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands, executeCommand, getCommandUri } from './common';
import { OpenPullRequestOnRemoteCommandArgs } from './openPullRequestOnRemote';
@command()
export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorCommand {
constructor(private readonly container: Container) {
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 this.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})`);
}
}
}