Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proof of concept] Show hello greeting message #44

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions source/dlangbot/github.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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_)
Expand All @@ -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 }

Expand Down
13 changes: 8 additions & 5 deletions test/comments.d
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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");
}
);

Expand All @@ -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);
}
);

Expand Down
2 changes: 2 additions & 0 deletions test/labels.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
Expand Down