@@ -237,7 +237,7 @@ void checkAndRemoveLabels(Json[] labels, in ref PullRequest pr, in string[] toRe
237237 .each! (l => pr.removeLabel(l));
238238}
239239
240- void addLabels (in ref PullRequest pr, string [] labels)
240+ void addLabels (in ref PullRequest pr, inout string [] labels)
241241{
242242 auto labelUrl = " %s/repos/%s/issues/%d/labels"
243243 .format(githubAPIURL, pr.repoSlug, pr.number);
@@ -286,4 +286,39 @@ void searchForAutoMergePrs(string repoSlug)
286286 }
287287}
288288
289+ /**
290+ Allows contributors to use [<label>] messages in the title.
291+ If they are part of a pre-defined, allowed list, the bot will add the
292+ respective label.
293+ */
294+ void checkTitleForLabels (in ref PullRequest pr)
295+ {
296+ import std.algorithm.iteration : splitter;
297+ import std.regex ;
298+ import std.string : strip, toLower;
299+
300+ static labelRe = regex(` \[(.*)\]` );
301+ string [] userLabels;
302+ foreach (m; pr.title.matchAll(labelRe))
303+ {
304+ foreach (el; m[1 ].splitter(" ," ))
305+ userLabels ~= el;
306+ }
289307
308+ const string [string ] userLabelsMap = [
309+ " trivial" : " trivial" ,
310+ " wip" : " WIP"
311+ ];
312+
313+ auto mappedLabels = userLabels
314+ .sort()
315+ .uniq
316+ .map! strip
317+ .map! toLower
318+ .filter! (l => l in userLabelsMap)
319+ .map! (l => userLabelsMap[l])
320+ .array;
321+
322+ if (mappedLabels.length)
323+ pr.addLabels(mappedLabels);
324+ }
0 commit comments