2021-05-17 17:10:52 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
die() {
|
|
|
|
printf '%s\n' "$*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-09-16 03:50:39 +02:00
|
|
|
command -v git >/dev/null 2>&1 ||
|
2021-05-17 17:10:52 +02:00
|
|
|
die "neither chroot-git nor git could be found!"
|
|
|
|
|
|
|
|
rev_parse() {
|
|
|
|
if [ -n "$1" ]; then
|
2022-09-16 03:50:39 +02:00
|
|
|
git rev-parse --verify "$1"
|
2021-05-17 17:10:52 +02:00
|
|
|
else
|
|
|
|
shift
|
|
|
|
while test "$#" != 0
|
|
|
|
do
|
2022-09-16 03:50:39 +02:00
|
|
|
git rev-parse --verify "$1" 2>/dev/null && return
|
2021-05-17 17:10:52 +02:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
base=$(rev_parse "$1" FETCH_HEAD ORIG_HEAD) || die "base commit not found"
|
|
|
|
tip=$(rev_parse "$2" HEAD) || die "tip commit not found"
|
|
|
|
status=0
|
|
|
|
|
2022-09-16 03:50:39 +02:00
|
|
|
for cmt in $(git rev-list --abbrev-commit $base..$tip)
|
2021-05-17 17:10:52 +02:00
|
|
|
do
|
2022-09-16 03:50:39 +02:00
|
|
|
git cat-file commit "$cmt" |
|
2021-05-17 17:10:52 +02:00
|
|
|
awk -vC="$cmt" '
|
|
|
|
# skip header
|
|
|
|
/^$/ && !msg { msg = 1; next }
|
2023-01-11 03:28:30 +01:00
|
|
|
/^author .*noreply/ && !msg {
|
|
|
|
print "::error title=Commit Lint::" C ": authored by noreply email";
|
|
|
|
ret=1;
|
|
|
|
}
|
2023-02-02 13:13:18 +01:00
|
|
|
/^author .*(localhost|localdomain|[(]none[)])/ && !msg {
|
|
|
|
print "::error title=Commit Lint::" C ": authored by localhost email";
|
|
|
|
ret=1;
|
|
|
|
}
|
2021-05-17 17:10:52 +02:00
|
|
|
!msg { next }
|
|
|
|
# 3: long-line-is-banned-except-footnote-like-this-for-url
|
2023-01-11 03:28:30 +01:00
|
|
|
(NF > 2) && (length > 80) {
|
|
|
|
print "::error title=Commit Lint::" C ": long line: " $0
|
|
|
|
ret = 1
|
|
|
|
}
|
2021-05-17 17:10:52 +02:00
|
|
|
!subject {
|
2022-05-02 06:58:34 +02:00
|
|
|
if (length > 50) { print "::warning title=Commit Lint::" C ": subject is a bit long" }
|
|
|
|
if (!($0 ~ ":" || $0 ~ "^Take over maintainership " || $0 ~ "^Orphan ")) { print "::error title=Commit Lint::" C ": subject does not follow CONTRIBUTING.md guildelines"; exit 1 }
|
2021-05-17 17:10:52 +02:00
|
|
|
# Below check is too noisy?
|
|
|
|
# if (!($0 ~ "^New package:" || $0 ~ ".*: update to")) {
|
2022-05-02 06:58:34 +02:00
|
|
|
# print "::warning title=Commit Lint::" C ": not new package/update/removal?"
|
2021-05-17 17:10:52 +02:00
|
|
|
# }
|
|
|
|
subject = 1; next
|
|
|
|
}
|
|
|
|
/^$/ { body = 1; next }
|
2023-01-11 03:28:30 +01:00
|
|
|
!body {
|
|
|
|
print "::error title=Commit Lint::" C ": second line must be blank"
|
|
|
|
ret = 1
|
|
|
|
}
|
|
|
|
END { exit ret }
|
2021-05-17 17:10:52 +02:00
|
|
|
' || status=1
|
|
|
|
done
|
|
|
|
exit $status
|