Skip to content

ci: Apply commitlint for all new commits

Rasmus Dahlberg requested to merge rgdd/fix-commitlint into main

Consider all commits between the target branch and current HEAD. Assume the target branch is main if the target branch is unknown, i.e., no MR.

Here's a bash script that you may find useful for reviewing, e.g., in case you want to try the logic on a local system.

#!/bin/bash

# Populated by GitLab CI, see:
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
#
# Added example value here to test that the below works locally
CI_MERGE_REQUEST_TARGET_BRANCH_NAME=main

base_commit_id="$(git merge-base HEAD "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME")"
commit_ids="$(git rev-list --no-merges HEAD ^"$base_commit_id")"
for commit_id in $commit_ids; do
        #
        # msg is the full git-commit message for the given commit ID.  In other
        # words, it should be a reasonable replacement of $CI_COMMIT_MESSAGE.
        #
        #  %B: raw body (unwrapped subject and body)
        # -n1: just the one commit please
        #
        msg="$(git log --format=%B -n1 "$commit_id")"
    echo "$msg" # this is what we would pipe to commitlint
done

Closes #23 (closed).

Edited by Rasmus Dahlberg

Merge request reports

Loading