X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FGithub%2FAPI.php;h=9f37c4f2d56410af18e8a83ecd4769840625c64d;hb=1097a4f83de3562c3518f31b168448c2c2ac0451;hp=e56ada1ecb3941079ddf9a176a07130cc08ccabd;hpb=8b207c90c6c49876775ab61908f45510baf9981a;p=pharext%2Fpharext.org diff --git a/app/Github/API.php b/app/Github/API.php index e56ada1..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; @@ -239,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); + }); + } + }