publish release *after* uploading the asset
[pharext/pharext.org] / app / Github / API / Hooks / UpdateHook.php
1 <?php
2
3 namespace app\Github\API\Hooks;
4
5 class UpdateHook extends \app\Github\API\Call
6 {
7 function enqueue(callable $callback) {
8 $url = $this->url->mod(uri_template("./repos/{+repo}/hooks{/id}", $this->args));
9 $request = new \http\Client\Request("PATCH", $url, [
10 "Authorization" => "token ". $this->api->getToken(),
11 "Accept" => $this->config->api->accept,
12 "Content-Type" => "application/json",
13 ]);
14
15 $events = [];
16 if (!empty($this->args["conf"]["tag"])) {
17 $events[] = "create";
18 }
19 if (!empty($this->args["conf"]["release"])) {
20 $events[] = "release";
21 }
22 $config = [
23 "zend" => (int)!empty($this->args["conf"]["zend"]),
24 "pecl" => (int)!empty($this->args["conf"]["pecl"]),
25 "url" => $this->config->hook->url,
26 "content_type" => $this->config->hook->content_type,
27 "insecure_ssl" => $this->config->hook->insecure_ssl,
28 "secret" => $this->config->client->secret, // FIXME: bad idea?
29 ];
30
31 $request->getBody()->append(json_encode(compact("events", "config")));
32 $this->api->getClient()->enqueue($request, function($response) use($callback) {
33 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
34 throw new \app\Github\Exception\RequestException($response);
35 }
36 $this->result = [$json];
37 $callback($json);
38 return true;
39 });
40 }
41 }