Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 строки
1.2 KiB

3 лет назад
  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. }