Skip to content

Commit

Permalink
Adds upstream & isRemote to create pr runner
Browse files Browse the repository at this point in the history
Moves a few api props to be at the root level
  • Loading branch information
eamodio committed Jan 20, 2021
1 parent a8b9127 commit 3d55395
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 29 deletions.
46 changes: 39 additions & 7 deletions src/api/gitlens.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
19 changes: 14 additions & 5 deletions src/git/formatters/commitFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import { OpenPullRequestActionContext } from '../../api/gitlens';
import { getPresenceDataUri } from '../../avatars';
import {
Commands,
Expand Down Expand Up @@ -304,12 +305,17 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
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}` : ''
Expand Down Expand Up @@ -470,12 +476,15 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
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}` : ''
Expand Down
49 changes: 32 additions & 17 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Expand Down Expand Up @@ -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,
},
});
}
Expand Down

0 comments on commit 3d55395

Please sign in to comment.