2nd round
[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 class Release extends Github
9 {
10 function __invoke(array $args = null) {
11 extract($args);
12 if ($this->checkToken()) {
13 $this->github->readRepo("$owner/$name")->then(
14 new RepoCallback($this->github)
15 )->then(function($result) use(&$repo) {
16 list($repo,,,$releases) = $result;
17 $config = $this->app->getRequest()->getForm();
18
19 foreach ($releases as $release) {
20 if ($release->tag_name === $config["tag"]) {
21 return $this->github->uploadAssetForRelease($repo, $release, $config);
22 }
23 }
24
25 return $this->github->createReleaseFromTag($repo, $config["tag"], $config);
26 })->done(function() use(&$repo) {
27 $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/" . $repo->full_name));
28 });
29
30 $this->github->drain();
31
32 $hook = $this->github->checkRepoHook($repo);
33 $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
34
35 if (($modal = $this->app->getRequest()->getQuery("modal"))) {
36 $action = $this->app->getRequest()->getQuery($modal);
37 $this->app->getView()->addData(compact("modal", "action"));
38 }
39
40 $this->app->display("github/repo");
41 }
42 }
43 }