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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ from `@commitlint/travis-cli`.
Only supports `git` projects, assumes a single repository (i.e. does not explicitly support cross-
repo pull requests), and doesn't support renaming the remote to something other than `origin`. We
welcome [pull requests](https://github.com/mixmaxhq/commitlint-jenkins/pulls)!

## Flags

### `--if-ci`

If `commitlint-jenkins` is run outside of a CI context, it will fail. This flag simply ignores the
failure, for use-cases where `commitlint-jenkins` should be run from a script shared with a non-CI
workflow.

### `--pr-only`

If `commitlint-jenkins` is run in CI in a build that isn't a pull request build, silently exit.
This flag is particularly handy for use with
[`@mixmaxhq/semantic-commitlint`](https://github.com/mixmaxhq/semantic-commitlint).
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"scripts": {
"ci": "npm run lint",
"lint": "eslint . && node . --if-ci",
"ci:commitlint": "node . --pr-only",
"lint": "eslint .",
"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 Down
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const argv = require('yargs').argv;
const commitlint = require('@commitlint/cli');

const IF_CI = !!argv.ifCi;
const PR_ONLY = !!argv.prOnly;

// Allow to override used bins for testing purposes
const GIT = process.env.JENKINS_COMMITLINT_GIT_BIN || 'git';
// Allow override of used bins for testing purposes
const COMMITLINT = process.env.JENKINS_COMMITLINT_BIN;

const REQUIRED = ['GIT_COMMIT'];
Expand Down Expand Up @@ -40,14 +40,16 @@ async function main() {
// We could lint since the last successful commit, but that would require a bunch of extra logic
// to detect changes to commitlint.config.js or related modules.
await lint(['--from', start, '--to', COMMIT]);
} else {
} else if (!PR_ONLY) {
// The --pr-only flag can be useful to use semantic-commitlint on the release branch instead of
// just linting one commit.
const input = await rawCommit(COMMIT);
await lint([], { input });
}
}

async function getBase({ branch, tip = 'HEAD' }) {
const result = await execa(GIT, ['merge-base', branch, tip]);
const result = await execa('git', ['merge-base', branch, tip]);
return result.stdout;
}

Expand All @@ -59,7 +61,7 @@ async function lint(args, options) {
}

async function rawCommit(hash) {
const result = await execa(GIT, ['show', '--pretty=format:%B', hash]);
const result = await execa('git', ['show', '-s', '--pretty=format:%B', hash]);
return result.stdout;
}

Expand Down