conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.93k stars 912 forks source link

docs: add gitlab example to check all commits in merge request #4154

Open bliuchak opened 2 months ago

bliuchak commented 2 months ago

Description

Add an example for Gitlab CI/CD that shows how to check all commits in merge request.

Also solves this question on Stackoverflow.

Motivation and Context

Current CI/CD guide shows examples how to validate single commit only in Gitlab CI/CD.

Usage examples

// commitlint.config.js
module.exports = {};
echo "your commit message here" | commitlint # fails/passes

How Has This Been Tested?

I've tested this with -V on branch with multiple commits (including one non-valid commit).

Positive (multiple valid commits):

// Gitlab CI/CD runner
// ...
$ npx commitlint -V --from $CI_MERGE_REQUEST_DIFF_BASE_SHA --to $CI_COMMIT_SHA
⧗   input: chore: good
✔   found 0 problems, 0 warnings
⧗   input: chore: bad
✔   found 0 problems, 0 warnings
⧗   input: feat(cicd): run commitlint in pipeline
✔   found 0 problems, 0 warnings
// ...

Negative (multiple commits including one invalid):

// Gitlab CI/CD runner
// ...
$ npx commitlint -V --from $CI_MERGE_REQUEST_DIFF_BASE_SHA --to $CI_COMMIT_SHA
⧗   input: chore: good
✔   found 0 problems, 0 warnings
⧗   input: bad
✖   subject may not be empty [subject-empty]
✖   type may not be empty [type-empty]
✖   found 2 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
⧗   input: feat(cicd): run commitlint in pipeline
✔   found 0 problems, 0 warnings
// ...

Types of changes

Checklist:

codesandbox-ci[bot] commented 2 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

escapedcat commented 2 months ago

@knocte wdyt?

knocte commented 2 months ago

I haven't used GitLab in ages. Hey @bliuchak, shouldn't this test first that the variable CI_MERGE_REQUEST_DIFF_BASE_SHA contains a value? (Because, if it doesn't, then the CI job is being spawned by a push, not a mergeRequest, and then in that case we wouldn't want to fail?)