2nd round
[pharext/pharext.org] / app / Controller / Github / Index.php
index f55eb0c2e4cdece8ebbc739199bd5f83705a2937..8b6da0328abe80908c0c2e9dd99c7117854cb553 100644 (file)
@@ -3,33 +3,22 @@
 namespace app\Controller\Github;
 
 use app\Controller\Github;
-
-use http\QueryString;
+use app\Github\API\Repos\ReposCallback;
 
 class Index extends Github
 {
        function __invoke(array $args = null) {
                if ($this->checkToken()) {
-                       try {
-                               $this->github->fetchRepos(
-                                       $this->app->getRequest()->getQuery("page"), 
-                                       [$this, "reposCallback"]
-                               )->send();
-                       } catch (\app\Github\Exception $exception) {
-                               $this->view->addData(compact("exception"));
-                       }
-                       $this->app->display("github/index");
-               }
-       }
-
-       function reposCallback($repos, $links) {
-               $this->app->getView()->addData(compact("repos"));
-               $this->app->getView()->registerFunction("link", $this->createLinkGenerator($links));
-
-               foreach ($repos as $repo) {
-                       $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) {
-                               $repo->hooks = $hooks;
+                       $this->github->listRepos(
+                               $this->app->getRequest()->getQuery("page")
+                       )->then(
+                               new ReposCallback($this->github)
+                       )->done(function($results) {
+                               list(list($repos, $links)) = $results;
+                               $this->app->display("github/index", compact("repos", "links"));
                        });
+                       
+                       $this->github->drain();
                }
        }
 }