show already uploaded asset
[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 });
36 $this->github->listTags($repo->full_name, 1, $this->createTagsCallback($repo));
37 $this->github->listReleases($repo->full_name, 1, $this->createReleasesCallback($repo));
38 $this->github->readContents($repo->full_name, null, $this->createContentsCallback($repo));
39 }
40
41 function createReleasesCallback($repo) {
42 return function($releases, $links) use($repo) {
43 foreach ($releases as $release) {
44 $tag = $release->tag_name;
45 settype($repo->tags->$tag, "object");
46 $repo->tags->$tag->release = $release;
47 $this->github->listReleaseAssets($repo->full_name, $release->id, function($assets) use($release) {
48 $release->assets = $assets;
49 });
50 }
51 };
52 }
53
54 function createTagsCallback($repo) {
55 return function($tags, $links) use ($repo) {
56 foreach ($tags as $tag) {
57 $name = $tag->name;
58 settype($repo->tags->$name, "object");
59 $repo->tags->$name->tag = $tag;
60 }
61 };
62 }
63
64 function createContentsCallback($repo) {
65 return function($tree) use($repo) {
66 foreach ($tree as $entry) {
67 if ($entry->type !== "file" || $entry->size <= 0) {
68 continue;
69 }
70 if ($entry->name === "config.m4" || fnmatch("config?.m4", $entry->name)) {
71 $repo->config_m4 = $entry->name;
72 } elseif ($entry->name === "package.xml" || $entry->name === "package2.xml") {
73 $repo->package_xml = $entry->name;
74 } elseif ($entry->name === "pharext_package.php") {
75 $repo->pharext_package_php = $entry->name;
76 }
77 }
78 };
79 }
80 }