X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FController%2FGithub%2FRepo.php;h=64fbb9dbb67459bcac988e5d9f5eb31cfaa0809e;hb=2198c781a021d85ee845f2f4b2f5c322f73e6bd5;hp=02ab7a94bd1e4202bb6a82b745969a115a68c370;hpb=7f4e70ea88d180cfa25f25f3846f842c5958ebf4;p=pharext%2Fpharext.org diff --git a/app/Controller/Github/Repo.php b/app/Controller/Github/Repo.php index 02ab7a9..64fbb9d 100644 --- a/app/Controller/Github/Repo.php +++ b/app/Controller/Github/Repo.php @@ -3,69 +3,29 @@ 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")); - } - $this->app->display("github/repo"); - } - } + $this->github->readRepo("$owner/$name")->then( + new RepoCallback($this->github) + )->done(function($result) use($owner, $name) { + list($repo) = $result; + $hook = $this->github->checkRepoHook($repo); - function repoCallback($repo, $links) { - $this->app->getView()->addData(compact("repo")); - settype($repo->tags, "object"); - $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) { - $repo->hooks = $hooks; - }); - $this->github->fetchTags($repo->full_name, 1, $this->createTagsCallback($repo)); - $this->github->fetchReleases($repo->full_name, 1, $this->createReleasesCallback($repo)); - $this->github->fetchContents($repo->full_name, null, $this->createContentsCallback($repo)); - } + $this->app->getView()->addData(compact("owner", "name", "repo", "hook")); + }); + $this->github->drain(); + } - 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; - } - }; - } + if (($modal = $this->app->getRequest()->getQuery("modal"))) { + $action = $this->app->getRequest()->getQuery($modal); + $this->app->getView()->addData(compact("modal", "action")); + } - 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; - } - }; - } - - function createContentsCallback($repo) { - return function($tree) use($repo) { - foreach ($tree as $entry) { - if ($entry->type !== "file" || $entry->size <= 0) { - continue; - } - if ($entry->name === "config.m4" || fnmatch("config?.m4", $entry->name)) { - $repo->config_m4 = $entry->name; - } elseif ($entry->name === "package.xml" || $entry->name === "package2.xml") { - $repo->package_xml = $entry->name; - } elseif ($entry->name === "pharext_package.php") { - $repo->pharext_package_php = $entry->name; - } - } - }; + $this->app->display("github/repo"); } }