diff --git a/source/dlangbot/bugzilla.d b/source/dlangbot/bugzilla.d index bee2e14..1c81401 100644 --- a/source/dlangbot/bugzilla.d +++ b/source/dlangbot/bugzilla.d @@ -6,8 +6,7 @@ import vibe.inet.webform : urlEncode; shared string bugzillaURL = "https://issues.dlang.org"; // D projects which use Bugzilla for bug tracking. -static immutable bugzillaProjectSlugs = ["dlang/dmd", "dlang/druntime", "dlang/phobos", - "dlang/dlang.org", "dlang/tools", "dlang/installer"]; +static immutable bugzillaProjectSlugs = ["dlang/installer"]; import std.algorithm, std.conv, std.range, std.string; @@ -95,65 +94,14 @@ struct IssueRef { int id; bool fixed; Json[] commits; } // get all issues mentioned in a commit IssueRef[] getIssueRefs(RE)(Json[] commits, RE re = issueRE) { - return commits - // Collect all issue references (range of ranges per commit) - .map!(c => c["commit"]["message"] - .get!string - .matchIssueRefs(re) - .map!((r) { r.commits = [c]; return r; }) - ) - // Join to flat list - .join - // Sort and group by issue ID - .sort!((a, b) => a.id < b.id, SwapStrategy.stable) - .groupBy - // Reduce each per-ID group to a single IssueRef - .map!(g => g - .reduce!((a, b) => - IssueRef(a.id, a.fixed || b.fixed, a.commits ~ b.commits) - ) - ) - .array; -} - -unittest -{ - Json fix(int id) { return ["commit":["message":"Fix Bugzilla %d".format(id).Json].Json].Json; } - Json mention(int id) { return ["commit":["message":"Bugzilla %d".format(id).Json].Json].Json; } - - assert(getIssueRefs([fix(1)]) == [IssueRef(1, true, [fix(1)])]); - assert(getIssueRefs([mention(1)]) == [IssueRef(1, false, [mention(1)])]); - assert(getIssueRefs([fix(1), mention(1)]) == [IssueRef(1, true, [fix(1), mention(1)])]); - assert(getIssueRefs([mention(1), fix(1)]) == [IssueRef(1, true, [mention(1), fix(1)])]); - assert(getIssueRefs([mention(1), fix(2), fix(1)]) == [IssueRef(1, true, [mention(1), fix(1)]), IssueRef(2, true, [fix(2)])]); + return null; } UserMessage[] checkLegacyIssueRefs(Json[] commits) { - auto oldHits = commits.getIssueRefs(oldIssueRE).map!(r => r.id); - auto newHits = commits.getIssueRefs(issueRE).map!(r => r.id); - auto onlyOld = oldHits.filter!(id => !newHits.canFind(id)); - if (!onlyOld.empty) - return [UserMessage(UserMessage.Type.Warning, - "In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. " ~ - "Please add the word \"Bugzilla\" to issue references. For example, `Fix Bugzilla Issue 12345` or `Fix Bugzilla 12345`." ~ - "(Reminder: the edit needs to be done in the Git *commit message*, not the GitHub *pull request*.)" - )]; return null; } -unittest -{ - Json fixOld(int id) { return ["commit":["message":"Fix Issue %d".format(id).Json].Json].Json; } - Json fixNew(int id) { return ["commit":["message":"Fix Bugzilla %d".format(id).Json].Json].Json; } - - assert( checkLegacyIssueRefs([]).empty); - assert( checkLegacyIssueRefs([fixNew(1)]).empty); - assert( checkLegacyIssueRefs([fixOld(1), fixNew(1)]).empty); - assert(!checkLegacyIssueRefs([fixOld(1)]).empty); - assert(!checkLegacyIssueRefs([fixOld(1), fixNew(2)]).empty); - } - struct Issue { int id; diff --git a/test/bugzilla.d b/test/bugzilla.d index 261669e..b8409df 100644 --- a/test/bugzilla.d +++ b/test/bugzilla.d @@ -1,371 +1 @@ -import std.string; - -import utils; - -@("after-merge-close-issue-bugzilla") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/phobos/pulls/4963/commits", (ref Json j) { - j[0]["commit"]["message"] = "Fix bugzilla Issue 17564"; - }, - "/github/repos/dlang/phobos/issues/4963/comments", - "/github/repos/dlang/phobos/issues/4963/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - res.writeJsonBody(Json.emptyArray); - }, - "/github/repos/dlang/phobos/issues/4963/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - res.writeVoidBody; - }, - "/trello/1/search?query=name:%22Issue%2017564%22&"~trelloAuth, - "/bugzilla/buglist.cgi?bug_id=17564&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords", - "/bugzilla/jsonrpc.cgi", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.json["method"].get!string == "Bug.comments"); - res.writeJsonBody([ - "error" : Json(null), - "result" : [ - "bugs" : [ - "17564" : [ - "comments" : Json.emptyArray - ].Json - ].Json - ].Json - ].Json); - }, - "/bugzilla/jsonrpc.cgi", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.POST); - assert(req.json["method"].get!string == "Bug.update"); - assert(req.json["params"][0]["status"].get!string == "RESOLVED"); - assert(req.json["params"][0]["resolution"].get!string == "FIXED"); - - auto comment = req.json["params"][0]["comment"]["body"].get!string; - enum expected = q"EOF -dlang/phobos pull request #4963 "[DEMO for DIP1005] Converted imports to selective imports in std.array" was merged into master: - -- e064d5664f92c4b2f0866c08f6d0290ba66825ed by Andrei Alexandrescu: - Fix bugzilla Issue 17564 - -https://github.com/dlang/phobos/pull/4963 -EOF".chomp; - assert(comment == expected, comment); - - auto j = Json(["error" : Json(null), "result" : Json.emptyObject]); - res.writeJsonBody(j); - }, - ); - - postGitHubHook("dlang_phobos_merged_4963.json"); -} - -@("after-merge-comment-issue-bugzilla") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/phobos/pulls/4963/commits", (ref Json j) { - j[0]["commit"]["message"] = "Do something with Bugzilla Issue 17564"; - }, - "/github/repos/dlang/phobos/issues/4963/comments", - "/trello/1/search?query=name:%22Issue%2017564%22&"~trelloAuth, - "/bugzilla/buglist.cgi?bug_id=17564&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords", - "/bugzilla/jsonrpc.cgi", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.json["method"].get!string == "Bug.comments"); - res.writeJsonBody([ - "error" : Json(null), - "result" : [ - "bugs" : [ - "17564" : [ - "comments" : Json.emptyArray - ].Json - ].Json - ].Json - ].Json); - }, - "/bugzilla/jsonrpc.cgi", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.POST); - assert(req.json["method"].get!string == "Bug.update"); - assert("status" !in req.json["params"][0]); - assert("resolution" !in req.json["params"][0]); - - auto comment = req.json["params"][0]["comment"]["body"].get!string; - enum expected = q"EOF -dlang/phobos pull request #4963 "[DEMO for DIP1005] Converted imports to selective imports in std.array" was merged into master: - -- e064d5664f92c4b2f0866c08f6d0290ba66825ed by Andrei Alexandrescu: - Do something with Bugzilla Issue 17564 - -https://github.com/dlang/phobos/pull/4963 -EOF".chomp; - assert(comment == expected, comment); - - auto j = Json(["error" : Json(null), "result" : Json.emptyObject]); - res.writeJsonBody(j); - }, - ); - - postGitHubHook("dlang_phobos_merged_4963.json"); -} - -@("after-merge-dont-comment-other-org") -unittest -{ - setAPIExpectations( - "/github/repos/notdlang/bar/pulls/12347/commits", (ref Json j) { - j[0]["commit"]["message"] = "Do something with Bugzilla Issue 17564"; - }, - "/github/repos/notdlang/bar/issues/12347/comments", - ); - - postGitHubHook("notdlang_bar_merged_12347.json"); -} - -@("after-merge-dont-comment-non-bugzilla") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/dub/pulls/12345/commits", (ref Json j) { - j[0]["commit"]["message"] = "Do something with Bugzilla Issue 17564"; - }, - "/github/repos/dlang/dub/issues/12345/comments", - ); - - postGitHubHook("dlang_dub_merged_12345.json"); -} - -@("after-merge-dont-spam-bugzilla") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/phobos/pulls/4963/commits", (ref Json j) { - j[0]["commit"]["message"] = "Fix Bugzilla Issue 17564"; - }, - "/github/repos/dlang/phobos/issues/4963/comments", - "/github/repos/dlang/phobos/issues/4963/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - res.writeJsonBody(Json.emptyArray); - }, - "/github/repos/dlang/phobos/issues/4963/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - res.writeVoidBody; - }, - "/trello/1/search?query=name:%22Issue%2017564%22&"~trelloAuth, - "/bugzilla/buglist.cgi?bug_id=17564&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords", - "/bugzilla/jsonrpc.cgi", - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.json["method"].get!string == "Bug.comments"); - enum oldComment = q"EOF -dlang/phobos pull request #4963 "[DEMO for DIP1005] Converted imports to selective imports in std.array" was merged into stable: - -- e064d5664f92c4b2f0866c08f6d0290ba66825ed by Andrei Alexandrescu: - Fix Bugzilla Issue 17564 - -https://github.com/dlang/phobos/pull/4963 -EOF".chomp; - res.writeJsonBody([ - "error" : Json(null), - "result" : [ - "bugs" : [ - "17564" : [ - "comments" : [ - [ - "creator" : bugzillaLogin.Json, - "text" : oldComment.Json - ].Json, - ].Json, - ].Json - ].Json - ].Json - ].Json); - }, - ); - - postGitHubHook("dlang_phobos_merged_4963.json"); -} - -@("pr-open-notify-bugzilla") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/dmd/pulls/6359/commits", - "/github/repos/dlang/dmd/issues/6359/comments", - "/bugzilla/buglist.cgi?bug_id=16794&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" -16794,"dmd not working on Ubuntu 16.10 because of default PIE linking","NEW","---","critical","P1",`); - }, - "/github/orgs/dlang/public_members?per_page=100", - "/github/repos/dlang/dmd/issues/6359/comments", - "/github/repos/dlang/dmd/issues/6359/labels", - "/github/repos/dlang/dmd/issues/6359/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/search?query=name:%22Issue%2016794%22&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/actions?filter=commentCard&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/actions/583f517b91413ef81f1f9d34/comments?"~trelloAuth, - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/cards/583f517a333add7c28e0cec7?"~trelloAuth, - "/trello/1/board/55586bf9fd02d8c66074321a/lists?"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/idList?value=55586d9b810fb97f9459df7d&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/pos?value=bottom&"~trelloAuth, - "/bugzilla/jsonrpc.cgi", // Bug.comments - "/bugzilla/jsonrpc.cgi", // Bug.update - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.POST); - assert(req.json["method"].get!string == "Bug.update"); - assert("status" !in req.json["params"][0]); - assert("resolution" !in req.json["params"][0]); - assert("keywords" in req.json["params"][0]); - - auto comment = req.json["params"][0]["comment"]["body"].get!string; - enum expected = q"EOF -@MartinNowak created dlang/dmd pull request #6359 "fix Issue 16794 - dmd not working on Ubuntu 16.10" fixing this issue: - -- fix Bugzilla Issue 16794 - dmd not working on Ubuntu 16.10 - - - enable PIC by default on amd64 linux (no significant overhead, full - PIC/PIE support) - - also see https://github.com/dlang/installer/pull/207 - -https://github.com/dlang/dmd/pull/6359 -EOF".chomp; - assert(comment == expected, comment); - - auto j = Json(["error" : Json(null), "result" : Json.emptyObject]); - res.writeJsonBody(j); - }, - ); - - postGitHubHook("dlang_dmd_open_6359.json"); -} - -@("pr-open-notify-bugzilla-whitehole") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/dmd/pulls/6359/commits", - (ref Json j){ - j[0]["commit"]["message"] = "Fix Bugzilla Issue 20540 - (White|Black)Hole does not work with return|scope functions"; - }, - "/github/repos/dlang/dmd/issues/6359/comments", - "/bugzilla/buglist.cgi?bug_id=20540&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" -20540,"(White|Black)Hole does not work with return|scope functions","NEW","---","normal","P1","pull"`); - }, - "/github/orgs/dlang/public_members?per_page=100", - "/github/repos/dlang/dmd/issues/6359/comments", - (scope HTTPServerRequest req, scope HTTPServerResponse res) { - assert(req.method == HTTPMethod.POST); - assert(req.json["body"].get!string.canFind(r"| \(White|Black\)Hole does not work with return|scope functions")); - }, - "/github/repos/dlang/dmd/issues/6359/labels", - "/github/repos/dlang/dmd/issues/6359/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/search?query=name:%22Issue%2020540%22&"~trelloAuth, - (scope HTTPServerRequest req, scope HTTPServerResponse res) { - res.writeBody(`{"cards": []}`); - }, - "/bugzilla/jsonrpc.cgi", // Bug.comments - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - res.writeBody(`{"error" : null, "result" : { - "bugs" : {"20540" : {"comments" : []}}, - "comments" : {} - }}`); - }, - "/bugzilla/jsonrpc.cgi", // Bug.update - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.POST); - assert(req.json["method"].get!string == "Bug.update"); - - auto j = Json(["error" : Json(null), "result" : Json.emptyObject]); - res.writeJsonBody(j); - }, - ); - - postGitHubHook("dlang_dmd_open_6359.json"); -} - -@("pr-open-different-org") -unittest -{ - setAPIExpectations( - "/github/repos/notdlang/foo/pulls/12346/commits", - "/github/repos/notdlang/foo/issues/12346/comments", - ); - - postGitHubHook("notdlang_foo_open_12346.json"); -} - -@("pr-open-dont-spam-closed-bugzilla-issues") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/dmd/pulls/6359/commits", - "/github/repos/dlang/dmd/issues/6359/comments", - "/bugzilla/buglist.cgi?bug_id=16794&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords", // "RESOLVED"/"FIXED" - "/github/orgs/dlang/public_members?per_page=100", - "/github/repos/dlang/dmd/issues/6359/comments", - "/github/repos/dlang/dmd/issues/6359/labels", - "/github/repos/dlang/dmd/issues/6359/labels", - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/search?query=name:%22Issue%2016794%22&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/actions?filter=commentCard&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/actions/583f517b91413ef81f1f9d34/comments?"~trelloAuth, - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/cards/583f517a333add7c28e0cec7?"~trelloAuth, - "/trello/1/board/55586bf9fd02d8c66074321a/lists?"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/idList?value=55586d9b810fb97f9459df7d&"~trelloAuth, - "/trello/1/cards/583f517a333add7c28e0cec7/pos?value=bottom&"~trelloAuth, - "/bugzilla/jsonrpc.cgi", // Bug.comments - ); - - postGitHubHook("dlang_dmd_open_6359.json"); -} - -@("pr-synchronize-dont-spam") -unittest -{ - setAPIExpectations( - "/github/repos/dlang/phobos/pulls/4921/commits", - "/github/repos/dlang/phobos/issues/4921/labels", - "/github/repos/dlang/phobos/issues/4921/comments", - "/github/orgs/dlang/public_members?per_page=100", - "/bugzilla/buglist.cgi?bug_id=8573&ctype=csv&columnlist=short_desc,bug_status,resolution,bug_severity,priority,keywords", // "NEW"/"---" - "/github/repos/dlang/phobos/issues/comments/262784442", - (scope HTTPServerRequest req, scope HTTPServerResponse res) {}, - "/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth, - "/bugzilla/jsonrpc.cgi", // Bug.comments - (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.json["method"].get!string == "Bug.comments"); - enum oldComment = q"EOF -@andralex created dlang/phobos pull request #4921 "[DEMO for DIP1005] Converted imports to selective imports in std.array" mentioning this issue: - -- yada yada - -https://github.com/dlang/phobos/pull/4921 -EOF".chomp; - res.writeJsonBody([ - "error" : Json(null), - "result" : [ - "bugs" : [ - "8573" : [ - "comments" : [ - [ - "creator" : bugzillaLogin.Json, - "text" : oldComment.Json - ].Json, - ].Json, - ].Json - ].Json - ].Json - ].Json); - }, - ); - - postGitHubHook("dlang_phobos_synchronize_4921.json"); -} +module bugzilla;