@@ -322,9 +322,9 @@ void searchForAutoMergePrs(string repoSlug)
322
322
}
323
323
324
324
/**
325
- Allows contributors to use [<label>] messages in the title.
326
- If they are part of a pre-defined, allowed list, the bot will add the
327
- respective label.
325
+ Allows contributors to use [<label>] and [-<label>] messages in the title.
326
+ If they are part of a pre-defined, allowed list, the bot will add or
327
+ remove the respective label.
328
328
*/
329
329
void checkTitleForLabels (in ref PullRequest pr)
330
330
{
@@ -334,10 +334,16 @@ void checkTitleForLabels(in ref PullRequest pr)
334
334
335
335
static labelRe = regex(` \[(.*)\]` );
336
336
string [] userLabels;
337
+ string [] removeLabels;
337
338
foreach (m; pr.title.matchAll(labelRe))
338
339
{
339
340
foreach (el; m[1 ].splitter(" ," ))
340
- userLabels ~= el;
341
+ {
342
+ if (el.length > 0 && el[0 ] == ' -' )
343
+ removeLabels ~= el[1 .. $];
344
+ else
345
+ userLabels ~= el;
346
+ }
341
347
}
342
348
343
349
const string [string ] userLabelsMap = [
@@ -356,4 +362,17 @@ void checkTitleForLabels(in ref PullRequest pr)
356
362
357
363
if (mappedLabels.length)
358
364
pr.addLabels(mappedLabels);
365
+
366
+ auto mappedRemoveLabels = removeLabels
367
+ .sort()
368
+ .uniq
369
+ .map! strip
370
+ .map! toLower
371
+ .filter! (l => l in userLabelsMap)
372
+ .map! (l => userLabelsMap[l])
373
+ .array;
374
+
375
+ if (mappedRemoveLabels.length)
376
+ checkAndRemoveLabels(pr.labels, pr, mappedRemoveLabels);
377
+
359
378
}
0 commit comments