X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FController%2FGithub%2FRepoHook.php;h=6733b3f680e6b3cc247a048b14d4fc0bb41168a9;hb=a2af03951ac7fbd032609d0044c0a85704b77771;hp=8ab1eed050a04575af2855b8e30e0bc078a9b5d7;hpb=25b99959b9e66d00681092977c23b5df32ead5f4;p=pharext%2Fpharext.org diff --git a/app/Controller/Github/RepoHook.php b/app/Controller/Github/RepoHook.php index 8ab1eed..6733b3f 100644 --- a/app/Controller/Github/RepoHook.php +++ b/app/Controller/Github/RepoHook.php @@ -34,35 +34,50 @@ class RepoHook extends Github function addHook($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")); - } - if (($back = $this->app->getRequest()->getForm("returnback")) && isset($this->session->previous)) { - $this->app->redirect($this->app->getBaseUrl()->mod($this->session->previous)); - } else { - $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/$owner/$repo")); - } + $call = $this->github->createRepoHook("$owner/$repo", $hook_conf, function($hook) use($owner, $repo, &$call) { + $call->dropFromCache(); + $this->redirectBack("$owner/$repo"); + }); + $call->send(); + } + + function updateHook($owner, $repo) { + $this->github->fetchRepo("$owner/$repo", function($repo) { + $call = $this->github->fetchHooks($repo->full_name, function($hooks, $links) use($repo, &$call) { + $repo->hooks = $hooks; + if (($hook = $this->checkRepoHook($repo))) { + $hook_conf = $this->app->getRequest()->getForm(); + $this->github->updateRepoHook($repo->full_name, $hook->id, $hook_conf, function($changed_hook) use($repo, $hook, $hooks, $links, $call) { + foreach ($changed_hook as $key => $val) { + $hook->$key = $val; + } + $call->saveToCache([$hooks, $links]); + $this->redirectBack($repo->full_name); + }); + } + }); })->send(); } function delHook($owner, $repo) { $this->github->fetchRepo("$owner/$repo", function($repo) { - $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) { + $call = $this->github->fetchHooks($repo->full_name, function($hooks) use($repo, &$call) { $repo->hooks = $hooks; if (($hook = $this->checkRepoHook($repo))) { - $this->github->deleteRepoHook($repo->full_name, $hook->id, function() use($repo) { - if (($cache = $this->github->getCacheStorage())) { - $cache->del($this->github->getCacheKey("hooks:" . $repo->full_name)); - } - if (($back = $this->app->getRequest()->getForm("returnback")) && isset($this->session->previous)) { - $this->app->redirect($this->app->getBaseUrl()->mod($this->session->previous)); - } else { - $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/" . $repo->full_name)); - } + $this->github->deleteRepoHook($repo->full_name, $hook->id, function() use($repo, $call) { + $call->dropFromCache(); + $this->redirectBack($repo->full_name); }); } }); })->send(); } + + function redirectBack($repo) { + if (($back = $this->app->getRequest()->getForm("returnback")) && isset($this->session->previous)) { + $this->app->redirect($this->app->getBaseUrl()->mod($this->session->previous)); + } else { + $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/" . $repo)); + } + } }