@@ -8,12 +8,14 @@ public import dlangbot.github : githubAPIURL, githubAuth, hookSecret;
8
8
public import dlangbot.travis : travisAPIURL;
9
9
public import dlangbot.trello : trelloAPIURL, trelloAuth, trelloSecret;
10
10
11
- import std.datetime : Clock , Duration, minutes, seconds, SysTime;
11
+ string cronDailySecret;
12
+
13
+ import std.datetime : Clock , days, Duration, minutes, seconds, SysTime;
12
14
13
15
import vibe.core.log ;
14
16
import vibe.data.json;
15
17
import vibe.http.client : HTTPClient;
16
- import vibe.http.common : HTTPMethod;
18
+ import vibe.http.common : enforceBadRequest, enforceHTTP, HTTPMethod, HTTPStatus ;
17
19
import vibe.http.router : URLRouter;
18
20
import vibe.http.server : HTTPServerRequest, HTTPServerResponse, HTTPServerSettings;
19
21
import vibe.stream.operations : readAllUTF8;
@@ -24,6 +26,8 @@ bool runTrello = true;
24
26
Duration timeBetweenFullPRChecks = 5. minutes; // this should never be larger 30 mins on heroku
25
27
Throttler! (typeof (&searchForAutoMergePrs)) prThrottler;
26
28
29
+ Duration prInactivityDur = 90. days; // PRs with no activity within X days will get flagged
30
+
27
31
enum trelloHookURL = " https://dlang-bot.herokuapp.com/trello_hook" ;
28
32
29
33
version (unittest ){} else
@@ -42,6 +46,7 @@ shared static this()
42
46
trelloAuth = " key=" ~ environment[" TRELLO_KEY" ]~ " &token=" ~ environment[" TRELLO_TOKEN" ];
43
47
hookSecret = environment[" GH_HOOK_SECRET" ];
44
48
travisAuth = " token " ~ environment[" TRAVIS_TOKEN" ];
49
+ cronDailySecret = environment[" CRON_DAILY_SECRET" ];
45
50
46
51
// workaround for stupid openssl.conf on Heroku
47
52
if (environment.get (" DYNO" ) ! is null )
@@ -68,6 +73,7 @@ void startServer(HTTPServerSettings settings)
68
73
.post(" /github_hook" , &githubHook)
69
74
.match(HTTPMethod.HEAD , " /trello_hook" , (req, res) => res.writeVoidBody)
70
75
.post(" /trello_hook" , &trelloHook)
76
+ .get (" /cron_daily" , &cronDaily)
71
77
;
72
78
73
79
HTTPClient.setUserAgentString(" dlang-bot vibe.d/" ~ vibeVersionString);
@@ -155,7 +161,7 @@ void githubHook(HTTPServerRequest req, HTTPServerResponse res)
155
161
case " opened" , " reopened" , " synchronize" , " labeled" , " edited" :
156
162
157
163
auto pullRequest = json[" pull_request" ].deserializeJson! PullRequest;
158
- runTaskHelper(toDelegate( &handlePR) , action, pullRequest);
164
+ runTaskHelper(&handlePR, action, & pullRequest);
159
165
return res.writeBody(" handled" );
160
166
default :
161
167
return res.writeBody(" ignored" );
@@ -167,11 +173,30 @@ void githubHook(HTTPServerRequest req, HTTPServerResponse res)
167
173
168
174
// ==============================================================================
169
175
170
- void handlePR (string action, PullRequest pr)
176
+ void cronDaily (HTTPServerRequest req, HTTPServerResponse res)
177
+ {
178
+ enforceBadRequest(req.query.length > 0 , " No repo slugs provided" );
179
+ enforceHTTP(req.query.get (" secret" ) == cronDailySecret,
180
+ HTTPStatus.unauthorized, " Invalid or no secret provided" );
181
+
182
+ foreach (ref slug; req.query.getAll(" repo" ))
183
+ {
184
+ logInfo(" running cron.daily for: %s" , slug);
185
+ runTaskHelper(&searchForInactivePrs, slug, prInactivityDur);
186
+ }
187
+
188
+ return res.writeBody(" OK" );
189
+ }
190
+
191
+ // ==============================================================================
192
+
193
+ void handlePR (string action, PullRequest* _pr)
171
194
{
172
195
import std.algorithm : any;
173
196
import vibe.core.core : setTimer;
174
197
198
+ const PullRequest pr = * _pr;
199
+
175
200
Json[] commits;
176
201
177
202
if (action == " labeled" || action == " synchronize" )
0 commit comments