11#! /bin/bash
22
3+ # Based on https://openwrt.org/submitting-patches#submission_guidelines
4+ MAX_SUBJECT_LEN=50
5+ MAX_BODY_LINE_LEN=75
6+
37source workflow_context/.github/scripts/ci_helpers.sh
48
59RET=0
@@ -48,19 +52,63 @@ for commit in $(git rev-list HEAD ^origin/"$BRANCH"); do
4852 RET=1
4953 fi
5054
55+ echo
56+ info " Checking subject:"
5157 subject=" $( git show -s --format=%s " $commit " ) "
52- if echo " $subject " | grep -q -e ' ^[0-9A-Za-z,+/_-]\+: ' -e ' ^Revert ' ; then
53- success " Commit subject line seems OK ($subject )"
54- elif echo " $subject " | grep -iq ' ^Translated using Weblate.*' ; then
55- warn " Weblate commit subject line exception: $subject "
56- elif echo " $subject " | grep -iq ' ^Added translation using Weblate.*' ; then
57- warn " Weblate commit subject line exception: $subject "
58+ echo " $subject "
59+
60+ # Check subject format
61+ if echo " $subject " | grep -iq -e ' ^Translated using Weblate.*' -e ' ^Added translation using Weblate.*' ; then
62+ warn " Weblate commit subject line exception"
63+ elif echo " $subject " | grep -q -e ' ^[0-9A-Za-z,+/_-]\+: [a-z]' -e ' ^Revert ' ; then
64+ success " Commit subject line format seems OK"
65+ elif echo " $subject " | grep -q -e ' ^[0-9A-Za-z,+/_-]\+: [A-Z]' ; then
66+ err " First word after prefix in subject should not be capitalized"
67+ RET=1
68+ elif echo " $subject " | grep -q -e ' ^[0-9A-Za-z,+/_-]\+: ' ; then
69+ # Handles cases when there's a prefix but the check for capitalization fails (e.g. no word
70+ # after prefix)
71+ err " Commit subject line MUST start with '<package name>: ' and be followed by a lower-case word"
72+ RET=1
5873 else
59- err " Commit subject line MUST start with '<package name>: ' ($subject )"
74+ err " Commit subject line MUST start with '<package name>: '"
75+ RET=1
76+ fi
77+
78+ if echo " $subject " | grep -q ' \.$' ; then
79+ err " Commit subject line should not end with a period"
6080 RET=1
6181 fi
6282
83+ # Check subject length
84+ if [ ${# subject} -gt " $MAX_SUBJECT_LEN " ]; then
85+ warn " Commit subject line is longer that $MAX_SUBJECT_LEN characters (is ${# subject} )"
86+ split_err " $MAX_SUBJECT_LEN " " $subject "
87+ else
88+ success " Commit subject line is $MAX_SUBJECT_LEN characters or less"
89+ fi
90+
91+ echo
92+ info " Checking body:"
6393 body=" $( git show -s --format=%b " $commit " ) "
94+ echo " $body "
95+ echo
96+
97+ # Check body line lengths
98+ body_line_too_long=0
99+ line_num=0
100+ while IFS= read -r line; do
101+ line_num=$(( line_num + 1 ))
102+ if [ ${# line} -gt " $MAX_BODY_LINE_LEN " ]; then
103+ warn " Commit body line $line_num is longer than $MAX_BODY_LINE_LEN characters (is ${# line} ):"
104+ split_err " $MAX_BODY_LINE_LEN " " $line "
105+ body_line_too_long=1
106+ fi
107+ done <<< " $body"
108+ if [ " $body_line_too_long " = 0 ]; then
109+ success " Commit body lines are $MAX_BODY_LINE_LEN characters or less"
110+ fi
111+
64112 sob=" $( git show -s --format=' Signed-off-by: %aN <%aE>' " $commit " ) "
65113 if echo " $body " | grep -qF " $sob " ; then
66114 success " Signed-off-by matches author"
@@ -78,12 +126,15 @@ for commit in $(git rev-list HEAD ^origin/"$BRANCH"); do
78126 success " Signed-off-by email is not a GitHub noreply email"
79127 fi
80128
81- if echo " $body " | grep -v " Signed-off-by:" ; then
129+ if echo " $body " | grep -qv " Signed-off-by:" ; then
82130 success " A commit message exists"
83131 else
84132 err " Commit message is missing. Please describe your changes."
85133 RET=1
86134 fi
135+
136+ info " === Done checking commit '$commit '"
137+ echo
87138done
88139
89140exit $RET
0 commit comments