Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix standalone pull requests creating #36

Merged
merged 1 commit into from
May 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@ import { processCherryPickRequest } from './processCherryPickRequest';
import { pushAndCreatePullRequests } from './processPullRequests';
import Git from './git/client';

async function preparePayload (
treeDataProvider: TreeDataProvider,
options: { skipBaseUpstream: boolean } = { skipBaseUpstream: false }
): Promise<TreePayload> {
const branch = await Git.getBranchName();
const [localBranch, baseUpstreamBranch] = Git.parseBranch(branch);
Git.setBranches(localBranch, baseUpstreamBranch);

const payload = await getTreePayload(treeDataProvider) as TreePayload;
if (options.skipBaseUpstream) {
payload.upstreams = payload.upstreams.filter((upstream) => upstream !== baseUpstreamBranch);
}
Logger.logInfo(`branch: ${branch}, localBranch: ${localBranch}, baseUpstreamBranch: ${baseUpstreamBranch}, upstreams: ${payload.upstreams}`);

return payload;
}
export class Action {
static async onPullRequest (treeDataProvider: TreeDataProvider) {
const payload = await getTreePayload(treeDataProvider);
const payload = await preparePayload(treeDataProvider);

if (!payload) {
Logger.logError('no payload');
Expand Down Expand Up @@ -70,13 +86,7 @@ export class Action {
}

static async onCherryPick (treeDataProvider: TreeDataProvider) {
const branch = await Git.getBranchName();
const [localBranch, baseUpstreamBranch] = Git.parseBranch(branch);
Git.setBranches(localBranch, baseUpstreamBranch);

const payload = await getTreePayload(treeDataProvider) as TreePayload;
payload.upstreams = payload.upstreams.filter((upstream) => upstream !== baseUpstreamBranch);
Logger.logInfo(`branch: ${branch}, localBranch: ${localBranch}, baseUpstreamBranch: ${baseUpstreamBranch}, upstreams: ${payload.upstreams}`);
const payload = await preparePayload(treeDataProvider, { skipBaseUpstream: true });
await processCherryPickRequest(payload as TreePayload);
}
}