]>
Commit | Line | Data |
---|---|---|
cb524aa2 GDN |
1 | #!/bin/bash |
2 | ||
3 | REF="HEAD" | |
4 | ||
5 | # test a url | |
6 | function test_url() | |
7 | { | |
8 | url="$1" | |
9 | if ! curl --output /dev/null --max-time 60 \ | |
10 | --silent --head --fail "$url" ; then | |
11 | echo "\"$url\" is unreachable" | |
12 | return 1 | |
13 | fi | |
3f2da6cb GDN |
14 | |
15 | return 0 | |
cb524aa2 GDN |
16 | } |
17 | ||
18 | # check for a tagged line | |
19 | function check_tagged_line() | |
20 | { | |
3f2da6cb | 21 | regex='^\s*'"$1"':\s[[:print:]]+\s<[[:graph:]]+>$' |
9d1a39ce | 22 | foundline=$(git log -n 1 "$REF" | grep -E -m 1 "$regex") |
cb524aa2 GDN |
23 | if [ -z "$foundline" ]; then |
24 | echo "error: missing \"$1\"" | |
25 | return 1 | |
26 | fi | |
27 | ||
28 | return 0 | |
29 | } | |
30 | ||
31 | # check for a tagged line and check that the link is valid | |
32 | function check_tagged_line_with_url () | |
33 | { | |
3f2da6cb | 34 | regex='^\s*'"$1"':\s\K([[:graph:]]+)$' |
cb524aa2 GDN |
35 | foundline=$(git log -n 1 "$REF" | grep -Po "$regex") |
36 | if [ -z "$foundline" ]; then | |
37 | echo "error: missing \"$1\"" | |
38 | return 1 | |
39 | fi | |
40 | ||
41 | if ! test_url "$foundline"; then | |
42 | return 1 | |
43 | fi | |
44 | ||
45 | return 0 | |
46 | } | |
47 | ||
48 | # check commit message for a normal commit | |
49 | function new_change_commit() | |
50 | { | |
51 | error=0 | |
52 | ||
b0d579bc NG |
53 | # subject is not longer than 72 characters |
54 | long_subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}') | |
cb524aa2 | 55 | if [ -n "$long_subject" ]; then |
b0d579bc | 56 | echo "error: commit subject over 72 characters" |
cb524aa2 GDN |
57 | error=1 |
58 | fi | |
59 | ||
60 | # need a signed off by | |
61 | if ! check_tagged_line "Signed-off-by" ; then | |
62 | error=1 | |
63 | fi | |
64 | ||
65 | # ensure that no lines in the body of the commit are over 72 characters | |
9d1a39ce | 66 | body=$(git log -n 1 --pretty=%b "$REF" | grep -E -m 1 '.{73}') |
cb524aa2 GDN |
67 | if [ -n "$body" ]; then |
68 | echo "error: commit message body contains line over 72 characters" | |
69 | error=1 | |
70 | fi | |
71 | ||
72 | return $error | |
73 | } | |
74 | ||
75 | function is_openzfs_port() | |
76 | { | |
77 | # subject starts with OpenZFS means it's an openzfs port | |
9d1a39ce | 78 | subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS') |
cb524aa2 GDN |
79 | if [ -n "$subject" ]; then |
80 | return 0 | |
81 | fi | |
82 | ||
83 | return 1 | |
84 | } | |
85 | ||
86 | function openzfs_port_commit() | |
87 | { | |
88 | # subject starts with OpenZFS dddd | |
9d1a39ce | 89 | subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS [[:digit:]]+ - ') |
cb524aa2 GDN |
90 | if [ -z "$subject" ]; then |
91 | echo "OpenZFS patch ports must have a summary that starts with \"OpenZFS dddd - \"" | |
92 | error=1 | |
93 | fi | |
94 | ||
95 | # need an authored by line | |
96 | if ! check_tagged_line "Authored by" ; then | |
97 | error=1 | |
98 | fi | |
99 | ||
100 | # need a reviewed by line | |
101 | if ! check_tagged_line "Reviewed by" ; then | |
102 | error=1 | |
103 | fi | |
104 | ||
105 | # need a approved by line | |
106 | if ! check_tagged_line "Approved by" ; then | |
107 | error=1 | |
108 | fi | |
109 | ||
110 | # need ported by line | |
111 | if ! check_tagged_line "Ported-by" ; then | |
112 | error=1 | |
113 | fi | |
114 | ||
115 | # need a url to openzfs commit and it should be valid | |
116 | if ! check_tagged_line_with_url "OpenZFS-commit" ; then | |
117 | error=1 | |
118 | fi | |
119 | ||
120 | # need a url to illumos issue and it should be valid | |
121 | if ! check_tagged_line_with_url "OpenZFS-issue" ; then | |
122 | error=1 | |
123 | fi | |
124 | ||
125 | return $error | |
126 | } | |
127 | ||
128 | if [ -n "$1" ]; then | |
129 | REF="$1" | |
130 | fi | |
131 | ||
132 | # if openzfs port, test against that | |
133 | if is_openzfs_port; then | |
134 | if ! openzfs_port_commit ; then | |
135 | exit 1 | |
136 | else | |
137 | exit 0 | |
138 | fi | |
139 | fi | |
140 | ||
141 | # have a normal commit | |
142 | if ! new_change_commit ; then | |
143 | exit 1 | |
144 | fi | |
145 | ||
146 | exit 0 |