Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 18 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"src"
],
"scripts": {
"ci": "npm run lint && npm run commitlint",
"commitlint": "if [ \"$CI\" != '' ]; then node .; else commitlint --from HEAD; fi",
"lint": "eslint .",
"ci": "npm run lint",
"lint": "eslint . && node . --if-ci",
"prepublishOnly": "if [ \"$CI\" = '' ]; then node -p 'JSON.parse(process.env.npm_package_config_manualPublishMessage)'; exit 1; fi",
"test": "echo \"Error: no test specified\" && exit 1",
"semantic-release": "semantic-release"
Expand All @@ -25,7 +24,8 @@
},
"homepage": "https://github.com/mixmaxhq/commitlint-jenkins#readme",
"dependencies": {
"execa": "^3.2.0"
"execa": "^3.2.0",
"yargs": "^14.2.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env node
const execa = require('execa');
const argv = require('yargs').argv;
const commitlint = require('@commitlint/cli');

const IF_CI = !!argv.ifCi;

// Allow to override used bins for testing purposes
const GIT = process.env.JENKINS_COMMITLINT_GIT_BIN || 'git';
const COMMITLINT = process.env.JENKINS_COMMITLINT_BIN;
Expand All @@ -23,7 +26,9 @@ main().catch((err) => {
});

async function main() {
validate();
if (!validate()) {
return;
}

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

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

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

return true;
}