forked from postgres/pgcommitfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitfest.js
382 lines (357 loc) · 12.3 KB
/
commitfest.js
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
373
374
375
376
377
378
379
380
381
382
function verify_reject() {
return confirm(
'Are you sure you want to close this patch as Rejected?\n\nThis should only be done when a patch will never be applied - if more work is needed, it should instead be set to "Returned with Feedback" or "Moved to next CF".\n\nSo - are you sure?',
);
}
function verify_withdrawn() {
return confirm(
"Are you sure you want to close this patch as Withdrawn?\n\nThis should only be done when the author voluntarily withdraws the patch.\n\nSo - are you sure?",
);
}
function verify_returned() {
return confirm(
'Are you sure you want to close this patch as Returned with Feedback?\n\nThis should be done if the patch is expected to be finished at some future time, but not necessarily in the next commitfest. If work is undergoing and expected in the next commitfest, it should instead be set to "Moved to next CF".\n\nSo - are you sure?',
);
}
function verify_next() {
return confirm(
'Are you sure you want to move this patch to the next commitfest?\n\nThis means the patch will be marked as closed in this commitfest, but will automatically be moved to the next one. If no further work is expected on this patch, it should be closed with "Rejected" or "Returned with Feedback" instead.\n\nSo - are you sure?',
);
}
function findLatestThreads() {
$("#attachThreadListWrap").addClass("loading");
$("#attachThreadSearchButton").addClass("disabled");
$.get("/ajax/getThreads/", {
s: $("#attachThreadSearchField").val(),
a: $("#attachThreadAttachOnly").val(),
})
.success((data) => {
sel = $("#attachThreadList");
sel.find("option").remove();
$.each(data, (m, i) => {
sel.append(
$("<option/>")
.text(`${i.from}: ${i.subj} (${i.date})`)
.data("subject", i.subj)
.val(i.msgid),
);
});
})
.always(() => {
$("#attachThreadListWrap").removeClass("loading");
$("#attachThreadSearchButton").removeClass("disabled");
attachThreadChanged();
});
return false;
}
function browseThreads(attachfunc, closefunc) {
$("#attachThreadList").find("option").remove();
$("#attachThreadMessageId").val("");
$("#attachModal").off("hidden.bs.modal");
$("#attachModal").on("hidden.bs.modal", (e) => {
if (closefunc) closefunc();
});
$("#attachModal").modal();
findLatestThreads();
$("#doAttachThreadButton").unbind("click");
$("#doAttachThreadButton").click(() => {
msgid = $("#attachThreadMessageId").val();
if (!msgid || msgid === "") {
msgid = $("#attachThreadList").val();
if (!msgid) return;
subject = $("#attachThreadList option:selected").data("subject");
subject = subject.replace(/\bre: /gi, "");
subject = subject.replace(/\bfwd: /gi, "");
// Strips [PATCH], [POC], etc. prefixes
subject = subject.replace(/\[\w+\]: /gi, "");
subject = subject.replace(/\[\w+\] /gi, "");
}
$("#attachThreadListWrap").addClass("loading");
$("#attachThreadSearchButton").addClass("disabled");
$("#attachThreadButton").addClass("disabled");
if (attachfunc(msgid, subject)) {
$("#attachModal").modal("hide");
}
$("#attachThreadListWrap").removeClass("loading");
$("#attachThreadSearchButton").removeClass("disabled");
attachThreadChanged();
});
}
function attachThread(cfid, patchid, closefunc) {
browseThreads(
(msgid) => {
doAttachThread(cfid, patchid, msgid, !closefunc);
if (closefunc) {
/* We don't really care about closing it, we just reload immediately */
closefunc();
}
},
() => {
if (closefunc) closefunc();
},
);
}
function detachThread(cfid, patchid, msgid) {
if (
confirm(
`Are you sure you want to detach the thread with messageid "${msgid}" from this patch?`,
)
) {
$.post("/ajax/detachThread/", {
cf: cfid,
p: patchid,
msg: msgid,
})
.success((data) => {
location.reload();
})
.fail((data) => {
alert("Failed to detach thread!");
});
}
}
function attachThreadChanged() {
if ($("#attachThreadList").val() || $("#attachThreadMessageId").val()) {
$("#doAttachThreadButton").removeClass("disabled");
} else {
$("#doAttachThreadButton").addClass("disabled");
}
}
function doAttachThread(cfid, patchid, msgid, reloadonsuccess) {
$.post("/ajax/attachThread/", {
cf: cfid,
p: patchid,
msg: msgid,
})
.success((data) => {
if (data !== "OK") {
alert(data);
}
if (reloadonsuccess) location.reload();
return true;
})
.fail((data) => {
if (data.status === 404) {
alert(`Message with messageid ${msgid} not found`);
} else if (data.status === 503) {
alert(`Failed to attach thread: ${data.responseText}`);
} else {
alert(`Failed to attach thread: ${data.statusText}`);
}
return false;
});
}
function updateAnnotationMessages(threadid) {
$("#annotateMessageBody").addClass("loading");
$("#doAnnotateMessageButton").addClass("disabled");
$.get("/ajax/getMessages", {
t: threadid,
})
.success((data) => {
sel = $("#annotateMessageList");
sel.find("option").remove();
sel.append('<option value="">---</option>');
$.each(data, (i, m) => {
sel.append(
`<option value="${m.msgid}">${m.from}: ${m.subj} (${m.date})</option>`,
);
});
})
.always(() => {
$("#annotateMessageBody").removeClass("loading");
});
}
function addAnnotation(threadid) {
$("#annotateThreadList").find("option").remove();
$("#annotateMessage").val("");
$("#annotateMsgId").val("");
$("#annotateModal").modal();
$("#annotateThreadList").focus();
updateAnnotationMessages(threadid);
$("#doAnnotateMessageButton").unbind("click");
$("#doAnnotateMessageButton").click(() => {
const msg = $("#annotateMessage").val();
if (msg.length >= 500) {
alert(
"Maximum length for an annotation is 500 characters.\nYou should probably post an actual message in the thread!",
);
return;
}
$("#doAnnotateMessageButton").addClass("disabled");
$("#annotateMessageBody").addClass("loading");
$.post("/ajax/annotateMessage/", {
t: threadid,
msgid: $.trim($("#annotateMsgId").val()),
msg: msg,
})
.success((data) => {
if (data !== "OK") {
alert(data);
$("#annotateMessageBody").removeClass("loading");
} else {
$("#annotateModal").modal("hide");
location.reload();
}
})
.fail((data) => {
alert("Failed to annotate message");
$("#annotateMessageBody").removeClass("loading");
});
});
}
function annotateMsgPicked() {
const val = $("#annotateMessageList").val();
if (val) {
$("#annotateMsgId").val(val);
annotateChanged();
}
}
function annotateChanged() {
/* Enable/disable the annotate button */
if ($("#annotateMessage").val() !== "" && $("#annotateMsgId").val()) {
$("#doAnnotateMessageButton").removeClass("disabled");
} else {
$("#doAnnotateMessageButton").addClass("disabled");
}
}
function deleteAnnotation(annid) {
if (confirm("Are you sure you want to delete this annotation?")) {
$.post("/ajax/deleteAnnotation/", {
id: annid,
})
.success((data) => {
location.reload();
})
.fail((data) => {
alert("Failed to delete annotation!");
});
}
}
function flagCommitted(committer) {
$("#commitModal").modal();
$("#committerSelect").val(committer);
$("#doCommitButton").unbind("click");
$("#doCommitButton").click(() => {
const c = $("#committerSelect").val();
if (!c) {
alert(
"You need to select a committer before you can mark a patch as committed!",
);
return;
}
document.location.href = `close/committed/?c=${c}`;
});
return false;
}
function sortpatches(sortby) {
const sortkey = $("#id_sortkey").val();
if (sortkey === sortby) {
$("#id_sortkey").val(-sortby);
} else if (-sortkey === sortby) {
$("#id_sortkey").val(0);
} else {
$("#id_sortkey").val(sortby);
}
$("#filterform").submit();
return false;
}
function toggleButtonCollapse(buttonId, collapseId) {
$(`#${buttonId}`).button("toggle");
$(`#${collapseId}`).toggleClass("in");
}
function togglePatchFilterButton(buttonId, collapseId) {
/* Figure out if we are collapsing it */
if ($(`#${collapseId}`).hasClass("in")) {
/* Go back to ourselves without a querystring to reset the form, unless it's already empty */
if (document.location.href.indexOf("?") > -1) {
document.location.href = ".";
return;
}
}
toggleButtonCollapse(buttonId, collapseId);
}
/*
* Upstream user search dialog
*/
function search_and_store_user() {
$("#doSelectUserButton").unbind("click");
$("#doSelectUserButton").click(() => {
if (!$("#searchUserList").val()) {
return false;
}
/* Create this user locally */
$.get("/ajax/importUser/", {
u: $("#searchUserList").val(),
})
.success((data) => {
if (data === "OK") {
alert("User imported!");
$("#searchUserModal").modal("hide");
} else {
alert(`Failed to import user: ${data}`);
}
})
.fail((data, statustxt) => {
alert(`Failed to import user: ${statustxt}`);
});
return false;
});
$("#searchUserModal").modal();
}
function findUsers() {
if (!$("#searchUserSearchField").val()) {
alert("No search term specified");
return false;
}
$("#searchUserListWrap").addClass("loading");
$("#searchUserSearchButton").addClass("disabled");
$.get("/ajax/searchUsers/", {
s: $("#searchUserSearchField").val(),
})
.success((data) => {
sel = $("#searchUserList");
sel.find("option").remove();
$.each(data, (i, u) => {
sel.append(
`<option value="${u.u}">${u.u} (${u.f} ${u.l})</option>`,
);
});
})
.always(() => {
$("#searchUserListWrap").removeClass("loading");
$("#searchUserSearchButton").removeClass("disabled");
searchUserListChanged();
});
return false;
}
function searchUserListChanged() {
if ($("#searchUserList").val()) {
$("#doSelectUserButton").removeClass("disabled");
} else {
$("#doSelectUserButton").addClass("disabled");
}
}
function addGitCheckoutToClipboard(patchId) {
navigator.clipboard.writeText(`git remote add commitfest https://github.com/postgresql-cfbot/postgresql.git
git fetch commitfest cf/${patchId}
git checkout commitfest/cf/${patchId}
`);
}
/* Build our button callbacks */
$(document).ready(() => {
$("button.attachThreadButton").each((i, o) => {
const b = $(o);
b.click(() => {
$("#attachThreadAttachOnly").val("1");
browseThreads((msgid, subject) => {
b.prev().val(msgid);
const description_field = $("#id_name");
if (description_field.val() === "") {
description_field.val(subject);
}
return true;
});
return false;
});
});
});