-
Notifications
You must be signed in to change notification settings - Fork 0
/
review
executable file
·248 lines (189 loc) · 6.05 KB
/
review
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/sh
. legit-setup.sh
follow_fixes_up()
{
local _commit=$1
local _exclude=$2
for fix in $(read_header fixed-by proposals/$_commit/proposal)
do
if test -n $_exclude && [ "$fix" != "$_exclude" ]
then
replace_header Status Auto-Rejected proposals/$fix/proposal
git add proposals/$fix/proposal >> /dev/null 2>&1
follow_fixes_up $fix
fi
done
}
follow_fixes_down()
{
local _commit=$1
local _fix=$(read_header fix-of proposals/$_commit/proposal)
if test -n "$_fix"
then
replace_header Status Auto-Rejected proposals/$_fix/proposal
git add proposals/$_fix/proposal >> /dev/null 2>&1
follow_fixes_up $_fix $_commit
follow_fixes_down $_fix
fi
}
# Get the commit message
message=
user=$(git config user.email)
user=${user//@/_}
result=
while test $# != 0
do
case "$1" in
-m)
shift
# Get the message, but trim whitespace from it
message=`echo $1 | sed 's/^\s*//;s/\s*$//'`
# This will be blank if the user either failed to provide a
# message, or if it was only whitespace (which we reject)
if [ -z "$message" ]; then
usage
fi
shift
;;
--approve)
result="approve" ;;
--reject)
result="reject" ;;
*)
usage
esac
shift
done
if ! test -n "$result"
then
usage
fi
if ! test -n "$user"
then
die "fatal: no user was found. Set one in git config"
fi
if ! permissions.sh review
then
die
fi
# People need to specify a message!
if [ ! -n "$message" ]; then
echo "# Please enter the review message. Lines starting" > .git/REVIEW_EDITMSG
echo "# with '#' will be ignored, and an empty message aborts the proposal." >> .git/REVIEW_EDITMSG
git_editor .git/REVIEW_EDITMSG
# Remove comments, whitespace and blank lines
message=`sed '/\s*#/d;s/^\s*//;s/\s*$//;/./,$!d' .git/REVIEW_EDITMSG`
if [ -z "$message" ]; then
echo "Aborting because of empty message"
exit 0
fi
fi
# Has this repo been legitimised?
if ! git show-ref --quiet refs/heads/tracking; then
die "fatal: no tracking branch exists"
fi
require_clean_work_tree 'make a review'
# Check we're not in a locked branch, or the tracking branch
orig_head=`git symbolic-ref -q --short HEAD`
if [ "$orig_head" = "tracking" ]; then
die "fatal: you are in the tracking branch. Please checkout the
the branch you wish to review."
fi
# The commit at the head of the proposal is used as it's ID
name=`git rev-parse --verify HEAD`
# Let's do this
git checkout --quiet tracking
# Hash collisions shouldn't happen...
if [ ! -d .tracking/proposals/$name ]; then
die "fatal: this proposal doesn't exist"
fi
if [ -e .tracking/proposals/$name/$user ]
then
die "fatal: you have already reviewed this proposal"
fi
cd .tracking/proposals/$name
vote_count=$(read_header votes proposal)
echo "Reviewer: $(git config user.name) <$(git config user.email)>" > $user
echo "Reviewed-at: $(date -R)" >> $user
if [[ "reject" == "$result" ]]
then
echo "Result: Reject" >> $user
vote_count=$(expr $vote_count - 1)
else
echo "Result: Accept" >> $user
vote_count=$(expr $vote_count + 1)
fi
echo "" >> $user
echo "$message" >> $user
replace_header Votes $vote_count proposal
git add $user >> /dev/null 2>&1
git add proposal >> /dev/null 2>&1
cd ../../users/
replace_header Reviews $(expr $(read_header reviews $user) + 1) $user
git add $user >> /dev/null 2>&1
git commit --quiet -m "Reviewed: $name"
echo "Successfully Reviewed"
cd ..
voteThreshold=$(git config --file config general.voteThreshold)
if ! test -z $voteThreshold
then
if test $vote_count -ge $voteThreshold
then
echo "The proposal has reached the required votes. Automatically approving..."
replace_header Status Accepted proposals/$name/proposal
sed '/$name/d' proposals/open | cat > proposals/open
echo $name >> proposals/pending
git add proposals/$name/proposal >> /dev/null 2>&1
git add proposals/open >> /dev/null 2>&1
git add proposals/pending >> /dev/null 2>&1
follow_fixes_up $name
follow_fixes_down $name
for file in $(find proposals/$name/* -printf %f\\n)
do
if [[ $file != "proposal" ]] && [ -n "$file" ]
then
result=$(read_header result proposals/$name/$file)
if [[ $result == "Reject" ]]
then
header1="Bad-Rejects"
header2="bad-rejects"
else
header1="Good-Accepts"
header2="good-accepts"
fi
file="./users/$file"
replace_header $header1 $(expr $(read_header $header2 $file) + 1) $file
git add $file >> /dev/null 2>&1
fi
done
git commit --quiet -m "Approved: $name"
cd ..
merge $name
elif test $vote_count -le $(expr $voteThreshold \* -1)
then
replace_header Status Rejected ./proposals/$name/proposal
sed '/$name/d' proposals/open | cat > ./proposals/open
git add proposals/$name/proposal >> /dev/null 2>&1
git add proposals/open >> /dev/null 2>&1
for file in $(find proposals/$name/* -printf %f\\n)
do
if [[ $file != "proposal" ]] && [ -n "$file" ]; then
result=$(read_header result proposals/$name/$file)
if test $result = "Reject"
then
header1="Good-Rejects"
header2="good-rejects"
else
header1="Bad-Accepts"
header2="bad-accepts"
fi
file="./users/$file"
replace_header $header1 $(expr $(read_header $header2 $file) + 1) $file
git add $file >> /dev/null 2>&1
fi
done
git commit --quiet -m "Rejected: $name"
cd ..
fi
fi
git checkout --quiet $orig_head