ngrok basic auth
[pharext/pharext.org] / app / Github / Create / Webhook.php
1 <?php
2
3 namespace app\Github\Create;
4
5 use app\Github\Create;
6 use app\Github\Exception\WebhookCreateFailed;
7 use http\Client\Request;
8
9 class Webhook extends Create
10 {
11 function getRequest() {
12 $url = $this->url->mod("./repos/". $this->args["repo"] ."/hooks");
13 $request = new Request("POST", $url, [
14 "Accept" => "application/vnd.github.v3+json",
15 "Content-Type" => "application/json",
16 "Authorization" => "token " . $this->api->getToken(),
17 ]);
18
19 $request->getBody()->append(json_encode([
20 "name" => "web",
21 "config" => [
22 "url" => $this->config->hook->url,
23 "content_type" => $this->config->hook->content_type,
24 "insecure_ssl" => $this->config->hook->insecure_ssl,
25 "secret" => $this->config->client->secret, // FIXME: bad idea?
26 ]
27 ]));
28 return $request;
29 }
30
31 function getException($message, $code, $previous = null) {
32 return new WebhookCreateFailed($message, $code, $previous);
33 }
34 }