Skip to content

Commit 8f896d1

Browse files
authored
Merge pull request #156 from wilzbach/impro
Rename cli option to --simulate-daily-cron + use toLower for labels merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
2 parents f41edb5 + bdc76d1 commit 8f896d1

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

source/dlangbot/app.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ else void main(string[] args)
268268
auto settings = new HTTPServerSettings;
269269
settings.port = 8080;
270270
readOption("port|p", &settings.port, "Sets the port used for serving.");
271-
readOption("simulative-cron-daily", &runDailyCronSimulation, "Sets the port used for serving.");
271+
readOption("simulate-cron-daily", &runDailyCronSimulation, "Sets the port used for serving.");
272272
readOption("cron-daily", &runDailyCron, "Run daily cron tasks.");
273273
if (!finalizeCommandLineOptions())
274274
return;

source/dlangbot/cron.d

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ auto walkPR(Actions)(string repoSlug, GHIssue issue, Actions actions, CronConfig
144144
}
145145
}
146146

147+
import std.uni : asLowerCase, sicmp;
148+
alias siEqual = (a, b) => sicmp(a, b) == 0;
149+
alias siLess = (a, b) => sicmp(a, b) < 0;
147150
// update labels
148151
auto putLabels = labels.chain(addLabels)
149152
.array
150-
.sort.uniq
151-
.filter!(l => !removeLabels.canFind(l)).array;
153+
.sort!siLess
154+
.uniq!siEqual
155+
.filter!(l => !removeLabels.map!asLowerCase.canFind(l.asLowerCase)).array;
152156

153-
if (!labels.equal(putLabels))
157+
auto labelsSorted = labels.dup.sort!siLess;
158+
if (!labelsSorted.equal!siEqual(putLabels))
154159
{
155160
logInfo("[%s/%d/putLabels]: %s (before: %s)", repoSlug, pr.number, putLabels, labels);
156161
if (!config.simulate)

source/dlangbot/github.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ Json[] tryMerge(in ref PullRequest pr, GHMerge.MergeMethod method)
197197

198198
void checkAndRemoveLabels(GHLabel[] labels, in ref PullRequest pr, in string[] toRemoveLabels)
199199
{
200+
import std.uni : toLower;
200201
labels
201-
.map!(l => l.name)
202+
.map!(l => l.name.toLower)
202203
.filter!(n => toRemoveLabels.canFind(n))
203204
.each!(l => pr.removeLabel(l));
204205
}

test/cronjob.d

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import utils;
33
import std.format : format;
44
import std.stdio;
55

6-
bool simulate = false;
76
string[] repositories = ["dlang/phobos"];
87

98
// test the first items of the cron job
@@ -53,14 +52,11 @@ unittest
5352
(scope HTTPServerRequest req, scope HTTPServerResponse res){
5453
assert(req.method == HTTPMethod.PUT);
5554
assert(req.json[].map!(e => e.get!string).equal(
56-
["Bug Fix", "Enhancement","decision block", "needs rebase", "stalled"]
55+
["Bug Fix", "decision block", "Enhancement", "needs rebase", "stalled"]
5756
));
5857
},
5958
);
60-
61-
import dlangbot.app : cronDaily;
62-
cronDaily(repositories, simulate);
63-
checkAPIExpectations;
59+
testCronDaily(repositories);
6460
}
6561

6662
// test that stalled isn't falsely removed (e.g. by recent labelling)
@@ -86,7 +82,5 @@ unittest
8682
},
8783
);
8884

89-
import dlangbot.app : cronDaily;
90-
cronDaily(repositories, simulate);
91-
checkAPIExpectations;
85+
testCronDaily(repositories);
9286
}

test/utils.d

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,14 @@ void openUrl(string url, string expectedResponse,
317317
checkAPIExpectations;
318318
assert(req.bodyReader.readAllUTF8 == expectedResponse);
319319
}
320+
321+
void testCronDaily(string[] repositories, int line = __LINE__, string file = __FILE__)
322+
{
323+
import dlangbot.app : cronDaily;
324+
bool simulate = false;
325+
326+
logInfo("Starting cron test in %s:%d", file, line);
327+
328+
cronDaily(repositories, simulate);
329+
checkAPIExpectations;
330+
}

0 commit comments

Comments
 (0)