3 namespace app\Controller\Github\Repo
;
5 use app\Controller\Github
;
7 class Hook
extends Github
9 function __invoke(array $args = null) {
10 switch ($args["action"]) {
12 $this->addHook($args["owner"], $args["name"]);
16 $this->delHook($args["owner"], $args["name"]);
21 function addHook($owner, $repo) {
22 $this->github
->createRepoHook("$owner/$repo", function($hook) use($owner, $repo) {
23 if (($cache = $this->github
->getCacheStorage())) {
24 $cache->del($this->github
->getCacheKey("hooks:$owner/$repo"));
26 if (($back = $this->app
->getRequest()->getForm("returnback")) && isset($this->session
->previous
)) {
27 $this->app
->redirect($this->app
->getBaseUrl()->mod($this->session
->previous
));
29 $this->app
->redirect($this->app
->getBaseUrl()->mod("./github/repo/$owner/$repo"));
34 function delHook($owner, $repo) {
35 $this->github
->fetchRepo("$owner/$repo", function($repo) {
36 $this->github
->fetchHooks($repo->full_name
, function($hooks) use($repo) {
37 $repo->hooks
= $hooks;
38 if (($id = $this->checkRepoHook($repo))) {
39 $this->github
->deleteRepoHook($repo->full_name
, $id, function() use($repo) {
40 if (($cache = $this->github
->getCacheStorage())) {
41 $cache->del($this->github
->getCacheKey("hooks:" . $repo->full_name
));
43 if (($back = $this->app
->getRequest()->getForm("returnback")) && isset($this->session
->previous
)) {
44 $this->app
->redirect($this->app
->getBaseUrl()->mod($this->session
->previous
));
46 $this->app
->redirect($this->app
->getBaseUrl()->mod("./github/repo/" . $repo->full_name
));