finished 1st round of refactoring
authorMichael Wallner <mike@php.net>
Tue, 9 Jun 2015 19:35:04 +0000 (21:35 +0200)
committerMichael Wallner <mike@php.net>
Tue, 9 Jun 2015 19:35:04 +0000 (21:35 +0200)
app/Controller/Github/Hook/Receive.php
app/Controller/Github/Release.php
app/Github/API.php
app/Pharext/Package.php

index 30a744e4ff3d5f69b844b9aca0ae8fe9f1c7fc02..3dc519a36290716b9ad0993a68f90775bd7d3dc6 100644 (file)
@@ -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;
-       }
-
 }
index f0dd55f840c3498c255515f14e0ea39886a4a6eb..32da9b5dd5f109ea29e4502701ec4fa00ef99951 100644 (file)
@@ -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"))) {
index c7a2b05075f18387fcc7878688aada799475642b..0ae7655e1f99e9606c5659950636281bb9ddeb01 100644 (file)
@@ -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);
index bb0d92ca2cbb7aa808bbb3e7bee7e15ace0b9eb4..fb91d368b932ad2a53b13a7849acf8916da4dca5 100644 (file)
@@ -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();
        }