summaryrefslogtreecommitdiffstats
path: root/dev/patchbot/scripts/post-ai.sh
blob: 7dba63a118f77e91ebfd63a28cda6fe4d5317885 (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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/bin/bash

####
#### Todo:
####   - change line color based on the selected radio button
####   - support collapsing lines per color/category (show/hide for each)
####   - add category "next" and see if the prompt can handle that (eg: d3e379b3)
####   - produce multiple lists on output (per category) allowing to save batches
####

die() {
	[ "$#" -eq 0 ] || echo "$*" >&2
	exit 1
}

err() {
	echo "$*" >&2
}

quit() {
	[ "$#" -eq 0 ] || echo "$*"
	exit 0
}

#### Main

USAGE="Usage: ${0##*/} [ -h ] [ -b 'bkp_list' ] patch..."
MYSELF="$0"
GITURL="http://git.haproxy.org/?p=haproxy.git;a=commitdiff;h="
ISSUES="https://github.com/haproxy/haproxy/issues/"
BKP=""

while [ -n "$1" -a -z "${1##-*}" ]; do
	case "$1" in
		-h|--help) quit "$USAGE" ;;
		-b)        BKP="$2"; shift 2 ;;
		*)         die  "$USAGE" ;;
	esac
done

PATCHES=( "$@" )

if [ ${#PATCHES[@]} = 0 ]; then
        die "$USAGE"
fi

# BKP is a space-delimited list of 8-char commit IDs, we'll
# assign them to the local bkp[] associative array.

declare -A bkp

for cid in $BKP; do
    bkp[$cid]=1
done

# some colors
BG_B="#e0e0e0"
BT_N="gray";     BG_N="white"
BT_U="#00e000";  BG_U="#e0ffe0"
BT_W="#0060ff";  BG_W="#e0e0ff"
BT_Y="red";      BG_Y="#ffe0e0"

echo "<HTML>"

cat <<- EOF
<HEAD><style>
input.n[type="radio"] {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 3px solid $BT_N;
  background-color: transparent;
}
input.n[type="radio"]:checked {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 2px solid black;
  background-color: $BT_N;
}

input.u[type="radio"] {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 3px solid $BT_U;
  background-color: transparent;
}
input.u[type="radio"]:checked {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 2px solid black;
  background-color: $BT_U;
}

input.w[type="radio"] {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 3px solid $BT_W;
  background-color: transparent;
}
input.w[type="radio"]:checked {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 2px solid black;
  background-color: $BT_W;
}

input.y[type="radio"] {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 3px solid $BT_Y;
  background-color: transparent;
}
input.y[type="radio"]:checked {
  appearance: none;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  border: 2px solid black;
  background-color: $BT_Y;
}
</style>

<script type="text/javascript"><!--

var nb_patches = 0;
var cid = [];
var bkp = [];

// first line to review
var review = 0;

// show/hide table lines and update their color
function updt_table(line) {
  var b = document.getElementById("sh_b").checked;
  var n = document.getElementById("sh_n").checked;
  var u = document.getElementById("sh_u").checked;
  var w = document.getElementById("sh_w").checked;
  var y = document.getElementById("sh_y").checked;
  var tn = 0, tu = 0, tw = 0, ty = 0;
  var i, el;

  for (i = 1; i < nb_patches; i++) {
    if (document.getElementById("bt_" + i + "_n").checked) {
      tn++;
      if (line && i != line)
        continue;
      el = document.getElementById("tr_" + i);
      el.style.backgroundColor = "$BG_N";
      el.style.display = n && (b || !bkp[i]) && i >= review ? "" : "none";
    }
    else if (document.getElementById("bt_" + i + "_u").checked) {
      tu++;
      if (line && i != line)
        continue;
      el = document.getElementById("tr_" + i);
      el.style.backgroundColor = "$BG_U";
      el.style.display = u && (b || !bkp[i]) && i >= review ? "" : "none";
    }
    else if (document.getElementById("bt_" + i + "_w").checked) {
      tw++;
      if (line && i != line)
        continue;
      el = document.getElementById("tr_" + i);
      el.style.backgroundColor = "$BG_W";
      el.style.display = w && (b || !bkp[i]) && i >= review ? "" : "none";
    }
    else if (document.getElementById("bt_" + i + "_y").checked) {
      ty++;
      if (line && i != line)
        continue;
      el = document.getElementById("tr_" + i);
      el.style.backgroundColor = "$BG_Y";
      el.style.display = y && (b || !bkp[i]) && i >= review ? "" : "none";
    }
    else {
      // bug
      if (line && i != line)
        continue;
      el = document.getElementById("tr_" + i);
      el.style.backgroundColor = "red";
      el.style.display = "";
    }
  }
  document.getElementById("cnt_n").innerText = tn;
  document.getElementById("cnt_u").innerText = tu;
  document.getElementById("cnt_w").innerText = tw;
  document.getElementById("cnt_y").innerText = ty;
}

function updt_output() {
  var b = document.getElementById("sh_b").checked;
  var i, y = "", w = "", u = "", n = "";

  for (i = 1; i < nb_patches; i++) {
    if (i < review)
       continue;
    if (bkp[i])
       continue;
    if (document.getElementById("bt_" + i + "_y").checked)
       y = y + " " + cid[i];
    else if (document.getElementById("bt_" + i + "_w").checked)
       w = w + " " + cid[i];
    else if (document.getElementById("bt_" + i + "_u").checked)
       u = u + " " + cid[i];
    else if (document.getElementById("bt_" + i + "_n").checked)
       n = n + " " + cid[i];
  }

  // update the textarea
  document.getElementById("output").value =
    "cid_y=(" + y + " )\n" +
    "cid_w=(" + w + " )\n" +
    "cid_u=(" + u + " )\n" +
    "cid_n=(" + n + " )\n";
}

function updt(line,value) {
  if (value == "r") {
    review = line;
    line = 0; // redraw everything
  }
  updt_table(line);
  updt_output();
}

// -->
</script>
</HEAD>
EOF

echo "<BODY>"
echo -n "<big><big>Show:"
echo -n " <span style='background-color:$BG_B'><input type='checkbox' onclick='updt_table(0);' id='sh_b' checked />B (${#bkp[*]})</span> "
echo -n " <span style='background-color:$BG_N'><input type='checkbox' onclick='updt_table(0);' id='sh_n' checked />N (<span id='cnt_n'>0</span>)</span> "
echo -n " <span style='background-color:$BG_U'><input type='checkbox' onclick='updt_table(0);' id='sh_u' checked />U (<span id='cnt_u'>0</span>)</span> "
echo -n " <span style='background-color:$BG_W'><input type='checkbox' onclick='updt_table(0);' id='sh_w' checked />W (<span id='cnt_w'>0</span>)</span> "
echo -n " <span style='background-color:$BG_Y'><input type='checkbox' onclick='updt_table(0);' id='sh_y' checked />Y (<span id='cnt_y'>0</span>)</span> "
echo -n "</big/></big> (B=show backported, N=no/drop, U=uncertain, W=wait/next, Y=yes/pick"
echo ")<P/>"

echo "<TABLE COLS=5 BORDER=1 CELLSPACING=0 CELLPADDING=3>"
echo "<TR><TH>All<br/><input type='radio' name='review' onclick='updt(0,\"r\");' checked title='Start review here'/></TH><TH>CID</TH><TH>Subject</TH><TH>Verdict<BR>N U W Y</BR></TH><TH>Reason</TH></TR>"
seq_num=1; do_check=1; review=0;
for patch in "${PATCHES[@]}"; do
        # try to retrieve the patch's numbering (0001-9999)
        pnum="${patch##*/}"
        pnum="${pnum%%[^0-9]*}"

        id=$(sed -ne 's/^#id: \(.*\)/\1/p' "$patch")
        resp=$(grep -v ^llama "$patch" | sed -ne '/^Explanation:/,$p' | sed -z 's/\n[\n]*/\n/g' | sed -z 's/\([^. ]\)\n\([A-Z]\)/\1.\n\2/' | tr '\012' ' ')
        resp="${resp#Explanation:}";
        while [ -n "$resp" -a -z "${resp##[ .]*}" ]; do
                resp="${resp#[ .]}"
        done

        respl=$(echo -- "$resp" | tr 'A-Z' 'a-z')

        if [[ "${respl}" =~ (conclusion|verdict)[:\ ][^.]*yes ]]; then
                verdict=yes
        elif [[ "${respl}" =~ (conclusion|verdict)[:\ ][^.]*wait ]]; then
                verdict=wait
        elif [[ "${respl}" =~ (conclusion|verdict)[:\ ][^.]*no ]]; then
                verdict=no
        elif [[ "${respl}" =~ (conclusion|verdict)[:\ ][^.]*uncertain ]]; then
                verdict=uncertain
        elif [[ "${respl}" =~ (\"wait\"|\"yes\"|\"no\"|\"uncertain\")[^\"]*$ ]]; then
                # last word under quotes in the response, sometimes happens as
                # in 'thus I would conclude "no"'.
                verdict=${BASH_REMATCH[1]}
        else
                verdict=uncertain
        fi

        verdict="${verdict//[\"\',;:. ]}"
        verdict=$(echo -n "$verdict" | tr '[A-Z]' '[a-z]')

        # There are two formats for the ID line:
        #   - old: #id: cid subject
        #   - new: #id: cid author date subject
        # We can detect the 2nd one as the date starts with a series of digits
        # followed by "-" then an upper case letter (eg: "18-Dec23").
        set -- $id
        cid="$1"
        author=""
        date=""
        if [ -n "$3" ] && [ -z "${3##[1-9]-[A-Z]*}" -o -z "${3##[0-3][0-9]-[A-Z]*}" ]; then
            author="$2"
            date="$3"
            subj="${id#$cid $author $date }"
        else
            subj="${id#$cid }"
        fi

        if [ -z "$cid" ]; then
            echo "ERROR: commit ID not found in patch $pnum: $patch" >&2
            continue
        fi

        echo "<script type='text/javascript'>cid[$seq_num]='$cid'; bkp[$seq_num]=${bkp[$cid]:+1}+0;</script>"

        echo -n "<TR id='tr_$seq_num' name='$cid'"

        # highlight unqualified docs and bugs
        if [ "$verdict" != "no" ]; then
                : # no special treatment for accepted/uncertain elements
        elif [ -z "${subj##BUG*}" ] && ! [[ "${respl}" =~ (explicitly|specifically|clearly|also|commit\ message|does)[\ ]*(state|mention|say|request) ]]; then
                # bold for BUG marked "no" with no "explicitly states that ..."
                echo -n " style='font-weight:bold'"
        elif [ -z "${subj##DOC*}" ]; then # && ! [[ "${respl}" =~ (explicitly|specifically|clearly|also|commit\ message|does)[\ ]*(state|mention|say|request) ]]; then
                # gray for DOC marked "no"
                echo -n " style='font-weight:bold'"
                #echo -n " bgcolor=#E0E0E0" #"$BG_U"
        fi

        echo -n ">"

        # HTMLify subject and summary
        subj="${subj//&/&amp;}"; subj="${subj//</&lt;}"; subj="${subj//>/&gt;}";
        resp="${resp//&/&amp;}"; resp="${resp//</&lt;}"; resp="${resp//>/&gt;}";

        # turn "#XXXX" to a link to an issue
        resp=$(echo "$resp" | sed -e "s|#\([0-9]\{1,5\}\)|<a href='${ISSUES}\1'>#\1</a>|g")

        # put links to commit IDs
        resp=$(echo "$resp" | sed -e "s|\([0-9a-f]\{8,40\}\)|<a href='${GITURL}\1'>\1</a>|g")

        echo -n "<TD nowrap align=center ${bkp[$cid]:+style='background-color:${BG_B}'}>$seq_num<BR/>"
        echo -n "<input type='radio' name='review' onclick='updt($seq_num,\"r\");' ${do_check:+checked} title='Start review here'/></TD>"
        echo -n "<TD nowrap ${bkp[$cid]:+style='background-color:${BG_B}'}><tt><a href='${GITURL}${cid}'>$cid</a></tt>${date:+<br/><small style='font-weight:normal'>$date</small>}</TD>"
        echo -n "<TD nowrap><a href='${GITURL}${cid}'>${pnum:+$pnum }$subj</a>${author:+<br/><div align=right><small style='font-weight:normal'>$author</small></div>}</TD>"
        echo -n "<TD nowrap align=center>"
        echo -n "<input type='radio' onclick='updt($seq_num,\"n\");' id='bt_${seq_num}_n' class='n' name='$cid' value='n' title='Drop' $(         [ "$verdict" != no ]     || echo -n checked) />"
        echo -n "<input type='radio' onclick='updt($seq_num,\"u\");' id='bt_${seq_num}_u' class='u' name='$cid' value='u' title='Uncertain' $(    [ "$verdict" != uncertain ] || echo -n checked) />"
        echo -n "<input type='radio' onclick='updt($seq_num,\"w\");' id='bt_${seq_num}_w' class='w' name='$cid' value='w' title='wait in -next' $([ "$verdict" != wait ]   || echo -n checked) />"
        echo -n "<input type='radio' onclick='updt($seq_num,\"y\");' id='bt_${seq_num}_y' class='y' name='$cid' value='y' title='Pick' $(         [ "$verdict" != yes ]    || echo -n checked) />"
        echo -n "</TD>"
        echo -n "<TD>$resp</TD>"
        echo "</TR>"
        echo
        ((seq_num++))

        # if this patch was already backported, make the review start on the next
        if [ -n "${bkp[$cid]}" ]; then
            review=$seq_num
            do_check=1
        else
            do_check=
        fi
done

echo "<TR><TH>New<br/><input type='radio' name='review' onclick='updt($seq_num,\"r\");' ${do_check:+checked} title='Nothing to backport'/></TH><TH>CID</TH><TH>Subject</TH><TH>Verdict<BR>N U W Y</BR></TH><TH>Reason</TH></TR>"

echo "</TABLE>"
echo "<P/>"
echo "<H3>Output:</H3>"
echo "<textarea cols=120 rows=10 id='output'></textarea>"
echo "<P/>"
echo "<script type='text/javascript'>nb_patches=$seq_num; review=$review; updt_table(0); updt_output();</script>"
echo "</BODY></HTML>"