ac2ce37d5916cebdb2a3fc68e8cb39f4c2fa1202
[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 $this->app->getView()->addData(compact("owner", "name"));
12 if ($this->checkToken()) {
13 $this->github->readRepo(
14 "$owner/$name",
15 [$this, "repoCallback"]
16 )->send();
17
18 if (($modal = $this->app->getRequest()->getQuery("modal"))) {
19 $this->app->getView()->addData(compact("modal") + [
20 "action" => $this->app->getRequest()->getQuery($modal)
21 ]);
22 }
23
24 $this->app->display("github/repo");
25 }
26 }
27
28 function repoCallback($repo) {
29 $this->app->getView()->addData(compact("repo") + [
30 "title" => "Github: {$repo->name}"
31 ]);
32 settype($repo->tags, "object");
33 $this->github->listHooks($repo->full_name, function($hooks) use($repo) {
34 $repo->hooks = $hooks;
35 $this->app->getView()->addData(["hook" => $this->checkRepoHook($repo)]);
36 });
37 $this->github->listTags($repo->full_name, 1, $this->createTagsCallback($repo));
38 $this->github->listReleases($repo->full_name, 1, $this->createReleasesCallback($repo));
39 $this->github->readContents($repo->full_name, null, $this->createContentsCallback($repo));
40 }
41
42 function createReleasesCallback($repo) {
43 return function($releases, $links) use($repo) {
44 foreach ($releases as $release) {
45 $tag = $release->tag_name;
46 settype($repo->tags->$tag, "object");
47 $repo->tags->$tag->release = $release;
48 $this->github->listReleaseAssets($repo->full_name, $release->id, function($assets) use($release) {
49 $release->assets = $assets;
50 });
51 }
52 };
53 }
54
55 function createTagsCallback($repo) {
56 return function($tags, $links) use ($repo) {
57 foreach ($tags as $tag) {
58 $name = $tag->name;
59 settype($repo->tags->$name, "object");
60 $repo->tags->$name->tag = $tag;
61 }
62 };
63 }
64
65 function createContentsCallback($repo) {
66 return function($tree) use($repo) {
67 foreach ($tree as $entry) {
68 if ($entry->type !== "file" || $entry->size <= 0) {
69 continue;
70 }
71 if ($entry->name === "config.m4" || fnmatch("config?.m4", $entry->name)) {
72 $repo->config_m4 = $entry->name;
73 } elseif ($entry->name === "package.xml" || $entry->name === "package2.xml") {
74 $repo->package_xml = $entry->name;
75 } elseif ($entry->name === "pharext_package.php") {
76 $repo->pharext_package_php = $entry->name;
77 }
78 }
79 };
80 }
81 }