add action to post-release a pharext package
[pharext/pharext.org] / app / Controller / Github / Release.php
1 <?php
2
3 namespace app\Controller\Github;
4
5 use app\Controller\Github;
6 use app\Github\API\Repos\RepoCallback;
7
8
9 class Release extends Github
10 {
11 function __invoke(array $args = null) {
12 extract($args);
13 if ($this->checkToken()) {
14 list($repo) = $this->github->readRepo("$owner/$name", function($repo, $links = null) {
15 call_user_func(new RepoCallback($this->github), $repo, $links);
16
17 $this->github->listReleases($repo->full_name, null, function($releases) use($repo) {
18 $tag = $this->app->getRequest()->getForm("tag");
19 foreach ($releases as $r) {
20 if ($r->tag_name === $tag) {
21 $this->github->uploadAssetForRelease($repo, $r, function() use($repo) {
22 $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name));
23 });
24 return;
25 }
26 }
27
28 $this->github->createReleaseFromTag($repo, $tag, function() use($repo) {
29 $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name));
30 });
31 });
32 })->send();
33
34 $hook = $this->github->checkRepoHook($repo);
35
36 $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
37
38 if (($modal = $this->app->getRequest()->getQuery("modal"))) {
39 $action = $this->app->getRequest()->getQuery($modal);
40 $this->app->getView()->addData(compact("modal", "action"));
41 }
42
43 $this->app->display("github/repo");
44 }
45 }
46 }