Skip to content

Commit 1fdf0a5

Browse files
committed
Fix #191 - remove common attributes when not in PR title
1 parent 10ce8a1 commit 1fdf0a5

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

source/dlangbot/github.d

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ void searchForAutoMergePrs(string repoSlug)
322322
}
323323

324324
/**
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.
328328
*/
329329
void checkTitleForLabels(in ref PullRequest pr)
330330
{
@@ -334,10 +334,16 @@ void checkTitleForLabels(in ref PullRequest pr)
334334

335335
static labelRe = regex(`\[(.*)\]`);
336336
string[] userLabels;
337+
string[] removeLabels;
337338
foreach (m; pr.title.matchAll(labelRe))
338339
{
339340
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+
}
341347
}
342348

343349
const string[string] userLabelsMap = [
@@ -356,4 +362,17 @@ void checkTitleForLabels(in ref PullRequest pr)
356362

357363
if (mappedLabels.length)
358364
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+
359378
}

0 commit comments

Comments
 (0)