Skip to content

Commit d39d7ed

Browse files
committed
dist/tools: add more forbidden keywords to PR check
1 parent eb08ad5 commit d39d7ed

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

dist/tools/pr_check/check.sh

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ cd "$RIOTBASE" || exit
1717

1818
EXIT_CODE=0
1919

20+
# Keywords that should trigger the commit message check and prevent an accidental
21+
# merge of something not meant to be merged.
22+
# The pretty-print format of the commit messages is always the following:
23+
# `a5e4f038b8 commit message`
24+
# This has to be reflected in the RegEx matching pattern.
25+
NOMERGE_KEYWORD_FILE="$(dirname "$0")/no_merge_keywords"
26+
2027
github_annotate_setup
2128

2229
if tput colors &> /dev/null && [ "$(tput colors)" -ge 8 ]; then
@@ -33,30 +40,28 @@ else
3340
RIOT_MASTER="master"
3441
fi
3542

36-
keyword_filter() {
37-
grep -i \
38-
-e "^ [0-9a-f]\+ .\{0,2\}SQUASH" \
39-
-e "^ [0-9a-f]\+ .\{0,2\}FIX" \
40-
-e "^ [0-9a-f]\+ .\{0,2\}REMOVE *ME" \
41-
-e "^ [0-9a-f]\+ .\{0,2\}Update"
42-
}
43-
44-
SQUASH_COMMITS="$(git log "$(git merge-base HEAD "${RIOT_MASTER}")"...HEAD --pretty=format:" %h %s" | \
45-
keyword_filter)"
43+
SQUASH_COMMITS="$(git log "$(git merge-base HEAD "${RIOT_MASTER}")"...HEAD --pretty=format:"%h %s" | \
44+
grep -i -f "${NOMERGE_KEYWORD_FILE}")"
4645

4746
if [ -n "${SQUASH_COMMITS}" ]; then
4847
if github_annotate_is_on; then
49-
echo "${SQUASH_COMMITS}" | while read -r commit; do
50-
ANNOTATION="Commit needs to be squashed: \"${commit}\""
51-
ANNOTATION="${ANNOTATION}\n\nPLEASE ONLY SQUASH WHEN ASKED BY A "
48+
ANNOTATION=""
49+
while read -r commit; do
50+
ANNOTATION="${ANNOTATION}Commit needs to be squashed or contains a no-merge keyword: \"${commit}\"\n"
51+
done < <(echo "${SQUASH_COMMITS}")
52+
53+
if [ -n "${ANNOTATION}" ]; then
54+
ANNOTATION="${ANNOTATION}\nPLEASE ONLY SQUASH WHEN ASKED BY A "
5255
ANNOTATION="${ANNOTATION}MAINTAINER!"
5356
ANNOTATION="${ANNOTATION}\nSee: "
54-
ANNOTATION="${ANNOTATION}https://github.com/RIOT-OS/RIOT/blob/master/CONTRIBUTING.md#squash-commits-after-review"
57+
ANNOTATION="${ANNOTATION}https://github.com/RIOT-OS/RIOT/blob/master/CONTRIBUTING.md#squash-commits-after-review\n"
5558
github_annotate_error_no_file "${ANNOTATION}"
56-
done
59+
fi
5760
else
58-
echo -e "${CERROR}Pull request needs squashing:${CRESET}" 1>&2
59-
echo -e "${SQUASH_COMMITS}"
61+
echo -e "${CERROR}Pull request needs squashing or contains no-merge keywords:${CRESET}" 1>&2
62+
while IFS= read -r line; do
63+
echo -e " ${line}"
64+
done <<< "${SQUASH_COMMITS}"
6065
fi
6166
EXIT_CODE=1
6267
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[0-9a-f]\+ SQUASH
2+
[0-9a-f]\+ FIX
3+
[0-9a-f]\+ REMOVE *ME
4+
[0-9a-f]\+ Update
5+
[0-9a-f]\+ \<DONOTMERGE\>
6+
[0-9a-f]\+ \<DO NOT MERGE\>
7+
[0-9a-f]\+ \<DON'T MERGE\>
8+
[0-9a-f]\+ \<NO MERGE\>
9+
[0-9a-f]\+ \<DELETE ME\>
10+
[0-9a-f]\+ \<DELETEME\>
11+
[0-9a-f]\+ \<WIP\>
12+
[0-9a-f]\+ \<TEMP\>

0 commit comments

Comments
 (0)