$response->getBody()->append("Not published");
return;
}
+ if (!empty($release->release->assets)) {
+ foreach ($release->release->assets as $asset) {
+ if ($asset->content_type === "application/phar") {
+ /* we've already uploaded the asset when we created the release */
+ return;
+ }
+ }
+ }
- $this->uploadAssetForRelease($release->release, $release->repository);
+ $this->uploadAssetForRelease($release->release, $release->repository)->send();
}
private function uploadAssetForRelease($release, $repo) {
$this->setTokenForUser($repo->owner->login);
- $this->github->listHooks($repo->full_name, function($hooks) use($release, $repo) {
+ return $this->github->listHooks($repo->full_name, function($hooks) use($release, $repo) {
$repo->hooks = $hooks;
$asset = $this->createReleaseAsset($release, $repo);
$name = sprintf("%s-%s.ext.phar", $repo->name, $release->tag_name);
$url = uri_template($release->upload_url, compact("name"));
- $this->github->createReleaseAsset($url, $asset, "application/phar", function($json) {
- $response = $this->app->getResponse();
- $response->setResponseCode(201);
- $response->setHeader("Location", $json->url);
+ $this->github->createReleaseAsset($url, $asset, "application/phar", function($json) use($release, $repo) {
+ if ($release->draft) {
+ $this->github->publishRelease($repo->full_name, $release->id, $release->tag_name, function($json) {
+ $response = $this->app->getResponse();
+ $response->setResponseCode(201);
+ $response->setHeader("Location", $json->url);
+ });
+ } else {
+ $response = $this->app->getResponse();
+ $response->setResponseCode(201);
+ $response->setHeader("Location", $json->url);
+ }
});
- })->send();
+ });
}
private function createReleaseAsset($release, $repo) {
return;
}
- $this->createReleaseFromTag($create->ref, $create->repository);
+ $this->createReleaseFromTag($create->ref, $create->repository)->send();
}
private function setTokenForUser($login) {
private function createReleaseFromTag($tag, $repo) {
$this->setTokenForUser($repo->owner->login);
- $this->github->createRelease($repo->full_name, $tag, function($json) {
- $response = $this->app->getResponse();
- $response->setResponseCode(201);
- $response->setHeader("Location", $json->url);
- })->send();
+ return $this->github->createRelease($repo->full_name, $tag, function($json) use($repo) {
+ $this->uploadAssetForRelease($json, $repo);
+ });
}
}
$call = new API\Releases\CreateRelease($this, compact("repo", "tag"));
return $call($callback);
}
-
+
+ function publishRelease($repo, $id, $tag, callable $callback) {
+ $call = new API\Releases\PublishRelease($this, compact("repo", "id", "tag"));
+ return $call($callback);
+ }
+
function createReleaseAsset($url, $asset, $type, callable $callback) {
$call = new API\Releases\CreateReleaseAsset($this, compact("url", "asset", "type"));
return $call($callback);
--- /dev/null
+<?php
+
+namespace app\Github\API\Releases;
+
+use app\Github\API\Call;
+use app\Github\Exception\RequestException;
+use http\Client\Request;
+
+class PublishRelease extends Call
+{
+ function enqueue(callable $callback) {
+ $url = $this->url->mod(uri_template("./repos/{+repo}/releases{/id}", $this->args));
+ $request = new Request("PATCH", $url, [
+ "Authorization" => "token ". $this->api->getToken(),
+ "Accept" => $this->config->api->accept,
+ "Content-Type" => "application/json",
+ ]);
+ $request->getBody()->append(json_encode([
+ "draft" => false,
+ "tag_name" => $this->args["tag"],
+ ]));
+ $this->api->getClient()->enqueue($request, function($response) use($callback) {
+ if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
+ throw new RequestException($response);
+ }
+ $this->result = [$json];
+ $callback($json);
+ return true;
+ });
+ }
+}
\ No newline at end of file