flush
[pharext/pharext.org] / app / Controller / Github / Repo / Hook.php
index 7bfb54565bd5980264afde502197c404196965d1..fac64502fa58d64fa9dafa8656ac79377b30cd68 100644 (file)
@@ -7,19 +7,32 @@ use app\Controller\Github;
 class Hook extends Github
 {
        function __invoke(array $args = null) {
-               switch ($args["action"]) {
-                       case "add":
-                               $this->addHook($args["owner"], $args["name"]);
-                               break;
-                       
-                       case "del":
-                               $this->delHook($args["owner"], $args["name"]);
-                               break;
+               if ($this->checkToken()) {
+                       if ($this->app->getRequest()->getRequestMethod() != "POST") {
+                               // user had to re-authenticate, and was redirected here
+                               $this->app->redirect($this->app->getBaseUrl()->mod([
+                                       "path" => "./github/repo/" . $args["owner"] ."/". $args["name"],
+                                       "query" => "modal=hook&hook=" . $args["action"]
+                               ]));
+                       } else switch ($args["action"]) {
+                               case "upd":
+                                       $this->updateHook($args["owner"], $args["name"]);
+                                       break;
+                               
+                               case "add":
+                                       $this->addHook($args["owner"], $args["name"]);
+                                       break;
+
+                               case "del":
+                                       $this->delHook($args["owner"], $args["name"]);
+                                       break;
+                       }
                }
        }
        
        function addHook($owner, $repo) {
-               $this->github->createRepoHook("$owner/$repo", function($hook) use($owner, $repo) {
+               $hook_conf = $this->app->getRequest()->getForm();
+               $this->github->createRepoHook("$owner/$repo", $hook_conf, function($hook) use($owner, $repo) {
                        if (($cache = $this->github->getCacheStorage())) {
                                $cache->del($this->github->getCacheKey("hooks:$owner/$repo"));
                        }