Browse Source

Adds upstream & isRemote to create pr runner

Moves a few api props to be at the root level
main
Eric Amodio 3 years ago
parent
commit
3d55395f2e
3 changed files with 85 additions and 29 deletions
  1. +39
    -7
      src/api/gitlens.d.ts
  2. +14
    -5
      src/git/formatters/commitFormatter.ts
  3. +32
    -17
      src/views/viewCommands.ts

+ 39
- 7
src/api/gitlens.d.ts View File

@ -11,24 +11,56 @@ export interface RemoteProvider {
export interface CreatePullRequestActionContext {
readonly type: 'createPullRequest';
readonly runnerId?: number;
readonly repoPath: string;
readonly branch: {
readonly name: string;
readonly remote?: {
readonly name: string;
readonly provider?: RemoteProvider;
readonly url?: string;
};
readonly upstream: string | undefined;
readonly isRemote: boolean;
/**
* @deprecated Use the root [repoPath](#CreatePullRequestActionContext.repoPath) property instead
*/
readonly repoPath: string;
/**
* @deprecated Use the root [remote](#CreatePullRequestActionContext.remote) property instead
*/
readonly remote:
| {
readonly name: string;
readonly provider?: RemoteProvider;
readonly url?: string;
}
| undefined;
};
readonly remote:
| {
readonly name: string;
readonly provider?: RemoteProvider;
readonly url?: string;
}
| undefined;
}
export interface OpenPullRequestActionContext {
readonly type: 'openPullRequest';
readonly runnerId?: number;
readonly repoPath: string;
readonly provider: RemoteProvider | undefined;
readonly pullRequest: {
readonly id: string;
readonly provider?: RemoteProvider;
readonly repoPath: string;
readonly url: string;
/**
* @deprecated Use the root [repoPath](#OpenPullRequestActionContext.repoPath) property instead
*/
readonly repoPath: string;
/**
* @deprecated Use the root [provider](#OpenPullRequestActionContext.provider) property instead
*/
readonly provider: RemoteProvider | undefined;
};
}

+ 14
- 5
src/git/formatters/commitFormatter.ts View File

@ -1,4 +1,5 @@
'use strict';
import { OpenPullRequestActionContext } from '../../api/gitlens';
import { getPresenceDataUri } from '../../avatars';
import {
Commands,
@ -304,12 +305,17 @@ export class CommitFormatter extends Formatter {
const { pullRequestOrRemote: pr } = this._options;
if (pr != null) {
if (PullRequest.is(pr)) {
commands += `[$(git-pull-request) PR #${pr.id}](${getMarkdownActionCommand('openPullRequest', {
commands += `[$(git-pull-request) PR #${
pr.id
}](${getMarkdownActionCommand<OpenPullRequestActionContext>('openPullRequest', {
repoPath: this._item.repoPath,
provider: { id: pr.provider.id, name: pr.provider.name, domain: pr.provider.domain },
pullRequest: {
id: pr.id,
url: pr.url,
provider: { id: pr.provider.id, name: pr.provider.name, domain: pr.provider.domain },
repoPath: this._item.repoPath,
url: pr.url,
},
})} "Open Pull Request \\#${pr.id}${
Container.actionRunners.count('openPullRequest') == 1 ? ` on ${pr.provider.name}` : ''
@ -470,12 +476,15 @@ export class CommitFormatter extends Formatter {
let text;
if (PullRequest.is(pr)) {
if (this._options.markdown) {
text = `[PR #${pr.id}](${getMarkdownActionCommand('openPullRequest', {
text = `[PR #${pr.id}](${getMarkdownActionCommand<OpenPullRequestActionContext>('openPullRequest', {
repoPath: this._item.repoPath,
provider: { id: pr.provider.id, name: pr.provider.name, domain: pr.provider.domain },
pullRequest: {
id: pr.id,
provider: { id: pr.provider.id, name: pr.provider.name, domain: pr.provider.domain },
repoPath: this._item.repoPath,
url: pr.url,
repoPath: this._item.repoPath,
provider: { id: pr.provider.id, name: pr.provider.name, domain: pr.provider.domain },
},
})} "Open Pull Request \\#${pr.id}${
Container.actionRunners.count('openPullRequest') == 1 ? ` on ${pr.provider.name}` : ''

+ 32
- 17
src/views/viewCommands.ts View File

@ -282,25 +282,31 @@ export class ViewCommands {
}
const remote = await node.branch.getRemote();
const remoteInfo =
remote != null
? {
name: remote.name,
provider:
remote.provider != null
? {
id: remote.provider.id,
name: remote.provider.name,
domain: remote.provider.domain,
}
: undefined,
url: remote.url,
}
: undefined;
return executeActionCommand<CreatePullRequestActionContext>('createPullRequest', {
repoPath: node.repoPath,
remote: remoteInfo,
branch: {
name: node.branch.name,
remote:
remote != null
? {
name: remote.name,
provider:
remote.provider != null
? {
id: remote.provider.id,
name: remote.provider.name,
domain: remote.provider.domain,
}
: undefined,
url: remote.url,
}
: undefined,
name: node.branch.getNameWithoutRemote(),
upstream: node.branch.getTrackingWithoutRemote(),
isRemote: node.branch.remote,
remote: remoteInfo,
repoPath: node.repoPath,
},
});
@ -413,16 +419,25 @@ export class ViewCommands {
private openPullRequest(node: PullRequestNode) {
if (!(node instanceof PullRequestNode)) return Promise.resolve();
const provider = {
id: node.pullRequest.provider.id,
name: node.pullRequest.provider.name,
domain: node.pullRequest.provider.domain,
};
return executeActionCommand<OpenPullRequestActionContext>('openPullRequest', {
repoPath: node.uri.repoPath!,
provider: provider,
pullRequest: {
id: node.pullRequest.id,
url: node.pullRequest.url,
provider: {
id: node.pullRequest.provider.id,
name: node.pullRequest.provider.name,
domain: node.pullRequest.provider.domain,
},
repoPath: node.uri.repoPath!,
url: node.pullRequest.url,
},
});
}

Loading…
Cancel
Save