Skip to content

Commit 298339a

Browse files
committed
Show warning when a critical PR isn't based against stable
1 parent 261e594 commit 298339a

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed

source/dlangbot/app.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void handlePR(string action, PullRequest* _pr)
209209
UserMessage[] msgs;
210210
if (action == "opened" || action == "synchronize")
211211
{
212-
//msgs = pr.checkForWarnings;
212+
msgs = pr.checkForWarnings(descs);
213213
}
214214

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

source/dlangbot/bugzilla.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ struct Issue
5151
{
5252
int id;
5353
string desc;
54-
string bug_status;
54+
string status;
5555
string resolution;
56-
string bug_severity;
56+
string severity;
5757
string priority;
5858
}
5959

source/dlangbot/github.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ string formatComment(R1, R2)(R1 refs, R2 descs, UserMessage[] msgs)
4848
}
4949
if (msgs.length)
5050
{
51-
app ~= "### Warnings \n\n";
51+
if (refs.length)
52+
app ~= "\n";
53+
app ~= "### Warnings\n\n";
5254
app.printMessages(msgs);
5355
}
5456
return app.data;
@@ -137,6 +139,7 @@ void updateGithubComment(in ref PullRequest pr, in ref GHComment comment,
137139
// Github Auto-merge
138140
//==============================================================================
139141

142+
string ref_;
140143
alias LabelsAndCommits = Tuple!(Json[], "labels", Json[], "commits");
141144
enum MergeMethod { none = 0, merge, squash, rebase }
142145

@@ -432,6 +435,7 @@ struct PullRequest
432435
static struct Branch
433436
{
434437
string sha;
438+
string ref_;
435439
Repo repo;
436440
}
437441
Branch base, head;

source/dlangbot/warnings.d

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
module dlangbot.warnings;
22

3+
import dlangbot.bugzilla : Issue;
34
import dlangbot.github : PullRequest;
45

6+
import std.algorithm;
7+
58
struct UserMessage
69
{
710
enum Type { Error, Warning, Info }
11+
Type type;
812

913
string text;
1014
}
@@ -21,24 +25,35 @@ Check bugzilla priority
2125
- enhancement -> changelog entry
2226
- regression/major -> stable
2327
*/
24-
void checkBugzilla(in ref PullRequest pr, UserMessage[] msgs)
28+
void checkBugzilla(in ref PullRequest pr, ref UserMessage[] msgs, in Issue[] bugzillaIssues)
2529
{
30+
// check for stable
31+
if (pr.base.ref_ != "stable")
32+
{
33+
if (bugzillaIssues.any!(i => i.status.among("NEW", "ASSIGNED") &&
34+
i.severity.among("critical", "major",
35+
"blocker", "regression")))
36+
{
37+
msgs ~= UserMessage(UserMessage.Type.Warning,
38+
"Regression fixes should always target stable");
39+
}
40+
}
2641
}
2742

2843

29-
UserMessage[] checkForWarnings(in PullRequest pr)
44+
UserMessage[] checkForWarnings(in PullRequest pr, in Issue[] bugzillaIssues)
3045
{
3146
UserMessage[] msgs;
3247
pr.checkDiff(msgs);
33-
pr.checkBugzilla(msgs);
48+
pr.checkBugzilla(msgs, bugzillaIssues);
3449
return msgs;
3550
}
3651

3752
void printMessages(W)(W app, UserMessage[] msgs)
3853
{
3954
foreach (msg; msgs)
4055
{
41-
app ~= " - ";
56+
app ~= "- ";
4257
app ~= msg.text;
4358
app ~= "\n";
4459
}

test/comments.d

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,45 @@ unittest
113113

114114
postGitHubHook("dlang_phobos_merged_4963.json");
115115
}
116+
117+
// critical bug fix (not in stable) -> show warning to target stable
118+
unittest
119+
{
120+
setAPIExpectations(
121+
"/github/repos/dlang/phobos/pulls/4921/commits",
122+
"/github/repos/dlang/phobos/issues/4921/labels",
123+
"/github/repos/dlang/phobos/issues/4921/comments", (ref Json j) {
124+
j = Json.emptyArray;
125+
},
126+
"/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority",
127+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
128+
res.writeBody(
129+
`bug_id,"short_desc","bug_status","resolution","bug_severity","priority"
130+
8573,"A simpler Phobos function that returns the index of the mix or max item","NEW","---","regression","P2"`);
131+
},
132+
// no bug fix label, since Issues are only referenced but not fixed according to commit messages
133+
"/github/repos/dlang/phobos/issues/4921/comments",
134+
(scope HTTPServerRequest req, scope HTTPServerResponse res){
135+
import std.stdio;
136+
assert(req.method == HTTPMethod.POST);
137+
writeln(req.json["body"]);
138+
auto expectedComment =
139+
`### Bugzilla references
140+
141+
Fix | Bugzilla | Description
142+
--- | --- | ---
143+
✗ | [8573](%s/show_bug.cgi?id=8573) | A simpler Phobos function that returns the index of the mix or max item
144+
145+
### Warnings
146+
147+
- Regression fixes should always target stable
148+
`.format(bugzillaURL);
149+
writeln(expectedComment);
150+
assert(req.json["body"].get!string == expectedComment);
151+
res.writeVoidBody;
152+
},
153+
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
154+
);
155+
156+
postGitHubHook("dlang_phobos_synchronize_4921.json");
157+
}

0 commit comments

Comments
 (0)