Skip to content

Commit d85dafe

Browse files
authored
Merge pull request #157 from wilzbach/sicmp-check-remove
Use sicmp for checkAndRemoveLabels merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
2 parents 8f896d1 + 2495a82 commit d85dafe

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

source/dlangbot/github.d

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ Json[] tryMerge(in ref PullRequest pr, GHMerge.MergeMethod method)
197197

198198
void checkAndRemoveLabels(GHLabel[] labels, in ref PullRequest pr, in string[] toRemoveLabels)
199199
{
200-
import std.uni : toLower;
200+
import std.uni : sicmp;
201201
labels
202-
.map!(l => l.name.toLower)
203-
.filter!(n => toRemoveLabels.canFind(n))
202+
.map!(l => l.name)
203+
.filter!(n => toRemoveLabels.canFind!((a, b) => sicmp(a,b) == 0)(n))
204204
.each!(l => pr.removeLabel(l));
205205
}
206206

@@ -222,7 +222,8 @@ void addLabels(in ref PullRequest pr, in string[] newLabels)
222222

223223
void removeLabel(in ref PullRequest pr, string label)
224224
{
225-
ghSendRequest(HTTPMethod.DELETE, pr.labelsURL ~ "/" ~ label);
225+
import std.uri : encodeComponent;
226+
ghSendRequest(HTTPMethod.DELETE, pr.labelsURL ~ "/" ~ label.encodeComponent);
226227
}
227228

228229
void replaceLabels(in ref PullRequest pr, string[] labels)

test/comments.d

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,36 @@ unittest
410410

411411
postGitHubHook("dlang_phobos_synchronize_4921.json");
412412
}
413+
414+
// Remove old labels on push
415+
unittest
416+
{
417+
import std.array : replace;
418+
foreach (label; ["needs work", "Needs work", "stalled"])
419+
{
420+
setAPIExpectations(
421+
"/github/repos/dlang/phobos/pulls/4921/commits", (ref Json j) {
422+
j = Json.emptyArray;
423+
},
424+
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
425+
j[0]["name"] = label;
426+
},
427+
// encodeComponent is avoided on purpose
428+
"/github/repos/dlang/phobos/issues/4921/labels/" ~ label.replace(" ", "%20"),
429+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
430+
assert(req.method == HTTPMethod.DELETE);
431+
},
432+
"/github/repos/dlang/phobos/issues/4921/comments",
433+
"/github/orgs/dlang/public_members?per_page=100",
434+
"/github/repos/dlang/phobos/issues/comments/262784442",
435+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
436+
assert(req.method == HTTPMethod.PATCH);
437+
auto body_ = req.json["body"].get!string;
438+
assert(body_.canFind("@andralex"));
439+
assert(!body_.canFind("Auto-close | Bugzilla"), "Shouldn't contain bug header");
440+
assert(!body_.canFind("/show_bug.cgi?id="), "Shouldn't contain a Bugzilla reference");
441+
}
442+
);
443+
postGitHubHook("dlang_phobos_synchronize_4921.json");
444+
}
445+
}

0 commit comments

Comments
 (0)