From 7014bd2ba226e9ad19704bbf1badf752aa955147 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Sun, 12 Feb 2017 02:37:23 +0100 Subject: [PATCH] Show hello greeting message --- source/dlangbot/github.d | 52 ++++++++++++++++++++++++++++++---------- test/comments.d | 13 ++++++---- test/labels.d | 2 ++ 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/source/dlangbot/github.d b/source/dlangbot/github.d index e2f554d..f0f95a9 100644 --- a/source/dlangbot/github.d +++ b/source/dlangbot/github.d @@ -20,21 +20,45 @@ import vibe.stream.operations : readAllUTF8; // Github comments //============================================================================== -string formatComment(R1, R2)(R1 refs, R2 descs) +string formatComment(in ref PullRequest pr, in IssueRef[] refs, in Issue[] descs) { import std.array : appender; import std.format : formattedWrite; - auto combined = zip(refs.map!(r => r.id), refs.map!(r => r.fixed), descs.map!(d => d.desc)); auto app = appender!string(); - app.put("Fix | Bugzilla | Description\n"); - app.put("--- | --- | ---\n"); + app.formattedWrite( +`Thanks for your pull request, @%s! We are looking +forward to reviewing it, and you should be hearing from +a maintainer soon. - foreach (num, closed, desc; combined) +Some things that can help to speed things up: + +- smaller, focused PRs are easier to review than big ones + +- try not to mix up refactoring or style changes with bug + fixes or feature enhancements + +- provide helpful commit messages explaining the rationale + behind each change + +Bear in mind that large or tricky changes may require multiple +rounds of review and revision. + +Please see [CONTRIBUTING.md](https://github.com/%s/blob/master/CONTRIBUTING.md) for more information. + +`, pr.user.login, pr.repoSlug); + + if (refs.length > 0) { - app.formattedWrite( - "%1$s | [%2$s](%4$s/show_bug.cgi?id=%2$s) | %3$s\n", - closed ? "✓" : "✗", num, desc, bugzillaURL); + auto combined = zip(refs.map!(r => r.id), refs.map!(r => r.fixed), descs.map!(d => d.desc)); + app.put("Fix | Bugzilla | Description\n"); + app.put("--- | --- | ---\n"); + foreach (num, closed, desc; combined) + { + app.formattedWrite( + "%1$s | [%2$s](%4$s/show_bug.cgi?id=%2$s) | %3$s\n", + closed ? "✓" : "✗", num, desc, bugzillaURL); + } } return app.data; } @@ -97,14 +121,10 @@ auto ghSendRequest(T...)(HTTPMethod method, string url, T arg) void updateGithubComment(in ref PullRequest pr, in ref GHComment comment, string action, IssueRef[] refs, Issue[] descs) { logDebug("%s", refs); - if (refs.empty) - { - return comment.remove(); - } logDebug("%s", descs); assert(refs.map!(r => r.id).equal(descs.map!(d => d.id))); - auto msg = formatComment(refs, descs); + auto msg = pr.formatComment(refs, descs); logDebug("%s", msg); if (msg != comment.body_) @@ -121,6 +141,12 @@ void updateGithubComment(in ref PullRequest pr, in ref GHComment comment, string // Github Auto-merge //============================================================================== + static struct User + { + string login; + } + + User user; alias LabelsAndCommits = Tuple!(Json[], "labels", Json[], "commits"); enum MergeMethod { none = 0, merge, squash, rebase } diff --git a/test/comments.d b/test/comments.d index b17dbed..faa90ab 100644 --- a/test/comments.d +++ b/test/comments.d @@ -18,7 +18,7 @@ unittest --- | --- | --- ✗ | [8573](%s/show_bug.cgi?id=8573) | A simpler Phobos function that returns the index of the mix or max item `.format(bugzillaURL); - assert(req.json["body"].get!string == expectedComment); + assert(req.json["body"].get!string.canFind(expectedComment)); }, "/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth, ); @@ -45,7 +45,7 @@ unittest --- | --- | --- ✗ | [8573](%s/show_bug.cgi?id=8573) | A simpler Phobos function that returns the index of the mix or max item `.format(bugzillaURL); - assert(req.json["body"].get!string == expectedComment); + assert(req.json["body"].get!string.canFind(expectedComment)); res.writeVoidBody; }, "/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth, @@ -55,7 +55,7 @@ unittest } // existing dlang bot comment, but no commits that reference a issue -// -> delete comment +// -> update comment (without references to Bugzilla) unittest { setAPIExpectations( @@ -66,7 +66,10 @@ unittest "/github/repos/dlang/phobos/issues/4921/comments", "/github/repos/dlang/phobos/issues/comments/262784442", (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.DELETE); + assert(req.method == HTTPMethod.PATCH); + auto body_= req.json["body"].get!string; + assert(!body_.canFind("Fix | Bugzilla"), "Shouldn't contain bug header"); + assert(!body_.canFind("/show_bug.cgi?id="), "Shouldn't contain a Bugzilla reference"); } ); @@ -92,7 +95,7 @@ unittest "/github/repos/dlang/phobos/issues/4921/comments", "/github/repos/dlang/phobos/issues/comments/262784442", (scope HTTPServerRequest req, scope HTTPServerResponse res){ - assert(req.method == HTTPMethod.DELETE); + assert(req.method == HTTPMethod.PATCH); } ); diff --git a/test/labels.d b/test/labels.d index e747ad7..5955fda 100644 --- a/test/labels.d +++ b/test/labels.d @@ -93,6 +93,7 @@ unittest json = Json.emptyArray; }, "/github/repos/dlang/dmd/issues/6359/comments", + "/github/repos/dlang/dmd/issues/6359/comments", "/github/repos/dlang/dmd/issues/6359/labels", (scope HTTPServerRequest req, scope HTTPServerResponse res) { assert(req.method == HTTPMethod.POST); @@ -116,6 +117,7 @@ unittest json = Json.emptyArray; }, "/github/repos/dlang/dmd/issues/6359/comments", + "/github/repos/dlang/dmd/issues/6359/comments", ); postGitHubHook("dlang_dmd_open_6359.json", "pull_request",