ci/check-commit-log: Generate JUnit report
This will make it less horrible when commit message doesn't pass the compliance checks. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1549>
This commit is contained in:
parent
369e2ac9b5
commit
0c9f7c7735
@ -12,6 +12,12 @@ check-commit-log:
|
|||||||
GIT_DEPTH: "100"
|
GIT_DEPTH: "100"
|
||||||
script:
|
script:
|
||||||
- ./.gitlab-ci/check-commit-log.sh
|
- ./.gitlab-ci/check-commit-log.sh
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- commit-message-junit-report.xml
|
||||||
|
reports:
|
||||||
|
junit: commit-message-junit-report.xml
|
||||||
only:
|
only:
|
||||||
- merge_requests
|
- merge_requests
|
||||||
|
|
||||||
|
@ -23,33 +23,80 @@ function commit_message_has_mr_url() {
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
function commit_message_subject_is_compliant() {
|
JUNIT_REPORT_TESTS_FILE=$(mktemp)
|
||||||
|
|
||||||
|
function append_failed_test_case() {
|
||||||
|
test_name="$1"
|
||||||
|
commit="$2"
|
||||||
|
test_message="$3"
|
||||||
|
commit_short=${commit:0:8}
|
||||||
|
|
||||||
|
echo "<testcase name=\"$test_name: $commit_short\"><failure message=\"$commit_short: $test_message\"/></testcase>" >> $JUNIT_REPORT_TESTS_FILE
|
||||||
|
echo &>2 "Commit check failed: $commit_short: $test_message"
|
||||||
|
}
|
||||||
|
|
||||||
|
function append_passed_test_case() {
|
||||||
|
test_name="$1"
|
||||||
|
commit="$2"
|
||||||
|
commit_short=${commit:0:8}
|
||||||
|
|
||||||
|
echo "<testcase name=\"$test_name: $commit_short\"></testcase>" >> $JUNIT_REPORT_TESTS_FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate_junit_report() {
|
||||||
|
junit_report_file="$1"
|
||||||
|
num_tests=$(cat "$JUNIT_REPORT_TESTS_FILE" | wc -l)
|
||||||
|
num_failures=$(grep '<failure />' "$JUNIT_REPORT_TESTS_FILE" | wc -l )
|
||||||
|
|
||||||
|
echo Generating JUnit report \"$(pwd)/$junit_report_file\" with $num_tests tests and $num_failures failures.
|
||||||
|
|
||||||
|
cat > $junit_report_file << __EOF__
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<testsuites tests="$num_tests" errors="0" failures="$num_failures">
|
||||||
|
<testsuite name="commit-review" tests="$num_tests" errors="0" failures="$num_failures" skipped="0">
|
||||||
|
$(< $JUNIT_REPORT_TESTS_FILE)
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
__EOF__
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_commit_message_subject() {
|
||||||
commit=$1
|
commit=$1
|
||||||
commit_message_subject=$(git show -s --format='format:%s' $commit)
|
commit_message_subject=$(git show -s --format='format:%s' $commit)
|
||||||
|
|
||||||
if echo "$commit_message_subject" | grep -qe "\(^meta-\|^Meta\)"; then
|
if echo "$commit_message_subject" | grep -qe "\(^meta-\|^Meta\)"; then
|
||||||
echo " - message subject should not be prefixed with 'meta-' or 'Meta'"
|
append_failed_test_case meta-prefix $commit \
|
||||||
return 1
|
"Commit message subject should not be prefixed with 'meta-' or 'Meta'"
|
||||||
|
else
|
||||||
|
append_passed_test_case meta-prefix $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$commit_message_subject" | grep -qe "\(^clutter-\|^Clutter\)"; then
|
if echo "$commit_message_subject" | grep -qe "\(^clutter-\|^Clutter\)"; then
|
||||||
echo " - message subject should not be prefixed with 'clutter-' or 'Clutter', use 'clutter/' instead"
|
append_failed_test_case clutter-prefix $commit \
|
||||||
return 1
|
"Commit message subject should not be prefixed with 'clutter-' or 'Clutter', use 'clutter/' instead"
|
||||||
|
else
|
||||||
|
append_passed_test_case clutter-prefix $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$commit_message_subject" | grep -qe "\(^cogl-\|^Cogl\)"; then
|
if echo "$commit_message_subject" | grep -qe "\(^cogl-\|^Cogl\)"; then
|
||||||
echo " - message subject should not be prefixed with 'cogl-' or 'Cogl', use 'cogl/' instead"
|
append_failed_test_case cogl-prefix $commit \
|
||||||
return 1
|
"Commit message subject should not be prefixed with 'cogl-' or 'Cogl', use 'cogl/' instead"
|
||||||
|
else
|
||||||
|
append_passed_test_case cogl-prefix $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$commit_message_subject" | sed -e 's/^[^:]\+: //' | grep -qe '^[[:lower:]]'; then
|
if echo "$commit_message_subject" | sed -e 's/^[^:]\+: //' | grep -qe '^[[:lower:]]'; then
|
||||||
echo " - message subject should be properly Capitalized. E.g. 'window: Marginalize extradicity'"
|
append_failed_test_case capitalization $commit \
|
||||||
return 1
|
"Commit message subject should be properly Capitalized. E.g. 'window: Marginalize extradicity'"
|
||||||
|
else
|
||||||
|
append_passed_test_case capitalization $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$commit_message_subject" | grep -qe "\.[ch]:"; then
|
if echo "$commit_message_subject" | grep -qe "\.[ch]:"; then
|
||||||
echo " - message subject prefix should not include .c, .h, etc."
|
append_failed_test_case not-file-suffix $commit \
|
||||||
return 1
|
"Commit message subject prefix should not include .c, .h, etc."
|
||||||
|
else
|
||||||
|
append_passed_test_case not-file-suffix $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -57,19 +104,18 @@ function commit_message_subject_is_compliant() {
|
|||||||
|
|
||||||
RET=0
|
RET=0
|
||||||
for commit in $commits; do
|
for commit in $commits; do
|
||||||
commit_short=$(echo $commit | cut -c -8)
|
|
||||||
|
|
||||||
if commit_message_has_mr_url $commit; then
|
if commit_message_has_mr_url $commit; then
|
||||||
echo "Commit $commit_short must not contain a link to its own merge request"
|
append_failed_test_case superfluous_url $commit \
|
||||||
exit 1
|
"Commit message must not contain a link to its own merge request"
|
||||||
|
else
|
||||||
|
append_passed_test_case superfluous_url $commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
errors=$(commit_message_subject_is_compliant $commit)
|
check_commit_message_subject $commit
|
||||||
if [ $? != 0 ]; then
|
|
||||||
echo "Commit message for $commit_short is not compliant:"
|
|
||||||
echo "$errors"
|
|
||||||
RET=1
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
exit $RET
|
generate_junit_report commit-message-junit-report.xml
|
||||||
|
|
||||||
|
! grep -q '<failure' commit-message-junit-report.xml
|
||||||
|
exit $?
|
||||||
|
Loading…
Reference in New Issue
Block a user