Skip to content

Commit c4640db

Browse files
author
Eli Skeggs
committed
feat: add --if-ci flag
The --if-ci flag will skip the commitlint step if not on CI.
1 parent a14ee5a commit c4640db

File tree

3 files changed

+31
-52
lines changed

3 files changed

+31
-52
lines changed

package-lock.json

Lines changed: 18 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"homepage": "https://github.com/mixmaxhq/commitlint-jenkins#readme",
2727
"dependencies": {
28-
"execa": "^3.2.0"
28+
"execa": "^3.2.0",
29+
"yargs": "^14.2.0"
2930
},
3031
"devDependencies": {
3132
"@commitlint/cli": "^8.2.0",

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env node
22
const execa = require('execa');
3+
const argv = require('yargs').argv;
34
const commitlint = require('@commitlint/cli');
45

6+
const IF_CI = !!argv.ifCi;
7+
58
// Allow to override used bins for testing purposes
69
const GIT = process.env.JENKINS_COMMITLINT_GIT_BIN || 'git';
710
const COMMITLINT = process.env.JENKINS_COMMITLINT_BIN;
@@ -23,7 +26,9 @@ main().catch((err) => {
2326
});
2427

2528
async function main() {
26-
validate();
29+
if (!validate()) {
30+
return;
31+
}
2732

2833
// Lint all commits on the branch if available
2934
if (IS_PR) {
@@ -60,6 +65,9 @@ async function rawCommit(hash) {
6065

6166
function validate() {
6267
if (process.env.CI !== 'true') {
68+
if (IF_CI) {
69+
return false;
70+
}
6371
throw new Error(`@mixmaxhq/commitlint-jenkins is intended to be used on Jenkins CI`);
6472
}
6573

@@ -69,4 +77,6 @@ function validate() {
6977
const stanza = missing.length > 1 ? 'they were not' : 'it was not';
7078
throw new Error(`Expected ${missing.join(', ')} to be defined globally, ${stanza}.`);
7179
}
80+
81+
return true;
7282
}

0 commit comments

Comments
 (0)