merging commits to main branch

This commit is contained in:
Laura Liberda 2021-02-26 14:01:58 +01:00
parent c71309c9e8
commit cf3fdb17dc
2 changed files with 23 additions and 1 deletions

View file

@ -17,6 +17,9 @@ export default class Replicate extends Command {
description: 'do not commit the applied changes (for MRs)', description: 'do not commit the applied changes (for MRs)',
allowNo: false, allowNo: false,
}), }),
mergeToMainBranch: flags.boolean({
description: 'merge the replicated commit into main branch as well (for MRs and commits)',
}),
remote: flags.string({ remote: flags.string({
description: 'git remote where the commits are pushed (for MRs)', description: 'git remote where the commits are pushed (for MRs)',
default: 'origin', default: 'origin',
@ -62,6 +65,7 @@ export default class Replicate extends Command {
const { const {
destBranch, destBranch,
doNotCommit, doNotCommit,
mergeToMainBranch,
remote, remote,
targetBranch, targetBranch,
patchHook, patchHook,
@ -112,6 +116,7 @@ export default class Replicate extends Command {
const repl = await kitku.replicateMergeRequest(sourceMR, destRepo, { const repl = await kitku.replicateMergeRequest(sourceMR, destRepo, {
destBranch, destBranch,
doNotCommit, doNotCommit,
mergeToMainBranch,
patchHook, patchHook,
remote, remote,
targetBranch, targetBranch,
@ -134,6 +139,7 @@ export default class Replicate extends Command {
destBranch || destBranch ||
`${sourceRepo.repo.owner.username}/${sourceRepo.repo.name}/commit-${sourceCommit.id}`, `${sourceRepo.repo.owner.username}/${sourceRepo.repo.name}/commit-${sourceCommit.id}`,
doNotCommit, doNotCommit,
mergeToMainBranch,
patchHook, patchHook,
includePaths, includePaths,
excludePaths, excludePaths,

View file

@ -62,6 +62,7 @@ export default class Copykitku {
destBranch?: string; destBranch?: string;
doNotCommit?: boolean | null; doNotCommit?: boolean | null;
doNotPush?: boolean | null; doNotPush?: boolean | null;
mergeToMainBranch?: boolean | null;
patchHook?: string | null; patchHook?: string | null;
remote: string; remote: string;
targetBranch: string; targetBranch: string;
@ -74,6 +75,7 @@ export default class Copykitku {
const { const {
doNotCommit, doNotCommit,
doNotPush, doNotPush,
mergeToMainBranch,
remote, remote,
targetBranch, targetBranch,
patchHook, patchHook,
@ -84,6 +86,7 @@ export default class Copykitku {
await this.replicateCommits(sourceMR.commits, destination, { await this.replicateCommits(sourceMR.commits, destination, {
destBranch, destBranch,
doNotCommit, doNotCommit,
mergeToMainBranch,
patchHook, patchHook,
includePaths, includePaths,
excludePaths, excludePaths,
@ -111,12 +114,20 @@ export default class Copykitku {
opts: { opts: {
destBranch: string; destBranch: string;
doNotCommit?: boolean | null; doNotCommit?: boolean | null;
mergeToMainBranch?: boolean | null;
patchHook?: string | null; patchHook?: string | null;
includePaths?: string[]; includePaths?: string[];
excludePaths?: string[]; excludePaths?: string[];
}, },
) { ) {
const { destBranch, doNotCommit, patchHook, includePaths, excludePaths } = opts; const {
destBranch,
doNotCommit,
mergeToMainBranch,
patchHook,
includePaths,
excludePaths,
} = opts;
const commits = Array.isArray(sourceCommit) ? sourceCommit : [sourceCommit]; const commits = Array.isArray(sourceCommit) ? sourceCommit : [sourceCommit];
const patchHookCall = patchHook const patchHookCall = patchHook
@ -179,6 +190,11 @@ export default class Copykitku {
}); });
} }
} }
if (doNotCommit !== true && mergeToMainBranch === true) {
// TODO: check the main branch name (T32)
await git.checkout('master');
await git.merge([destBranch]);
}
return true; return true;
} }