promise refactoring++
[pharext/pharext.org] / app / Github / API / Releases / PublishRelease.php
1 <?php
2
3 namespace app\Github\API\Releases;
4
5 use app\Github\API\Call;
6 use app\Github\Exception\RequestException;
7 use http\Client\Request;
8 use http\Client\Response;
9
10 class PublishRelease extends Call
11 {
12 function request() {
13 $url = $this->url->mod(uri_template("./repos/{+repo}/releases{/id}", $this->args));
14 $request = new Request("PATCH", $url, [
15 "Authorization" => "token ". $this->api->getToken(),
16 "Accept" => $this->config->api->accept,
17 "Content-Type" => "application/json",
18 ]);
19 $request->getBody()->append(json_encode([
20 "draft" => false,
21 "tag_name" => $this->args["tag"],
22 ]));
23 return $request;
24 }
25
26 function response(Response $response) {
27 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
28 throw new RequestException($response);
29 }
30 return [$json];
31 }
32 }