Commit bc3eeb9a authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

feat: check merge request title

parent c52e1600
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ include:
  - local: yaml/yamllint.yml
  - local: project-automation/pipeline-scheduler.yml
  - local: project-automation/pages-hugo.yml
  - local: project-automation/check-merge-request.yml

gitlab:recommended:
  variables:
+28 −0
Original line number Diff line number Diff line
---
check:merge-request:
  stage: .pre
  image: node:alpine
  variables:
    GIT_STRATEGY: none
  script:
    - apk add --no-cache curl jq
    - npm install -g git-conventional-commits

    - git-conventional-commits init

    - |
      curl -sSLf --header "PRIVATE-TOKEN: ${GL_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests?iids[]=${CI_MERGE_REQUEST_IID}" > /tmp/mr.json
    - |
      if [ "$(jq -r '.[].squash' test.json)" = "true" ]; then
        echo "[*] Squashing is enabled. Will check the MR title."
        echo "${CI_MERGE_REQUEST_TITLE}" > /tmp/mr_title
        if ! git-conventional-commits commit-msg-hook /tmp/mr_title; then
          exit 1  # The previous command will output a descriptive error
        else
          echo "[+] Merge request title looks good."
        fi
      else
        echo "[!] You're not squashing this MR. Ensure all commit messages have a proper format!"  # TODO automatically check this
      fi
  rules:
    - if: '$CI_MERGE_REQUEST_IID && $GL_TOKEN'