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

  1. import { TextEditor, Uri } from 'vscode';
  2. import type { Container } from '../container';
  3. import { GitUri } from '../git/gitUri';
  4. import { Logger } from '../logger';
  5. import { ActiveEditorCommand, command, Commands, executeCommand, getCommandUri } from './common';
  6. import { OpenPullRequestOnRemoteCommandArgs } from './openPullRequestOnRemote';
  7. @command()
  8. export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorCommand {
  9. constructor(private readonly container: Container) {
  10. super(Commands.OpenAssociatedPullRequestOnRemote);
  11. }
  12. async execute(editor?: TextEditor, uri?: Uri) {
  13. if (editor == null) return;
  14. uri = getCommandUri(uri, editor);
  15. if (uri == null) return;
  16. const gitUri = await GitUri.fromUri(uri);
  17. const blameline = editor.selection.active.line;
  18. if (blameline < 0) return;
  19. try {
  20. const blame = await this.container.git.getBlameForLine(gitUri, blameline);
  21. if (blame == null) return;
  22. await executeCommand<OpenPullRequestOnRemoteCommandArgs>(Commands.OpenPullRequestOnRemote, {
  23. clipboard: false,
  24. ref: blame.commit.sha,
  25. repoPath: blame.commit.repoPath,
  26. });
  27. } catch (ex) {
  28. Logger.error(ex, 'OpenAssociatedPullRequestOnRemoteCommand', `getBlameForLine(${blameline})`);
  29. }
  30. }
  31. }