Skip to content

Commit

Permalink
dlangbot.warnings: Warn when fixing enhancements without changelog
Browse files Browse the repository at this point in the history
Fixes dlang#178.
  • Loading branch information
CyberShadow committed May 27, 2021
1 parent e03480e commit 3946807
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
Empty file.
22 changes: 22 additions & 0 deletions source/dlangbot/warnings.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ struct UserMessage
}


void checkEnhancementChangelog(in ref PullRequest pr, ref UserMessage[] msgs,
in Issue[] bugzillaIssues, in IssueRef[] refs)
{
import dlangbot.utils : request, expectOK;
import vibe.stream.operations : readAllUTF8;

if (bugzillaIssues.any!(i => i.status.among("NEW", "ASSIGNED", "REOPENED") &&
i.severity == "enhancement" &&
refs.canFind!(r => r.id == i.id && r.fixed)))
{
auto diff = request(pr.diffURL).expectOK.bodyReader.readAllUTF8;
if (!diff.canFind("\n+++ b/changelog/"))
{
msgs ~= UserMessage(UserMessage.Type.Warning,
"Pull requests implementing enhancements should include a [full changelog entry](https://github.com/dlang/dmd/tree/master/changelog)."
);
}
}
}


/**
Check bugzilla priority
- enhancement -> changelog entry
Expand Down Expand Up @@ -50,6 +71,7 @@ UserMessage[] checkForWarnings(in PullRequest pr, in Issue[] bugzillaIssues, in
{
UserMessage[] msgs;
pr.checkBugzilla(msgs, bugzillaIssues, refs);
pr.checkEnhancementChangelog(msgs, bugzillaIssues, refs);
return msgs;
}

Expand Down
89 changes: 89 additions & 0 deletions test/comments.d
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ unittest
8573,"A simpler Phobos function that returns the index of the mix or max item","NEW","---","enhancement","P2",`);
},
"/github/repos/dlang/phobos/issues/4921/labels",
"/github.com/dlang/phobos/pull/4921.diff",
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
j = Json.emptyArray;
},
Expand Down Expand Up @@ -169,6 +170,7 @@ unittest
8574,"Some Bug","NEW","---","normal","P2",`);
},
"/github/repos/dlang/phobos/issues/4921/labels",
"/github.com/dlang/phobos/pull/4921.diff",
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
j = Json.emptyArray;
},
Expand Down Expand Up @@ -200,6 +202,7 @@ unittest
"/github/repos/dlang/phobos/issues/4921/comments",
"/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords",
"/github/repos/dlang/phobos/issues/4921/labels",
"/github.com/dlang/phobos/pull/4921.diff",
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
j[0]["name"] = "Enhancement";
},
Expand Down Expand Up @@ -558,3 +561,89 @@ unittest
assert("a\\b".markdownEscape == "a\\\\b");
assert("a+b".markdownEscape == r"a\+b");
}

@("enhancement-with-changelog")
unittest
{
setAPIExpectations(
"/github/repos/dlang/phobos/pulls/4921/commits", (ref Json j) {
j[0]["commit"]["message"] = "Fix Issue 8573";
},
"/github/repos/dlang/phobos/issues/4921/comments",
"/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
res.writeBody(
`bug_id,"short_desc","bug_status","resolution","bug_severity","priority","keywords"
8573,"A simpler Phobos function that returns the index of the mix or max item","NEW","---","enhancement","P2",`);
},
"/github/repos/dlang/phobos/issues/4921/labels",
"/github.com/dlang/phobos/pull/4921.diff", (scope HTTPServerRequest req, scope HTTPServerResponse res){
res.writeBody(q"EOF
diff --git a/changelog/bla-bla.dd b/changelog/bla-bla.dd
new file mode 100644
index 00000000000..0147f501f08
--- /dev/null
+++ b/changelog/bla-bla.dd
@@ -0,0 +1,1 @@
+bla bla
EOF");
},
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
j = Json.emptyArray;
},
"/github/orgs/dlang/public_members?per_page=100",
"/github/repos/dlang/phobos/issues/comments/262784442",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
assert(req.method == HTTPMethod.PATCH);
assert(!req.json["body"].get!string.canFind("Pull requests implementing enhancements should include"));
res.writeVoidBody;
},
"/github/repos/dlang/phobos/issues/4921/labels",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
assert(req.json[].equal(["Enhancement"]));
},
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
"/bugzilla/jsonrpc.cgi", // Bug.comments
"/bugzilla/jsonrpc.cgi", // Bug.update
);

postGitHubHook("dlang_phobos_synchronize_4921.json");
}

@("enhancement-with-changelog")
unittest
{
setAPIExpectations(
"/github/repos/dlang/phobos/pulls/4921/commits", (ref Json j) {
j[0]["commit"]["message"] = "Fix Issue 8573";
},
"/github/repos/dlang/phobos/issues/4921/comments",
"/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
res.writeBody(
`bug_id,"short_desc","bug_status","resolution","bug_severity","priority","keywords"
8573,"A simpler Phobos function that returns the index of the mix or max item","NEW","---","enhancement","P2",`);
},
"/github/repos/dlang/phobos/issues/4921/labels",
"/github.com/dlang/phobos/pull/4921.diff",
"/github/repos/dlang/phobos/issues/4921/labels", (ref Json j) {
j = Json.emptyArray;
},
"/github/orgs/dlang/public_members?per_page=100",
"/github/repos/dlang/phobos/issues/comments/262784442",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
assert(req.method == HTTPMethod.PATCH);
assert(req.json["body"].get!string.canFind("Pull requests implementing enhancements should include"));
res.writeVoidBody;
},
"/github/repos/dlang/phobos/issues/4921/labels",
(scope HTTPServerRequest req, scope HTTPServerResponse res){
assert(req.json[].equal(["Enhancement"]));
},
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
"/bugzilla/jsonrpc.cgi", // Bug.comments
"/bugzilla/jsonrpc.cgi", // Bug.update
);

postGitHubHook("dlang_phobos_synchronize_4921.json");
}

0 comments on commit 3946807

Please sign in to comment.