ntpd-rs: update to 1.3.1
[void-pkg.git] / common / scripts / lint-commits
blob56f16ff194b346dd2460d9fccbed114580dc3343
1 #!/bin/sh
3 die() {
4 printf '%s\n' "$*" >&2
5 exit 1
8 command -v git >/dev/null 2>&1 ||
9 die "neither chroot-git nor git could be found!"
11 rev_parse() {
12 if [ -n "$1" ]; then
13 git rev-parse --verify "$1"
14 else
15 shift
16 while test "$#" != 0
18 git rev-parse --verify "$1" 2>/dev/null && return
19 shift
20 done
21 return 1
25 base=$(rev_parse "$1" FETCH_HEAD ORIG_HEAD) || die "base commit not found"
26 tip=$(rev_parse "$2" HEAD) || die "tip commit not found"
27 status=0
29 for cmt in $(git rev-list --abbrev-commit $base..$tip)
31 git cat-file commit "$cmt" |
32 awk -vC="$cmt" '
33 # skip header
34 /^$/ && !msg { msg = 1; next }
35 /^author .*noreply/ && !msg {
36 print "::error title=Commit Lint::" C ": authored by noreply email";
37 ret=1;
39 /^author .*(localhost|localdomain|[(]none[)])/ && !msg {
40 print "::error title=Commit Lint::" C ": authored by localhost email";
41 ret=1;
43 !msg { next }
44 # 3: long-line-is-banned-except-footnote-like-this-for-url
45 (NF > 2) && (length > 80) {
46 print "::error title=Commit Lint::" C ": long line: " $0
47 ret = 1
49 !subject {
50 if (length > 50) { print "::warning title=Commit Lint::" C ": subject is a bit long" }
51 if (!($0 ~ ":" || $0 ~ "^Take over maintainership " || $0 ~ "^Orphan ")) { print "::error title=Commit Lint::" C ": subject does not follow CONTRIBUTING.md guildelines"; exit 1 }
52 # Below check is too noisy?
53 # if (!($0 ~ "^New package:" || $0 ~ ".*: update to")) {
54 # print "::warning title=Commit Lint::" C ": not new package/update/removal?"
55 # }
56 subject = 1; next
58 /^$/ { body = 1; next }
59 !body {
60 print "::error title=Commit Lint::" C ": second line must be blank"
61 ret = 1
63 END { exit ret }
64 ' || status=1
65 done
66 exit $status