3 namespace app\Github\API\Hooks
;
5 use app\Github\API\Call
;
6 use app\Github\Exception\RequestException
;
7 use http\Client\Request
;
9 class CreateHook
extends Call
11 function enqueue(callable
$callback) {
12 $url = $this->url
->mod("./repos/". $this->args
["repo"] ."/hooks");
13 $request = new Request("POST", $url, [
14 "Authorization" => "token " . $this->api
->getToken(),
15 "Accept" => $this->config
->api
->accept
,
16 "Content-Type" => "application/json",
20 if (!empty($this->args
["conf"]["tag"])) {
23 if (!empty($this->args
["conf"]["release"])) {
24 $events[] = "release";
27 $request->getBody()->append(json_encode([
31 "zend" => !empty($this->args
["conf"]["zend"]),
32 "pecl" => !empty($this->args
["conf"]["pecl"]),
33 "url" => $this->config
->hook
->url
,
34 "content_type" => $this->config
->hook
->content_type
,
35 "insecure_ssl" => $this->config
->hook
->insecure_ssl
,
36 "secret" => $this->config
->client
->secret
, // FIXME: bad idea?
40 $this->api
->getClient()->enqueue($request, function($response) use($callback) {
41 if ($response->getResponseCode() >= 400 ||
null === ($json = json_decode($response->getBody()))) {
42 throw new RequestException($response);
44 $this->result
= [$json];