Skip to content

Commit

Permalink
Exit without error message when requireCommits is true but requireCom…
Browse files Browse the repository at this point in the history
…mitsFail is false and no commits are available (#1101)

* feat: exit without error message when requireCommits is true but requireCommitsFail is false and no commits are available

Fixes #1095

* refactor: pass state using error object cause

Fixes #1095
  • Loading branch information
juancarlosjr97 committed Apr 26, 2024
1 parent 679bd0e commit cce35f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/index.js
Expand Up @@ -138,7 +138,12 @@ const runTasks = async (opts, di) => {
};
} catch (err) {
const { log } = container;
log ? log.error(err.message || err) : console.error(err); // eslint-disable-line no-console

const errorMessage = err.message || err;
const logger = log || console;

err.cause === 'INFO' ? logger.info(errorMessage) : logger.error(errorMessage);

throw err;
}
};
Expand Down
1 change: 1 addition & 0 deletions lib/util.js
Expand Up @@ -92,6 +92,7 @@ const parseVersion = raw => {
const e = (message, docs, fail = true) => {
const error = new Error(docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message);
error.code = fail ? 1 : 0;
error.cause = fail ? 'ERROR' : 'INFO';
return error;
};

Expand Down
2 changes: 1 addition & 1 deletion test/git.init.js
Expand Up @@ -76,7 +76,7 @@ test.serial('should not throw if there are commits', async t => {
const gitClient = factory(Git, { options });
sh.exec('git tag 1.0.0');
gitAdd('line', 'file', 'Add file');
await t.notThrowsAsync(gitClient.init());
await t.notThrowsAsync(gitClient.init(), 'There are no commits since the latest tag');
});

test.serial('should fail (exit code 1) if there are no commits', async t => {
Expand Down

0 comments on commit cce35f3

Please sign in to comment.