@@ -7,10 +7,10 @@ public import dlangbot.bugzilla : bugzillaURL;
77public import dlangbot.github : githubAPIURL, githubAuth, hookSecret;
88public import dlangbot.trello : trelloAPIURL, trelloAuth, trelloSecret;
99
10- string cronDailySecret;
11-
1210import std.datetime : Clock , days, Duration, minutes, seconds, SysTime;
1311
12+ import vibe.core.args ;
13+ import vibe.core.core ;
1414import vibe.core.log ;
1515import vibe.data.json;
1616import vibe.http.client : HTTPClient;
@@ -29,32 +29,6 @@ Duration prInactivityDur = 90.days; // PRs with no activity within X days will g
2929
3030enum trelloHookURL = " https://dlang-bot.herokuapp.com/trello_hook" ;
3131
32- version (unittest ){} else
33- shared static this ()
34- {
35- import std.process : environment;
36- import vibe.core.args : readOption;
37-
38- auto settings = new HTTPServerSettings;
39- settings.port = 8080 ;
40- readOption(" port|p" , &settings.port, " Sets the port used for serving." );
41- startServer(settings);
42-
43- githubAuth = " token " ~ environment[" GH_TOKEN" ];
44- trelloSecret = environment[" TRELLO_SECRET" ];
45- trelloAuth = " key=" ~ environment[" TRELLO_KEY" ]~ " &token=" ~ environment[" TRELLO_TOKEN" ];
46- hookSecret = environment[" GH_HOOK_SECRET" ];
47- cronDailySecret = environment[" CRON_DAILY_SECRET" ];
48-
49- // workaround for stupid openssl.conf on Heroku
50- if (environment.get (" DYNO" ) ! is null )
51- {
52- HTTPClient.setTLSSetupCallback((ctx) {
53- ctx.useTrustedCertificateFile(" /etc/ssl/certs/ca-certificates.crt" );
54- });
55- }
56- }
57-
5832void startServer (HTTPServerSettings settings)
5933{
6034 import vibe.core.core : vibeVersionString;
@@ -71,7 +45,6 @@ void startServer(HTTPServerSettings settings)
7145 .post(" /github_hook" , &githubHook)
7246 .match(HTTPMethod.HEAD , " /trello_hook" , (req, res) => res.writeVoidBody)
7347 .post(" /trello_hook" , &trelloHook)
74- .get (" /cron_daily" , &cronDaily)
7548 ;
7649
7750 HTTPClient.setUserAgentString(" dlang-bot vibe.d/" ~ vibeVersionString);
@@ -152,19 +125,13 @@ void githubHook(HTTPServerRequest req, HTTPServerResponse res)
152125
153126// ==============================================================================
154127
155- void cronDaily (HTTPServerRequest req, HTTPServerResponse res )
128+ void cronDaily ()
156129{
157- enforceBadRequest(req.query.length > 0 , " No repo slugs provided" );
158- enforceHTTP(req.query.get (" secret" ) == cronDailySecret,
159- HTTPStatus.unauthorized, " Invalid or no secret provided" );
160-
161- foreach (ref slug; req.query.getAll(" repo" ))
130+ foreach (repo; [" dlang/phobos" ])
162131 {
163- logInfo(" running cron.daily for: %s" , slug );
164- runTaskHelper(& searchForInactivePrs, slug , prInactivityDur);
132+ logInfo(" running cron.daily for: %s" , repo );
133+ searchForInactivePrs(repo , prInactivityDur);
165134 }
166-
167- return res.writeBody(" OK" );
168135}
169136
170137// ==============================================================================
@@ -213,3 +180,39 @@ void handlePR(string action, PullRequest* _pr)
213180 if (runTrello)
214181 updateTrelloCard(action, pr.htmlURL, refs, descs);
215182}
183+
184+ // ==============================================================================
185+
186+ version (unittest ) {}
187+ else void main(string [] args)
188+ {
189+ import std.process : environment;
190+ import vibe.core.args : readOption;
191+
192+ githubAuth = " token " ~ environment[" GH_TOKEN" ];
193+ trelloSecret = environment[" TRELLO_SECRET" ];
194+ trelloAuth = " key=" ~ environment[" TRELLO_KEY" ]~ " &token=" ~ environment[" TRELLO_TOKEN" ];
195+ hookSecret = environment[" GH_HOOK_SECRET" ];
196+
197+ // workaround for stupid openssl.conf on Heroku
198+ if (environment.get (" DYNO" ) ! is null )
199+ {
200+ HTTPClient.setTLSSetupCallback((ctx) {
201+ ctx.useTrustedCertificateFile(" /etc/ssl/certs/ca-certificates.crt" );
202+ });
203+ }
204+
205+ bool runDailyCron;
206+ auto settings = new HTTPServerSettings;
207+ settings.port = 8080 ;
208+ readOption(" port|p" , &settings.port, " Sets the port used for serving." );
209+ readOption(" cron-daily" , &runDailyCron, " Run daily cron tasks." );
210+ if (! finalizeCommandLineOptions())
211+ return ;
212+ if (runDailyCron)
213+ return cronDaily ();
214+
215+ startServer(settings);
216+ lowerPrivileges();
217+ runEventLoop();
218+ }
0 commit comments