Skip to content

Commit 4816501

Browse files
authored
Merge pull request #3 from mixmaxhq/eli/add-if-ci-flag
feat: add --if-ci flag
2 parents a14ee5a + f8ead24 commit 4816501

File tree

3 files changed

+33
-55
lines changed

3 files changed

+33
-55
lines changed

package-lock.json

+18-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"src"
88
],
99
"scripts": {
10-
"ci": "npm run lint && npm run commitlint",
11-
"commitlint": "if [ \"$CI\" != '' ]; then node .; else commitlint --from HEAD; fi",
12-
"lint": "eslint .",
10+
"ci": "npm run lint",
11+
"lint": "eslint . && node . --if-ci",
1312
"prepublishOnly": "if [ \"$CI\" = '' ]; then node -p 'JSON.parse(process.env.npm_package_config_manualPublishMessage)'; exit 1; fi",
1413
"test": "echo \"Error: no test specified\" && exit 1",
1514
"semantic-release": "semantic-release"
@@ -25,7 +24,8 @@
2524
},
2625
"homepage": "https://github.com/mixmaxhq/commitlint-jenkins#readme",
2726
"dependencies": {
28-
"execa": "^3.2.0"
27+
"execa": "^3.2.0",
28+
"yargs": "^14.2.0"
2929
},
3030
"devDependencies": {
3131
"@commitlint/cli": "^8.2.0",

src/index.js

+11-1
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)