repo checks
authorMichael Wallner <mike@php.net>
Fri, 1 May 2015 12:10:05 +0000 (14:10 +0200)
committerMichael Wallner <mike@php.net>
Fri, 1 May 2015 12:10:05 +0000 (14:10 +0200)
app/Controller/Github/Repo.php
app/Github/API.php
app/Github/Exception/ContentsFetchFailed.php [new file with mode: 0644]
app/Github/Exception/ReleasesFetchFailed.php [new file with mode: 0644]
app/Github/Exception/ReleasesFetchFailed.php.php [deleted file]
app/Github/Fetch/Contents.php [new file with mode: 0644]
app/Github/Fetch/Releases.php
app/views/github/repo.phtml

index 0c33a016c4cbc643bfeeaf7a049c47df5ee0627d..02ab7a94bd1e4202bb6a82b745969a115a68c370 100644 (file)
@@ -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;
+                               }
+                       }
+               };
+       }
 }
index 381533d298e8d6d2f2efe54a48a88488505913c6..0f8b95c4780e22e40f31fbe3ba9cf9dc4b2d544c 100644 (file)
@@ -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 (file)
index 0000000..cd2abd7
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace app\Github\Exception;
+
+use app\Github\Exception\RequestException;
+
+class ContentsFetchFailed extends \Exception implements RequestException
+{
+       function __construct($message, $code, $previous = null) {
+               parent::__construct($message ?: "Contents fetch request failed", $code, $previous);
+       }
+}
diff --git a/app/Github/Exception/ReleasesFetchFailed.php b/app/Github/Exception/ReleasesFetchFailed.php
new file mode 100644 (file)
index 0000000..12043de
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace app\Github\Exception;
+
+use app\Github\Exception\RequestException;
+
+class ReleasesFetchFailed extends \Exception implements RequestException
+{
+       function __construct($message, $code, $previous = null) {
+               parent::__construct($message ?: "Releases fetch request failed", $code, $previous);
+       }
+}
diff --git a/app/Github/Exception/ReleasesFetchFailed.php.php b/app/Github/Exception/ReleasesFetchFailed.php.php
deleted file mode 100644 (file)
index 12043de..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-
-namespace app\Github\Exception;
-
-use app\Github\Exception\RequestException;
-
-class ReleasesFetchFailed extends \Exception implements RequestException
-{
-       function __construct($message, $code, $previous = null) {
-               parent::__construct($message ?: "Releases fetch request failed", $code, $previous);
-       }
-}
diff --git a/app/Github/Fetch/Contents.php b/app/Github/Fetch/Contents.php
new file mode 100644 (file)
index 0000000..955cb3c
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace app\Github\Fetch;
+
+use app\Github\Exception\ContentsFetchFailed;
+use app\Github\Fetch;
+use http\Client\Request;
+
+class Contents extends Fetch
+{
+       function getRequest() {
+               $url = $this->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"]));
+       }
+}
index fa9c01201a142369c1554323dc1be0a65457f01b..bd9f8f9afb76d262e970fafc89362e2b4803af4e 100644 (file)
@@ -17,7 +17,6 @@ class Releases extends Fetch
                                "page" => $this->getPage(),
                        ])
                ], 0);
-               echo $url."<br>";
                return new Request("GET", $url, [
                        "Accept" => "application/vnd.github.v3+json",
                        "Authorization" => "token " . $this->api->getToken(),
index 4477e8af54cd71f93fb893d19f8d734c510c87a2..c3fdba41352821bc9003545a3bcd01a08c782425 100644 (file)
                                <p>Has a <code>config*.m4</code> file?</p>
                        </div>
                        <div class="col-md-4 text-center">
-                               <p><span class="label label-info">YES</span></p>
+                               <p>
+                                       <?php if (!empty($repo->config_m4)) : ?>
+                                       <span class="label label-info">YES</span>
+                                       <?php else : ?>
+                                       <span class="label label-warning">NO</span>
+                                       <?php endif; ?>
+                               </p>
                        </div>
                </div>
 
                                <p>Has a <code>package*.xml</code> file?</p>
                        </div>
                        <div class="col-md-4 text-center">
-                               <p><span class="label label-warning">NO</span></p>
+                               <p>
+                                       <?php if (!empty($repo->package_xml)) : ?>
+                                       <span class="label label-info">YES</span>
+                                       <?php else : ?>
+                                       <span class="label label-warning">NO</span>
+                                       <?php endif; ?>
+                               </p>
                        </div>
                </div>
 
                                <p>Has a <code>pharext_package.php</code> file?</p>
                        </div>
                        <div class="col-md-4 text-center">
-                               <p><span class="label label-info">YES</span></p>
+                               <p>
+                                       <?php if (!empty($repo->pharext_package_php)) : ?>
+                                       <span class="label label-info">YES</span>
+                                       <?php else : ?>
+                                       <span class="label label-warning">NO</span>
+                                       <?php endif; ?>
+                               </p>
                        </div>
                </div>
 
                                <p>Is the <code>pharext</code> hook enabled?</p>
                        </div>
                        <div class="col-md-4 text-center">
-                               <p><span class="label label-warning">NO</span></p>
+                                       <?php if ($this->check($repo)) : ?>
+                                       <span class="label label-info">YES</span>
+                                       <?php else : ?>
+                                       <span class="label label-warning">NO</span>
+                                       <?php endif; ?>
                        </div>
                </div>
        </div>
        <div class="col-md-6">
                <div class="row text-center">
                        <div class="col-md-6">
-                               <button class="btn btn-lg btn-block btn-success">Enable Hook</button>
+                               <button class="btn btn-lg btn-block btn-success <?= $this->check($repo) ? "disabled":"" ?>">Enable Hook</button>
                        </div>
                        <div class="col-md-6">
-                               <button class="btn btn-lg btn-block btn-danger disabled">Disable Hook</button>
+                               <button class="btn btn-lg btn-block btn-danger <?= $this->check($repo) ? "":"disabled" ?>">Disable Hook</button>
                        </div>
                </div>
        </div>
 </div>
 
 <h2>Release History</h2>
+<?php if (empty($repo->tags) || !count((array) $repo->tags)) : ?>
+<div class="alert alert-warning" role="alert">
+       <p class="text-danger">No releases or tags found.</p>
+</div>
+<?php endif; ?>
 
 <?php foreach ($repo->tags as $name => $v) : ?>
 <div class="panel panel-<?= empty($v->release) ? "info": "primary" ?>">
 </div>
 <?php endforeach; ?>
 
-<pre><?php var_dump($repo) ?></pre>
-
 <?php endif; ?>