Skip to content

Commit

Permalink
Merge pull request #1881 from hunterkepley/ocm-6302-2
Browse files Browse the repository at this point in the history
OCM-6302 | ci: Prow job update to check PR author in commit check
  • Loading branch information
openshift-merge-bot[bot] committed Mar 28, 2024
2 parents 61aed4f + 374c1d5 commit 0c0f1c3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions hack/commit-msg-verify.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/usr/bin/env bash

# This regex matches the pull number with an author from the job spec. Prow does not have a PULL_AUTHOR job var
PULL_AUTHOR=$(echo $JOB_SPEC | grep -Po "$PULL_NUMBER,\"author\":\"\K[^\"]*")

# PULL_BASE_SHA and PULL_PULL_SHA are set in prow job
PULL_BASE_SHA="${PULL_BASE_SHA:-$(git merge-base master HEAD)}"
PULL_PULL_SHA="${PULL_PULL_SHA:-HEAD}"

pattern="^[A-Z]+-[0-9]+ \| (feat|fix|docs|style|refactor|test|chore|build|ci|perf): .*$"

# Lists of GitHub users for whom the commit validation should be skipped:
# # This contains the bots used in the ROSA project
# * openshift-merge-bot[bot] - bot responsible for merigng MRs
# * openshift-ci[bot] - bot responsible for running tests / approvals
declare -a skip_pr_authors=(
"openshift-ci[bot]"
"openshift-merge-bot[bot]"
)
echo "The PR Author is \"${PULL_AUTHOR}\""
for skip_pr_author in "${skip_pr_authors[@]}"
do
if [ "${PULL_AUTHOR}" = "${skip_pr_author}" ]; then
echo "The commits created by this PR author (probably bot) should be skipped!!!"
exit 0
fi
done
commits=$(git rev-list --no-merges $PULL_BASE_SHA..$PULL_PULL_SHA)

for sha in $commits; do
Expand All @@ -18,4 +35,4 @@ for sha in $commits; do
fi
done

echo "All commit message are valid"
echo "All commit messages are valid"

0 comments on commit 0c0f1c3

Please sign in to comment.