commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

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

Open bliuchak opened this issue 1 year ago β€’ 3 comments

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

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [x] Chore (documentation update)

Checklist:

  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

bliuchak avatar Sep 16 '24 09:09 bliuchak

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.

codesandbox-ci[bot] avatar Sep 16 '24 09:09 codesandbox-ci[bot]

@knocte wdyt?

escapedcat avatar Sep 18 '24 07:09 escapedcat

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?)

knocte avatar Sep 18 '24 07:09 knocte

Please re-open when this continues

escapedcat avatar Jan 16 '25 09:01 escapedcat