yet another github api refactoring
[pharext/pharext.org] / app / Controller / Github / Repo.php
index 0c33a016c4cbc643bfeeaf7a049c47df5ee0627d..813b942bf0c2ec7f72345f29049b2ef9977070d5 100644 (file)
@@ -3,48 +3,24 @@
 namespace app\Controller\Github;
 
 use app\Controller\Github;
+use app\Github\API\Repos\RepoCallback;
 
 class Repo extends Github
 {
        function __invoke(array $args = null) {
                extract($args);
                if ($this->checkToken()) {
-                       try {
-                               $this->github->fetchRepo(
-                                       "$owner/$name",
-                                       [$this, "repoCallback"]
-                               )->send();
-                       } catch (\app\Github\Exception $exception) {
-                               $this->app->getView()->addData(compact("exception", "owner", "name"));
+                       list($repo) = $this->github->readRepo("$owner/$name", new RepoCallback($this->github))->send();
+                       $hook = $this->github->checkRepoHook($repo);
+                       
+                       $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
+                       
+                       if (($modal = $this->app->getRequest()->getQuery("modal"))) {
+                               $action = $this->app->getRequest()->getQuery($modal);
+                               $this->app->getView()->addData(compact("modal", "action")); 
                        }
+                       
                        $this->app->display("github/repo");
                }
        }
-
-       function repoCallback($repo, $links) {
-               $this->app->getView()->addData(compact("repo"));
-               settype($repo->tags, "object");
-               $this->github->fetchTags($repo->full_name, 1, $this->createTagsCallback($repo));
-               $this->github->fetchReleases($repo->full_name, 1, $this->createReleasesCallback($repo));
-       }
-
-       function createReleasesCallback($repo) {
-               return function($releases, $links) use($repo) {
-                       foreach ($releases as $release) {
-                               $tag = $release->tag_name;
-                               settype($repo->tags->$tag, "object");
-                               $repo->tags->$tag->release = $release;
-                       }
-               };
-       }
-
-       function createTagsCallback($repo) {
-               return function($tags, $links) use ($repo) {
-                       foreach ($tags as $tag) {
-                               $name = $tag->name;
-                               settype($repo->tags->$name, "object");
-                               $repo->tags->$name->tag = $tag;
-                       }
-               };
-       }
 }