1fb8231cdfde9c8d7d1de044426dfdda1955ea52
[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
23 $request->getBody()->append(json_encode(compact("events")));
24 $this->api->getClient()->enqueue($request, function($response) use($callback) {
25 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
26 throw new \app\Github\Exception\RequestException($response);
27 }
28 $this->result = [$json];
29 $callback($json);
30 return true;
31 });
32 }
33 }