Skip to content

Commit 58cd1d8

Browse files
classabbyampthe-maldridge
authored andcommitted
res/ci/commit-lint.sh: add commit lint script
1 parent feb2d05 commit 58cd1d8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

res/ci/commit-lint.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
die() {
4+
printf '%s\n' "$*" >&2
5+
exit 1
6+
}
7+
8+
command -v git >/dev/null 2>&1 ||
9+
die "neither chroot-git nor git could be found!"
10+
11+
tip="$(git rev-list -1 --parents HEAD)"
12+
case "$tip" in
13+
# This is a merge commit, pick last parent
14+
*" "*" "*) tip="${tip##* }" ;;
15+
# This is a non-merge commit, pick itself
16+
*) tip="${tip%% *}" ;;
17+
esac
18+
19+
base="$(git merge-base origin/HEAD "$tip")"
20+
21+
[ $(git rev-list --count "$tip" "^$base") -lt 20 ] || {
22+
echo "::error title=Branch out of date::Your branch is too out of date. Please rebase on upstream and force-push."
23+
exit 1
24+
}
25+
26+
status=0
27+
28+
for cmt in $(git rev-list --abbrev-commit $base..$tip)
29+
do
30+
git cat-file commit "$cmt" |
31+
awk -vC="$cmt" '
32+
# skip header
33+
/^$/ && !msg { msg = 1; next }
34+
!msg { next }
35+
# 3: long-line-is-banned-except-footnote-like-this-for-url
36+
(NF > 2) && (length > 80) { print "::error title=Commit Lint::" C ": long line: " $0; exit 1 }
37+
!subject {
38+
if (length > 50) { print "::warning title=Commit Lint::" C ": subject is a bit long" }
39+
if (!($0 ~ ":")) { print "::error title=Commit Lint::" C ": subject does not follow CONTRIBUTING.md guidelines"; exit 1 }
40+
subject = 1; next
41+
}
42+
/^$/ { body = 1; next }
43+
!body { print "::error title=Commit Lint::" C ": second line must be blank"; exit 1 }
44+
' || status=1
45+
done
46+
exit $status

0 commit comments

Comments
 (0)