diff options
author | Đoàn Trần Công Danh <congdanhqx@gmail.com> | 2021-05-17 15:10:52 +0000 |
---|---|---|
committer | Đoàn Trần Công Danh <sgn.danh@gmail.com> | 2021-05-21 08:56:44 +0000 |
commit | 1f07584a663ed110710c80d3c88b23a93bf981a5 (patch) | |
tree | 54fe2d58afe327e5addd5ecc86272b295da1b779 | |
parent | f507c73f32534bc0115c85d82fcbb60650ca7ef0 (diff) | |
download | void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar.gz void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar.bz2 void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar.lz void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar.xz void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.tar.zst void-packages-1f07584a663ed110710c80d3c88b23a93bf981a5.zip |
common: add basic commit lint
Warn if:
* subject is longer than 50 characters
Error if:
* any lines are longer than 80 characters except it's footnotes
* second line is not blank
-rw-r--r-- | .github/workflows/build.yaml | 2 | ||||
-rwxr-xr-x | common/scripts/lint-commits | 51 |
2 files changed, 53 insertions, 0 deletions
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1ea1da2e488..eb96a151c59 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,6 +21,8 @@ jobs: - run: common/travis/changed_templates.sh - run: common/travis/fetch-xtools.sh - run: common/travis/xlint.sh + # GitHub Action create a merge commit, ignore it + - run: common/scripts/lint-commits FETCH_HEAD HEAD^2 # Build changed packages. build: diff --git a/common/scripts/lint-commits b/common/scripts/lint-commits new file mode 100755 index 00000000000..785bf0ef1d0 --- /dev/null +++ b/common/scripts/lint-commits @@ -0,0 +1,51 @@ +#!/bin/sh + +die() { + printf '%s\n' "$*" >&2 + exit 1 +} + +GIT_CMD=$(command -v chroot-git 2>/dev/null) || +GIT_CMD=$(command -v git 2>/dev/null) || +die "neither chroot-git nor git could be found!" + +rev_parse() { + if [ -n "$1" ]; then + "$GIT_CMD" rev-parse --verify "$1" + else + shift + while test "$#" != 0 + do + "$GIT_CMD" rev-parse --verify "$1" 2>/dev/null && return + 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 + +for cmt in $("$GIT_CMD" rev-list --abbrev-commit $base..$tip) +do + "$GIT_CMD" cat-file commit "$cmt" | + awk -vC="$cmt" ' + # skip header + /^$/ && !msg { msg = 1; next } + !msg { next } + # 3: long-line-is-banned-except-footnote-like-this-for-url + (NF > 2) && (length > 80) { print C ": long line: " $0; exit 1 } + !subject { + if (length > 50) { print C ": subject is a bit long" } + # Below check is too noisy? + # if (!($0 ~ "^New package:" || $0 ~ ".*: update to")) { + # print C ": not new package/update/removal?" + # } + subject = 1; next + } + /^$/ { body = 1; next } + !body { print C ": second line must be blank"; exit 1 } + ' || status=1 +done +exit $status |