publish release *after* uploading the asset
[pharext/pharext.org] / app / Github / API / Releases / CreateRelease.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
9 class CreateRelease extends Call
10 {
11 function enqueue(callable $callback) {
12 $url = $this->url->mod("/repos/". $this->args["repo"] ."/releases");
13 $request = new Request("POST", $url, [
14 "Authorization" => "token ". $this->api->getToken(),
15 "Accept" => $this->config->api->accept,
16 "Content-Type" => "application/json",
17 ]);
18 $request->getBody()->append(json_encode([
19 "tag_name" => $this->args["tag"],
20 "draft" => true,
21 ]));
22 $this->api->getClient()->enqueue($request, function($response) use($callback) {
23 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
24 throw new RequestException($response);
25 }
26 $this->result = [$json];
27 $callback($json);
28 return true;
29 });
30 }
31 }