Skip to content

Commit c547fb8

Browse files
wilzbachPetarKirov
authored andcommitted
Fix #65 - the Dlang-Bot should use the 'Enhancement' label (#84)
1 parent 23c83a3 commit c547fb8

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

source/dlangbot/app.d

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,23 @@ void handlePR(string action, PullRequest* _pr)
185185

186186
pr.updateGithubComment(comment, action, refs, descs, msgs);
187187

188-
if (refs.any!(r => r.fixed) && comment.body_.length == 0)
188+
if (refs.any!(r => r.fixed))
189189
{
190-
logDebug("[github/handlePR](%s): adding bug fix label", _pr.pid);
191-
pr.addLabels(["Bug fix"]);
190+
import std.algorithm : canFind, filter, map, sort, uniq;
191+
import std.array : array;
192+
// references are already sorted by id
193+
auto bugzillaIds = refs.map!(r => r.id).uniq;
194+
auto bugzillSeverities = descs
195+
.filter!(d => bugzillaIds.canFind(d.id))
196+
.map!(i => i.severity);
197+
logDebug("[github/handlePR](%s): trying to add bug fix label", _pr.pid);
198+
string[] labels;
199+
if (bugzillSeverities.canFind("enhancement"))
200+
labels ~= "Enhancement";
201+
else
202+
labels ~= "Bug fix";
203+
204+
pr.addLabels(labels);
192205
}
193206

194207
if (runTrello)

test/comments.d

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,39 @@ unittest
112112
postGitHubHook("dlang_phobos_synchronize_4921.json");
113113
}
114114

115+
// existing dlang bot comment + enhancement bugzilla labels
116+
// -> test that we add an enhancement label (not bug fix)
117+
unittest
118+
{
119+
setAPIExpectations(
120+
"/github/repos/dlang/phobos/pulls/4921/commits", (ref Json j) {
121+
j[0]["commit"]["message"] = "Fix Issue 8573";
122+
},
123+
"/github/repos/dlang/phobos/issues/4921/comments",
124+
"/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority",
125+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
126+
res.writeBody(
127+
`bug_id,"short_desc","bug_status","resolution","bug_severity","priority"
128+
8573,"A simpler Phobos function that returns the index of the mix or max item","NEW","---","enhancement","P2"`);
129+
},
130+
"/github/repos/dlang/phobos/issues/4921/labels",
131+
"/github/orgs/dlang/public_members",
132+
"/github/repos/dlang/phobos/issues/comments/262784442",
133+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
134+
assert(req.method == HTTPMethod.PATCH);
135+
auto body_= req.json["body"].get!string;
136+
assert(body_.canFind("@andralex"));
137+
},
138+
"/github/repos/dlang/phobos/issues/4921/labels",
139+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
140+
assert(req.json[].equal(["Enhancement"]));
141+
},
142+
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
143+
);
144+
145+
postGitHubHook("dlang_phobos_synchronize_4921.json");
146+
}
147+
115148
// existing dlang bot comment -> update comment
116149
// auto-merge label -> remove (due to synchronization)
117150
unittest
@@ -170,9 +203,7 @@ unittest
170203
// no bug fix label, since Issues are only referenced but not fixed according to commit messages
171204
"/github/repos/dlang/phobos/issues/4921/comments",
172205
(scope HTTPServerRequest req, scope HTTPServerResponse res){
173-
import std.stdio;
174206
assert(req.method == HTTPMethod.POST);
175-
writeln(req.json["body"]);
176207
auto expectedComment =
177208
`### Bugzilla references
178209
@@ -184,7 +215,6 @@ Fix | Bugzilla | Description
184215
185216
- Regression fixes should always target stable
186217
`.format(bugzillaURL);
187-
writeln(expectedComment);
188218
assert(req.json["body"].get!string.canFind(expectedComment));
189219
res.writeVoidBody;
190220
},

0 commit comments

Comments
 (0)