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) {
}
};
}
+
+ 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;
+ }
+ }
+ };
+ }
}
$fetch->setPage($page);
return $fetch($callback);
}
+
+ function fetchContents($repo, $path, callable $callback) {
+ $fetch = new Fetch\Contents($this, compact("repo", "path"));
+ return $fetch($callback);
+ }
}
--- /dev/null
+<?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);
+ }
+}
--- /dev/null
+<?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);
+ }
+}
+++ /dev/null
-<?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);
- }
-}
--- /dev/null
+<?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"]));
+ }
+}
"page" => $this->getPage(),
])
], 0);
- echo $url."<br>";
return new Request("GET", $url, [
"Accept" => "application/vnd.github.v3+json",
"Authorization" => "token " . $this->api->getToken(),
<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; ?>