Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix #191 - remove common attributes when not in PR title #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions source/dlangbot/github.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ void searchForAutoMergePrs(string repoSlug)
}

/**
Allows contributors to use [<label>] messages in the title.
If they are part of a pre-defined, allowed list, the bot will add the
respective label.
Allows contributors to use [<label>] and [-<label>] messages in the title.
If they are part of a pre-defined, allowed list, the bot will add or
remove the respective label.
*/
void checkTitleForLabels(in ref PullRequest pr)
{
Expand All @@ -334,10 +334,16 @@ void checkTitleForLabels(in ref PullRequest pr)

static labelRe = regex(`\[(.*)\]`);
string[] userLabels;
string[] removeLabels;
foreach (m; pr.title.matchAll(labelRe))
{
foreach (el; m[1].splitter(","))
userLabels ~= el;
{
if (el.length > 0 && el[0] == '-')
removeLabels ~= el[1 .. $];
else
userLabels ~= el;
}
}

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

if (mappedLabels.length)
pr.addLabels(mappedLabels);

auto mappedRemoveLabels = removeLabels
.sort()
.uniq
.map!strip
.map!toLower
.filter!(l => l in userLabelsMap)
.map!(l => userLabelsMap[l])
.array;

if (mappedRemoveLabels.length)
checkAndRemoveLabels(pr.labels, pr, mappedRemoveLabels);

}