repo checks
[pharext/pharext.org] / app / Controller / Github / Repo.php
1 <?php
2
3 namespace app\Controller\Github;
4
5 use app\Controller\Github;
6
7 class Repo extends Github
8 {
9 function __invoke(array $args = null) {
10 extract($args);
11 if ($this->checkToken()) {
12 try {
13 $this->github->fetchRepo(
14 "$owner/$name",
15 [$this, "repoCallback"]
16 )->send();
17 } catch (\app\Github\Exception $exception) {
18 $this->app->getView()->addData(compact("exception", "owner", "name"));
19 }
20 $this->app->display("github/repo");
21 }
22 }
23
24 function repoCallback($repo, $links) {
25 $this->app->getView()->addData(compact("repo"));
26 settype($repo->tags, "object");
27 $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) {
28 $repo->hooks = $hooks;
29 });
30 $this->github->fetchTags($repo->full_name, 1, $this->createTagsCallback($repo));
31 $this->github->fetchReleases($repo->full_name, 1, $this->createReleasesCallback($repo));
32 $this->github->fetchContents($repo->full_name, null, $this->createContentsCallback($repo));
33 }
34
35 function createReleasesCallback($repo) {
36 return function($releases, $links) use($repo) {
37 foreach ($releases as $release) {
38 $tag = $release->tag_name;
39 settype($repo->tags->$tag, "object");
40 $repo->tags->$tag->release = $release;
41 }
42 };
43 }
44
45 function createTagsCallback($repo) {
46 return function($tags, $links) use ($repo) {
47 foreach ($tags as $tag) {
48 $name = $tag->name;
49 settype($repo->tags->$name, "object");
50 $repo->tags->$name->tag = $tag;
51 }
52 };
53 }
54
55 function createContentsCallback($repo) {
56 return function($tree) use($repo) {
57 foreach ($tree as $entry) {
58 if ($entry->type !== "file" || $entry->size <= 0) {
59 continue;
60 }
61 if ($entry->name === "config.m4" || fnmatch("config?.m4", $entry->name)) {
62 $repo->config_m4 = $entry->name;
63 } elseif ($entry->name === "package.xml" || $entry->name === "package2.xml") {
64 $repo->package_xml = $entry->name;
65 } elseif ($entry->name === "pharext_package.php") {
66 $repo->pharext_package_php = $entry->name;
67 }
68 }
69 };
70 }
71 }