X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FGithub%2FAPI.php;h=9f37c4f2d56410af18e8a83ecd4769840625c64d;hb=1097a4f83de3562c3518f31b168448c2c2ac0451;hp=522cf146c6b6090872917897c904d52270b1101e;hpb=bc779094fcd9c484492979bc73f04ba0cf914c85;p=pharext%2Fpharext.org diff --git a/app/Github/API.php b/app/Github/API.php index 522cf14..9f37c4f 100644 --- a/app/Github/API.php +++ b/app/Github/API.php @@ -5,6 +5,7 @@ namespace app\Github; use app\Github\API; use app\Github\Storage; use app\Github\Exception; +use app\Pharext; use merry\Config; @@ -224,7 +225,12 @@ class API $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); @@ -234,4 +240,30 @@ class API $call = new API\Releases\ListReleaseAssets($this, compact("repo", "id")); return $call($callback); } + + function uploadAssetForRelease($repo, $release, $config, callable $callback) { + return $this->listHooks($repo->full_name, function($hooks) use($release, $repo, $config, $callback) { + $repo->hooks = $hooks; + $hook = $this->checkRepoHook($repo); + $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $config ?: $hook->config); + $name = sprintf("%s-%s.ext.phar", $repo->name, $release->tag_name); + $url = uri_template($release->upload_url, compact("name")); + $this->createReleaseAsset($url, $phar, "application/phar", function($json) use($release, $repo, $callback) { + if ($release->draft) { + $this->publishRelease($repo->full_name, $release->id, $release->tag_name, function($json) use($callback) { + $callback($json); + }); + } else { + $callback($json); + } + }); + }); + } + + function createReleaseFromTag($repo, $tag_name, $config, callable $callback) { + return $this->createRelease($repo->full_name, $tag_name, function($json) use($repo, $callback) { + $this->uploadAssetForRelease($repo, $json, $config, $callback); + }); + } + }