Skip to content

Commit 95803e5

Browse files
committed
Process ping payload to test webhooks
Issue #243
1 parent 11af308 commit 95803e5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

bin/Squashable.p6

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ use JSON::Fast;
139139
my %config = from-json slurp CONFIG;
140140
my $server = HTTP::Server::Async.new: |(%config<squashable><host port>:p).Capture;
141141
my $channel = Channel.new;
142+
my $squashable = Squashable.new;
142143

143144
# TODO failures here will blow up (or get ignored) without proper handling
144145
$server.handler: sub ($request, $response) {
@@ -147,11 +148,6 @@ $server.handler: sub ($request, $response) {
147148
$response.status = 500; $response.close;
148149
return
149150
}
150-
if now !~~ squashathon-range $next {
151-
$response.status = 200; $response.close;
152-
return
153-
}
154-
155151
use Digest::SHA;
156152
use Digest::HMAC;
157153
my $body = $request.data;
@@ -161,21 +157,31 @@ $server.handler: sub ($request, $response) {
161157
$response.status = 400; $response.close(Signatures didn't match);
162158
return
163159
}
164-
my $file = $request.headers<X-GitHub-Delivery>;
165-
mkdir $PATH.add($next);
166-
spurt $PATH.add($next/$file), $body if $file ~~ /^ [<.xdigit>|‘-’]+ $/;
167160
my $data = try from-json $body.decode;
168161
without $data {
169-
$response.status = 400; $response.close;
162+
$response.status = 400; $response.close(Invalid JSON);
170163
return
171164
}
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+
172179
$channel.send: $request.headers<X-GitHub-Event> => $data;
173180
$response.headers<Content-Type> = 'text/plain';
174181
$response.status = 200;
175182
$response.close
176183
}
177184

178-
my $squashable = Squashable.new;
179185
my %state;
180186
try set-next-squashathon;
181187
if $next-event.defined and $PATH.add($next-event/state).e {

0 commit comments

Comments
 (0)