From 7f4e70ea88d180cfa25f25f3846f842c5958ebf4 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 1 May 2015 14:10:05 +0200 Subject: [PATCH] repo checks --- app/Controller/Github/Repo.php | 21 ++++++++++ app/Github/API.php | 5 +++ app/Github/Exception/ContentsFetchFailed.php | 12 ++++++ ...Failed.php.php => ReleasesFetchFailed.php} | 0 app/Github/Fetch/Contents.php | 28 +++++++++++++ app/Github/Fetch/Releases.php | 1 - app/views/github/repo.phtml | 41 +++++++++++++++---- 7 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 app/Github/Exception/ContentsFetchFailed.php rename app/Github/Exception/{ReleasesFetchFailed.php.php => ReleasesFetchFailed.php} (100%) create mode 100644 app/Github/Fetch/Contents.php diff --git a/app/Controller/Github/Repo.php b/app/Controller/Github/Repo.php index 0c33a01..02ab7a9 100644 --- a/app/Controller/Github/Repo.php +++ b/app/Controller/Github/Repo.php @@ -24,8 +24,12 @@ class Repo extends Github 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)); } function createReleasesCallback($repo) { @@ -47,4 +51,21 @@ class Repo extends Github } }; } + + 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; + } + } + }; + } } diff --git a/app/Github/API.php b/app/Github/API.php index 381533d..0f8b95c 100644 --- a/app/Github/API.php +++ b/app/Github/API.php @@ -139,4 +139,9 @@ class API $fetch->setPage($page); return $fetch($callback); } + + function fetchContents($repo, $path, callable $callback) { + $fetch = new Fetch\Contents($this, compact("repo", "path")); + return $fetch($callback); + } } diff --git a/app/Github/Exception/ContentsFetchFailed.php b/app/Github/Exception/ContentsFetchFailed.php new file mode 100644 index 0000000..cd2abd7 --- /dev/null +++ b/app/Github/Exception/ContentsFetchFailed.php @@ -0,0 +1,12 @@ +url->mod(sprintf("/repos/%s/contents/%s", + $this->args["repo"], $this->args["path"])); + return new Request("GET", $url, [ + "Accept" => "application/vnd.github.v3+json", + "Authorization" => "token " . $this->api->getToken() + ]); + } + + function getException($message, $code, $previous = null) { + return new ContentsFetchFailed($message, $code, $previous); + } + + function getCacheKey() { + return $this->api->getCacheKey(sprintf("contents:%s:%s", + $this->args["repo"], $this->args["path"])); + } +} diff --git a/app/Github/Fetch/Releases.php b/app/Github/Fetch/Releases.php index fa9c012..bd9f8f9 100644 --- a/app/Github/Fetch/Releases.php +++ b/app/Github/Fetch/Releases.php @@ -17,7 +17,6 @@ class Releases extends Fetch "page" => $this->getPage(), ]) ], 0); - echo $url."
"; return new Request("GET", $url, [ "Accept" => "application/vnd.github.v3+json", "Authorization" => "token " . $this->api->getToken(), diff --git a/app/views/github/repo.phtml b/app/views/github/repo.phtml index 4477e8a..c3fdba4 100644 --- a/app/views/github/repo.phtml +++ b/app/views/github/repo.phtml @@ -64,7 +64,13 @@

Has a config*.m4 file?

-

YES

+

+ config_m4)) : ?> + YES + + NO + +

@@ -73,7 +79,13 @@

Has a package*.xml file?

-

NO

+

+ package_xml)) : ?> + YES + + NO + +

@@ -82,7 +94,13 @@

Has a pharext_package.php file?

-

YES

+

+ pharext_package_php)) : ?> + YES + + NO + +

@@ -91,7 +109,11 @@

Is the pharext hook enabled?

-

NO

+ check($repo)) : ?> + YES + + NO +
@@ -99,16 +121,21 @@
- +
- +

Release History

+tags) || !count((array) $repo->tags)) : ?> + + tags as $name => $v) : ?>
"> @@ -151,6 +178,4 @@
-
- -- 2.30.2