Skip to content

Commit 7014bd2

Browse files
committed
Show hello greeting message
1 parent 8153e4d commit 7014bd2

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

source/dlangbot/github.d

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,45 @@ import vibe.stream.operations : readAllUTF8;
2020
// Github comments
2121
//==============================================================================
2222

23-
string formatComment(R1, R2)(R1 refs, R2 descs)
23+
string formatComment(in ref PullRequest pr, in IssueRef[] refs, in Issue[] descs)
2424
{
2525
import std.array : appender;
2626
import std.format : formattedWrite;
2727

28-
auto combined = zip(refs.map!(r => r.id), refs.map!(r => r.fixed), descs.map!(d => d.desc));
2928
auto app = appender!string();
30-
app.put("Fix | Bugzilla | Description\n");
31-
app.put("--- | --- | ---\n");
29+
app.formattedWrite(
30+
`Thanks for your pull request, @%s! We are looking
31+
forward to reviewing it, and you should be hearing from
32+
a maintainer soon.
3233
33-
foreach (num, closed, desc; combined)
34+
Some things that can help to speed things up:
35+
36+
- smaller, focused PRs are easier to review than big ones
37+
38+
- try not to mix up refactoring or style changes with bug
39+
fixes or feature enhancements
40+
41+
- provide helpful commit messages explaining the rationale
42+
behind each change
43+
44+
Bear in mind that large or tricky changes may require multiple
45+
rounds of review and revision.
46+
47+
Please see [CONTRIBUTING.md](https://github.com/%s/blob/master/CONTRIBUTING.md) for more information.
48+
49+
`, pr.user.login, pr.repoSlug);
50+
51+
if (refs.length > 0)
3452
{
35-
app.formattedWrite(
36-
"%1$s | [%2$s](%4$s/show_bug.cgi?id=%2$s) | %3$s\n",
37-
closed ? "" : "", num, desc, bugzillaURL);
53+
auto combined = zip(refs.map!(r => r.id), refs.map!(r => r.fixed), descs.map!(d => d.desc));
54+
app.put("Fix | Bugzilla | Description\n");
55+
app.put("--- | --- | ---\n");
56+
foreach (num, closed, desc; combined)
57+
{
58+
app.formattedWrite(
59+
"%1$s | [%2$s](%4$s/show_bug.cgi?id=%2$s) | %3$s\n",
60+
closed ? "" : "", num, desc, bugzillaURL);
61+
}
3862
}
3963
return app.data;
4064
}
@@ -97,14 +121,10 @@ auto ghSendRequest(T...)(HTTPMethod method, string url, T arg)
97121
void updateGithubComment(in ref PullRequest pr, in ref GHComment comment, string action, IssueRef[] refs, Issue[] descs)
98122
{
99123
logDebug("%s", refs);
100-
if (refs.empty)
101-
{
102-
return comment.remove();
103-
}
104124
logDebug("%s", descs);
105125
assert(refs.map!(r => r.id).equal(descs.map!(d => d.id)));
106126

107-
auto msg = formatComment(refs, descs);
127+
auto msg = pr.formatComment(refs, descs);
108128
logDebug("%s", msg);
109129

110130
if (msg != comment.body_)
@@ -121,6 +141,12 @@ void updateGithubComment(in ref PullRequest pr, in ref GHComment comment, string
121141
// Github Auto-merge
122142
//==============================================================================
123143

144+
static struct User
145+
{
146+
string login;
147+
}
148+
149+
User user;
124150
alias LabelsAndCommits = Tuple!(Json[], "labels", Json[], "commits");
125151
enum MergeMethod { none = 0, merge, squash, rebase }
126152

test/comments.d

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ unittest
1818
--- | --- | ---
1919
✗ | [8573](%s/show_bug.cgi?id=8573) | A simpler Phobos function that returns the index of the mix or max item
2020
`.format(bugzillaURL);
21-
assert(req.json["body"].get!string == expectedComment);
21+
assert(req.json["body"].get!string.canFind(expectedComment));
2222
},
2323
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
2424
);
@@ -45,7 +45,7 @@ unittest
4545
--- | --- | ---
4646
✗ | [8573](%s/show_bug.cgi?id=8573) | A simpler Phobos function that returns the index of the mix or max item
4747
`.format(bugzillaURL);
48-
assert(req.json["body"].get!string == expectedComment);
48+
assert(req.json["body"].get!string.canFind(expectedComment));
4949
res.writeVoidBody;
5050
},
5151
"/trello/1/search?query=name:%22Issue%208573%22&"~trelloAuth,
@@ -55,7 +55,7 @@ unittest
5555
}
5656

5757
// existing dlang bot comment, but no commits that reference a issue
58-
// -> delete comment
58+
// -> update comment (without references to Bugzilla)
5959
unittest
6060
{
6161
setAPIExpectations(
@@ -66,7 +66,10 @@ unittest
6666
"/github/repos/dlang/phobos/issues/4921/comments",
6767
"/github/repos/dlang/phobos/issues/comments/262784442",
6868
(scope HTTPServerRequest req, scope HTTPServerResponse res){
69-
assert(req.method == HTTPMethod.DELETE);
69+
assert(req.method == HTTPMethod.PATCH);
70+
auto body_= req.json["body"].get!string;
71+
assert(!body_.canFind("Fix | Bugzilla"), "Shouldn't contain bug header");
72+
assert(!body_.canFind("/show_bug.cgi?id="), "Shouldn't contain a Bugzilla reference");
7073
}
7174
);
7275

@@ -92,7 +95,7 @@ unittest
9295
"/github/repos/dlang/phobos/issues/4921/comments",
9396
"/github/repos/dlang/phobos/issues/comments/262784442",
9497
(scope HTTPServerRequest req, scope HTTPServerResponse res){
95-
assert(req.method == HTTPMethod.DELETE);
98+
assert(req.method == HTTPMethod.PATCH);
9699
}
97100
);
98101

test/labels.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ unittest
9393
json = Json.emptyArray;
9494
},
9595
"/github/repos/dlang/dmd/issues/6359/comments",
96+
"/github/repos/dlang/dmd/issues/6359/comments",
9697
"/github/repos/dlang/dmd/issues/6359/labels",
9798
(scope HTTPServerRequest req, scope HTTPServerResponse res) {
9899
assert(req.method == HTTPMethod.POST);
@@ -116,6 +117,7 @@ unittest
116117
json = Json.emptyArray;
117118
},
118119
"/github/repos/dlang/dmd/issues/6359/comments",
120+
"/github/repos/dlang/dmd/issues/6359/comments",
119121
);
120122

121123
postGitHubHook("dlang_dmd_open_6359.json", "pull_request",

0 commit comments

Comments
 (0)