X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FController%2FGithub%2FRepo.php;h=3c166ad51c5c8812fbf90e87a6fccd7820707868;hb=303950054385d4c55cfef9a8828ee79420b7366e;hp=8caba2af43ef2f7412a08b15a40be068451feabb;hpb=07b87ac26f62bc3c069bb16983fe7500272e19b4;p=pharext%2Fpharext.org diff --git a/app/Controller/Github/Repo.php b/app/Controller/Github/Repo.php index 8caba2a..3c166ad 100644 --- a/app/Controller/Github/Repo.php +++ b/app/Controller/Github/Repo.php @@ -3,75 +3,32 @@ 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); - $this->app->getView()->addData(compact("owner", "name")); - if ($this->checkToken()) { - $this->github->fetchRepo( - "$owner/$name", - [$this, "repoCallback"] - )->send(); - - if (($modal = $this->app->getRequest()->getQuery("modal"))) { - $this->app->getView()->addData(compact("modal") + [ - "action" => $this->app->getRequest()->getQuery($modal) - ]); - } - - $this->app->display("github/repo"); + if (!$this->checkToken()) { + return; } - } - function repoCallback($repo) { - $this->app->getView()->addData(compact("repo") + [ - "title" => "Github: {$repo->name}" - ]); - settype($repo->tags, "object"); - $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) { - $repo->hooks = $hooks; + extract($args); + $this->github->readRepo("$owner/$name")->then( + new RepoCallback($this->github) + )->done(function($result) use($owner, $name) { + list($repo) = $result; + $hook = $this->github->checkRepoHook($repo); + + $this->app->getView()->addData(compact("owner", "name", "repo", "hook")); }); - $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)); - } - 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; - } - }; - } + $this->github->drain(); - 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; - } - } - }; + 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"); } }