Skip to content

Commit

Permalink
feat: ✅ apply no-verify to push too
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed Dec 5, 2020
1 parent 87ad2da commit b0f3c76
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
25 changes: 24 additions & 1 deletion packages/semver/src/builders/version/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,37 @@ describe('@jscutlery/semver:version', () => {
expect.arrayContaining([
'push',
'--follow-tags',
'--no-verify',
'--atomic',
'origin',
'main',
])
);
});

it(`should push to Git and add '--no-verify' option when asked for`, async () => {
await runBuilder(
{
...options,
push: true,
remote: 'origin',
baseBranch: 'main',
noVerify: true,
},
context
).toPromise();

expect(childProcess.exec).toHaveBeenCalledWith(
'git',
expect.arrayContaining([
'push',
'--follow-tags',
'--no-verify',
'--atomic',
'origin',
'main',
])
);
});
it('should fail if Git config is missing', async () => {
const output = await runBuilder(
{ ...options, push: true, remote: undefined, baseBranch: null },
Expand Down
39 changes: 24 additions & 15 deletions packages/semver/src/builders/version/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@ async function getProjectRoot(context: BuilderContext): Promise<string> {
return metadata.root as string;
}

function pushToGitRemote(
remote: string,
branch: string,
context: BuilderContext
): Rule {
function pushToGitRemote({
remote,
branch,
context,
noVerify,
}: {
remote: string;
branch: string;
context: BuilderContext;
noVerify: boolean;
}): Rule {
if (remote == null || branch == null) {
throw new Error(
'Missing configuration for Git push, please provide --remote and --branch options'
);
}

const gitPushOptions = [
'--follow-tags',
...(noVerify ? ['--no-verify'] : []),
];

return exec('git', [
'push',
'--follow-tags',
'--no-verify',
...gitPushOptions,
'--atomic',
remote,
branch,
Expand All @@ -51,13 +61,7 @@ function pushToGitRemote(
'git push --atomic failed, attempting non-atomic push'
);

return exec('git', [
'push',
'--follow-tags',
'--no-verify',
remote,
branch,
]);
return exec('git', ['push', ...gitPushOptions, remote, branch]);
}

// ensure unexpected errors still break chain
Expand Down Expand Up @@ -85,7 +89,12 @@ export function runBuilder(
options.push && options.dryRun === false
? switchMapTo(
defer(() =>
pushToGitRemote(options.remote, options.baseBranch, context)
pushToGitRemote({
remote: options.remote,
branch: options.baseBranch,
context,
noVerify: options.noVerify,
})
)
)
: mapTo(noop()),
Expand Down

0 comments on commit b0f3c76

Please sign in to comment.