@@ -139,6 +139,7 @@ use JSON::Fast;
139
139
my % config = from-json slurp CONFIG;
140
140
my $ server = HTTP::Server::Async. new : | (% config <squashable ><host port >: p). Capture ;
141
141
my $ channel = Channel . new ;
142
+ my $ squashable = Squashable. new ;
142
143
143
144
# TODO failures here will blow up (or get ignored) without proper handling
144
145
$ server . handler: sub ($ request , $ response ) {
@@ -147,11 +148,6 @@ $server.handler: sub ($request, $response) {
147
148
$ response . status = 500 ; $ response . close ;
148
149
return
149
150
}
150
- if now ! ~~ squashathon-range $ next {
151
- $ response . status = 200 ; $ response . close ;
152
- return
153
- }
154
-
155
151
use Digest::SHA;
156
152
use Digest::HMAC;
157
153
my $ body = $ request . data;
@@ -161,21 +157,31 @@ $server.handler: sub ($request, $response) {
161
157
$ response . status = 400 ; $ response . close (‘ Signatures didn't match’ );
162
158
return
163
159
}
164
- my $ file = $ request . headers<X-GitHub-Delivery >;
165
- mkdir $ PATH . add(“ $ next” );
166
- spurt $ PATH . add(“ $ next /$ file” ), $ body if $ file ~~ /^ [<.xdigit >| ‘-’ ]+ $ /;
167
160
my $ data = try from-json $ body . decode;
168
161
without $ data {
169
- $ response . status = 400 ; $ response . close ;
162
+ $ response . status = 400 ; $ response . close ( ‘ Invalid JSON ’ ) ;
170
163
return
171
164
}
165
+ if $ data <zen >: exists {
166
+ my $ text = “ Webhook for { $ data <repository ><full_name >} is now ”
167
+ ~ ($ data <hook ><active >?? ‘ active’ !! ‘ inactive’ ) ~ ‘ ! ’
168
+ ~ $ data <zen >;
169
+ $ squashable . irc. send: : $ text , where => $ CHANNEL ; # TODO race?
170
+ }
171
+ if now ! ~~ squashathon-range $ next {
172
+ $ response . status = 200 ; $ response . close ;
173
+ return
174
+ }
175
+ my $ file = $ request . headers<X-GitHub-Delivery >;
176
+ mkdir $ PATH . add(“ $ next” );
177
+ spurt $ PATH . add(“ $ next /$ file” ), $ body if $ file ~~ /^ [<.xdigit >| ‘-’ ]+ $ /;
178
+
172
179
$ channel . send: $ request . headers<X-GitHub-Event > => $ data ;
173
180
$ response . headers<Content-Type > = ' text/plain' ;
174
181
$ response . status = 200 ;
175
182
$ response . close
176
183
}
177
184
178
- my $ squashable = Squashable. new ;
179
185
my % state ;
180
186
try set-next-squashathon;
181
187
if $ next-event . defined and $ PATH . add(“ $ next-event /state” ). e {
0 commit comments