From: Michael Wallner Date: Tue, 9 Jun 2015 19:35:04 +0000 (+0200) Subject: finished 1st round of refactoring X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=21ea66aa639b5c7bbd63d687d4445f821d1475ec;p=pharext%2Fpharext.org finished 1st round of refactoring --- diff --git a/app/Controller/Github/Hook/Receive.php b/app/Controller/Github/Hook/Receive.php index 30a744e..3dc519a 100644 --- a/app/Controller/Github/Hook/Receive.php +++ b/app/Controller/Github/Hook/Receive.php @@ -7,9 +7,6 @@ use app\Github\API; use app\Model\Accounts; use app\Web; use http\Params; -use pharext\Task; -use pharext\Metadata; -use pharext\SourceDir; class Receive implements Controller { @@ -97,10 +94,15 @@ class Receive implements Controller } $this->setTokenForUser($release->repository->owner->login); - $this->github->uploadAssetForRelease($release->release, $release->repository, null, function($json) use($response) { + $this->github->uploadAssetForRelease( + $release->release, + $release->repository + )->done(function($result) use($response) { + list($created) = $result; $response->setResponseCode(201); - $response->setHeader("Location", $json->url); - })->send(); + $response->setHeader("Location", $created->url); + }); + $this->github->drain(); } private function create($create) { @@ -113,32 +115,14 @@ class Receive implements Controller } $this->setTokenForUser($create->repository->owner->login); - $this->github->createReleaseFromTag($create->repository, $create->ref, null, function($json) use($response) { + $this->github->createReleaseFromTag( + $create->repository, + $create->ref + )->done(function($result) use($response) { + list($created) = $result; $response->setResponseCode(201); - $response->setHeader("Location", $json->url); - })->send(); + $response->setHeader("Location", $created->url); + }); + $this->github->drain(); } - - private function createReleaseAsset($release, $repo) { - $hook = $this->github->checkRepoHook($repo); - $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $hook->config); - return $phar->getFile(); - - $dir = (new Task\GitClone($repo->clone_url, $release->tag_name))->run(); - if (!empty($hook->config->pecl)) { - $src = new SoureDir\Pecl($dir); - } else { - $src = new SourceDir\Git($dir); - } - $meta = Metadata::all() + [ - "name" => $repo->name, - "release" => $release->tag_name, - "license" => $src->getLicense(), - "stub" => "pharext_installer.php", - "type" => !empty($hook->config->zend) ? "zend_extension" : "extension", - ]; - $file = (new Task\PharBuild($src, $meta))->run(); - return $file; - } - } diff --git a/app/Controller/Github/Release.php b/app/Controller/Github/Release.php index f0dd55f..32da9b5 100644 --- a/app/Controller/Github/Release.php +++ b/app/Controller/Github/Release.php @@ -5,34 +5,30 @@ namespace app\Controller\Github; use app\Controller\Github; use app\Github\API\Repos\RepoCallback; - class Release extends Github { function __invoke(array $args = null) { extract($args); if ($this->checkToken()) { - list($repo) = $this->github->readRepo("$owner/$name", function($repo, $links = null) { - call_user_func(new RepoCallback($this->github), $repo, $links); - - $this->github->listReleases($repo->full_name, null, function($releases) use($repo) { - $config = $this->app->getRequest()->getForm(); - foreach ($releases as $r) { - if ($r->tag_name === $config->tag) { - $this->github->uploadAssetForRelease($repo, $r, $config, function() use($repo) { - $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name)); - }); - return; - } + $this->github->readRepo("$owner/$name")->then( + new RepoCallback($this->github) + )->then(function($result) use(&$repo) { + list($repo,,,$releases) = $result; + $config = $this->app->getRequest()->getForm(); + + foreach ($releases as $release) { + if ($release->tag_name === $config["tag"]) { + return $this->github->uploadAssetForRelease($repo, $release, $config); } - - $this->github->createReleaseFromTag($repo, $tag, $config, function() use($repo) { - $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name)); - }); - }); - })->send(); + } + + return $this->github->createReleaseFromTag($repo, $config["tag"], $config); + })->done(function() use(&$repo) { + $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/" . $repo->full_name)); + }); + $this->github->drain(); $hook = $this->github->checkRepoHook($repo); - $this->app->getView()->addData(compact("owner", "name", "repo", "hook")); if (($modal = $this->app->getRequest()->getQuery("modal"))) { diff --git a/app/Github/API.php b/app/Github/API.php index c7a2b05..0ae7655 100644 --- a/app/Github/API.php +++ b/app/Github/API.php @@ -243,11 +243,15 @@ class API return $this->queue(new API\Releases\ListReleaseAssets($this, compact("repo", "id"))); } - function uploadAssetForRelease($repo, $release, $config) { + function uploadAssetForRelease($repo, $release, $config = null) { return $this->listHooks($repo->full_name)->then(function($result) use($release, $repo, $config) { list($repo->hooks) = $result; - $hook = $this->checkRepoHook($repo); - $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $config ?: $hook->config); + $phar = new Pharext\Package( + $repo->clone_url, + $release->tag_name, + $repo->name, + $config ?: (array) $this->checkRepoHook($repo)->config + ); $name = sprintf("%s-%s.ext.phar", $repo->name, $release->tag_name); $url = uri_template($release->upload_url, compact("name")); $promise = $this->createReleaseAsset($url, $phar, "application/phar"); @@ -260,7 +264,7 @@ class API }); } - function createReleaseFromTag($repo, $tag_name, $config) { + function createReleaseFromTag($repo, $tag_name, $config = null) { return $this->createRelease($repo->full_name, $tag_name)->then(function($result) use($repo, $config) { list($release) = $result; return $this->uploadAssetForRelease($repo, $release, $config); diff --git a/app/Pharext/Package.php b/app/Pharext/Package.php index bb0d92c..fb91d36 100644 --- a/app/Pharext/Package.php +++ b/app/Pharext/Package.php @@ -12,7 +12,7 @@ class Package function __construct($git_url, $tag_name, $pkg_name, $options) { $dir = (new Task\GitClone($git_url, $tag_name))->run(); - $src = !empty($options->pecl) + $src = !empty($options["pecl"]) ? new SourceDir\Pecl($dir) : new SourceDir\Git($dir); $meta = Metadata::all() + [ @@ -20,7 +20,7 @@ class Package "release" => $tag_name, "license" => $src->getLicense(), "stub" => "pharext_installer.php", - "type" => !empty($options->zend) ? "zend_extension" : "extension", + "type" => !empty($options["zend"]) ? "zend_extension" : "extension", ]; $this->file = (new Task\PharBuild($src, $meta))->run(); }