Skip to content

Commit bb29c92

Browse files
wilzbachdlang-bot
authored andcommitted
Restrict Bugzilla features to dlang repositories
1 parent e2508f1 commit bb29c92

File tree

4 files changed

+69
-32
lines changed

4 files changed

+69
-32
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ script:
1111
# Tests are neither random- nor parallelizable atm., so use a --single serial thread.
1212
- dub test --compiler=$DC -- --single --trace
1313

14-
addons:
15-
apt:
16-
packages:
17-
- libevent-dev
18-
1914
matrix:
2015
include:
2116
- d: dmd-2.085.0 # the deployment compiler

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ For example, `dlang/phobos` is configured as follows:
210210

211211
<a name="missing-a-feature" />
212212

213+
Improve the bot
214+
---------------
215+
216+
Run the testsuite:
217+
218+
```
219+
dub test -- --single --trace
220+
```
221+
213222
Missing a feature?
214223
------------------
215224

source/dlangbot/app.d

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -238,48 +238,52 @@ void handlePR(string action, PullRequest* _pr)
238238
if (commits is null)
239239
commits = ghGetRequest(pr.commitsURL).readJson[];
240240

241-
auto refs = getIssueRefs(commits);
242-
243-
auto descs = getDescriptions(refs);
244241
auto comment = pr.getBotComment;
245242

246243
UserMessage[] msgs;
247-
if (action == "opened" || action == "synchronize")
244+
IssueRef[] refs;
245+
Issue[] descs;
246+
if (pr.base.repo.owner.login.among("dlang", "dlang-bots"))
248247
{
249-
msgs = pr.checkForWarnings(descs, refs);
250-
}
248+
refs = getIssueRefs(commits);
249+
descs = getDescriptions(refs);
250+
if (action == "opened" || action == "synchronize")
251+
{
252+
msgs = pr.checkForWarnings(descs, refs);
253+
}
251254

252-
if (pr.base.repo.owner.login.among("dlang", "dlang-bots"))
253255
pr.updateGithubComment(comment, action, refs, descs, msgs);
254256

255-
if (refs.any!(r => r.fixed))
256-
{
257-
import std.algorithm : canFind, filter, map, sort, uniq;
258-
import std.array : array;
259-
// references are already sorted by id
260-
auto bugzillaIds = refs.map!(r => r.id).uniq;
261-
auto bugzillSeverities = descs
262-
.filter!(d => bugzillaIds.canFind(d.id))
263-
.map!(i => i.severity);
264-
logDebug("[github/handlePR](%s): trying to add bug fix label", _pr.pid);
265-
string[] labels;
266-
if (bugzillSeverities.canFind("enhancement"))
267-
labels ~= "Enhancement";
268-
else
269-
labels ~= "Bug Fix";
270-
271-
pr.addLabels(labels);
257+
if (refs.any!(r => r.fixed))
258+
{
259+
import std.algorithm : canFind, filter, map, sort, uniq;
260+
import std.array : array;
261+
// references are already sorted by id
262+
auto bugzillaIds = refs.map!(r => r.id).uniq;
263+
auto bugzillSeverities = descs
264+
.filter!(d => bugzillaIds.canFind(d.id))
265+
.map!(i => i.severity);
266+
logDebug("[github/handlePR](%s): trying to add bug fix label", _pr.pid);
267+
string[] labels;
268+
if (bugzillSeverities.canFind("enhancement"))
269+
labels ~= "Enhancement";
270+
else
271+
labels ~= "Bug Fix";
272+
273+
pr.addLabels(labels);
274+
}
272275
}
273276

274-
if (runTrello)
277+
if (runTrello && pr.base.repo.owner.login == "dlang")
275278
{
276279
logDebug("[github/handlePR](%s): updating trello card", _pr.pid);
277280
updateTrelloCard(action, pr.htmlURL, refs, descs);
278281
}
279282

280283
// When a PR is opened or updated mentioning some Bugzilla issues,
281284
// post a link to the PR as an issue comment.
282-
if (runBugzillaUpdates && (action == "opened" || action == "synchronize"))
285+
if (runBugzillaUpdates && pr.base.repo.owner.login == "dlang" &&
286+
(action == "opened" || action == "synchronize"))
283287
{
284288
import std.algorithm.iteration : filter, map;
285289
import std.algorithm.searching : canFind;
@@ -324,7 +328,8 @@ void handlePR(string action, PullRequest* _pr)
324328

325329
// When a PR is merged, update Bugzilla issues
326330
// (leave a comment with a link to the PR, and close them appropriately).
327-
if (runBugzillaUpdates && action == "merged")
331+
if (runBugzillaUpdates && pr.base.repo.owner.login == "dlang" &&
332+
action == "merged")
328333
{
329334
import std.algorithm.iteration : filter, map;
330335
import std.algorithm.searching : canFind, all, startsWith;

test/bugzilla.d

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ EOF".chomp;
110110
postGitHubHook("dlang_phobos_merged_4963.json");
111111
}
112112

113+
@("after-merge-dont-comment-other-org")
114+
unittest
115+
{
116+
setAPIExpectations(
117+
"/github/repos/dlang/phobos/pulls/4963/commits", (ref Json j) {
118+
j[0]["commit"]["message"] = "Do something with Issue 17564";
119+
},
120+
"/github/repos/dlang/phobos/issues/4963/comments",
121+
);
122+
123+
postGitHubHook("dlang_phobos_merged_4963.json", "pull_request", (ref Json j, scope req) {
124+
j["pull_request"]["base"]["repo"]["owner"]["login"] = "dlang-community";
125+
});
126+
}
127+
113128
@("after-merge-dont-spam-bugzilla")
114129
unittest
115130
{
@@ -216,6 +231,19 @@ EOF".chomp;
216231
postGitHubHook("dlang_dmd_open_6359.json");
217232
}
218233

234+
@("pr-open-different-org")
235+
unittest
236+
{
237+
setAPIExpectations(
238+
"/github/repos/dlang/dmd/pulls/6359/commits",
239+
"/github/repos/dlang/dmd/issues/6359/comments",
240+
);
241+
242+
postGitHubHook("dlang_dmd_open_6359.json", "pull_request", (ref Json j, scope req) {
243+
j["pull_request"]["base"]["repo"]["owner"]["login"] = "dlang-community";
244+
});
245+
}
246+
219247
@("pr-open-dont-spam-closed-bugzilla-issues")
220248
unittest
221249
{

0 commit comments

Comments
 (0)