blob: 5b8887c5b877fd9e1173e71374b016dde2b4c155 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#!/bin/bash
BASE=${1:-origin/master}
RETCODE=0
RED='\033[1;31m'
GREEN='\033[1;32m'
NC='\033[0m'
function fail() {
echo -e "${RED}$*${NC}"
RETCODE=1
}
echo -e "${GREEN}Checking from $(git rev-parse --short ${BASE}):${NC}"
git log --pretty=oneline --no-merges --abbrev-commit ${BASE}..
echo
git diff ${BASE}.. -- '*.py' | grep '^+' > added_lines
git diff ${BASE}.. -- 'chirp/drivers/*.py' | grep '^+' > driver_lines
if grep -E '\<(from|import)\>.*\<six\>' added_lines; then
fail No new uses of six
fi
if grep -E '\<six\>' added_lines; then
fail No new uses of six
fi
if grep -E '\<(from|import)\>.*builtins' added_lines; then
fail No new uses of future
fi
if grep -E '\<future\>' added_lines; then
fail No new uses of future
fi
if grep -E '\<(from|import)\>.*\<past\>' added_lines; then
fail Use of past library not allowed
fi
if grep -E '\<MemoryMap\(' added_lines; then
fail New uses of MemoryMap should be MemoryMapBytes
fi
if grep -E "[^_]_\([^\"']" added_lines; then
fail 'Translated strings must be literals!'
fi
if grep -E "\<eval\(" added_lines; then
fail 'Use of eval() is dangerous and not permitted!'
fi
if git diff ${BASE}.. -- 'tools/cpep8.manifest' | tail -n +5 | grep -q '^+'; then
fail 'Do not add new files to cpep8.manifest; no longer needed'
fi
if git diff ${BASE}.. -- 'tools/cpep8.blacklist' | tail -n +5 | grep -q '^+'; then
fail 'Do not add new files to cpep8.blacklist; fix the code'
fi
grep -i 'license' added_lines > license_lines
if grep -ivE '(GNU General Public License|Free Software Foundation|gnu.org.licenses)' license_lines; then
fail 'Files must be GPLv3 licensed (or not contain any license language)'
fi
for file in $(git diff --name-only ${BASE}..); do
if file $file | grep -q CRLF; then
fail "$file : Files should be LF (Unix) format, not CR (Mac) or CRLF (Windows)"
fi
done
#if grep 'def match_model' added_lines; then
# fail 'New drivers should not have match_model() implemented as it is not needed'
#fi
if grep -E '\<print\(' added_lines; then
fail 'Do not use print()'
fi
if grep -E '\<(from|import)\>.*wx' driver_lines; then
fail 'Drivers may not import GUI components or manipulate the GUI'
fi
if grep -E '(subprocess|webbrowser)' driver_lines; then
fail 'Drivers may not spawn external commands'
fi
if git log ${BASE}.. --merges | grep .; then
fail Please do not include merge commits in your PR
fi
make -C chirp/locale clean all >/dev/null 2>&1
if [ $? -ne 0 ]; then
fail Locale build failed
fi
if git diff -- chirp/locale | grep '^+[^#+]' | grep -v POT-Creation; then
fail Locale files need updating
fi
added_files=$(git diff --name-only --diff-filter=A ${BASE}..)
added_py=$(git diff --name-only --diff-filter=A ${BASE}.. | grep '\.py$')
if echo $added_py | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then
fail All new drivers should include a test image
fi
modified_files=$(git diff --name-only --diff-filter=M ${BASE}..)
modified_img=$(echo "$modified_files" | grep 'tests.images')
modified_py=$(echo "$modified_files" | grep '\.py$')
if [ "$modified_img" -a "$modified_py" ]; then
fail "Change modifies an image and (potentially) a driver for a possible upgrade breakage"
fi
existing_drivers=$(git ls-tree --name-only $BASE -- chirp/drivers/)
limit=51
for nf in $added_py; do
for of in $existing_drivers; do
common=$(wdiff -s $of $nf | grep -I $nf | sed -r 's/.* ([0-9]+)% common.*/\1/')
if [ ! "$common" ]; then
continue
fi
if [ "$common" -gt "$limit" ]; then
fail "New file $nf shares at least ${common}% with $of!"
fi
done
done
rm -f added_lines license_lines
commits=$(git log --pretty=format:%h ${BASE}..)
for commit in $commits; do
git log -n1 $commit --pretty=format:%B > commit_msg
if [[ `sed -n '1p' commit_msg | wc -c` > 99 ]]; then
fail "First line of commit message of $commit must be <99 chars"
fi
if [[ `wc -l < commit_msg` > 1 ]]; then
if ! sed -n '2p' commit_msg | grep '^$'; then
fail "Second line of commit message of $commit must be blank for proper formatting in the notification emails"
fi
fi
rm -f commit_msg
done
exit $RETCODE
|