3 namespace app\Controller\Github
;
5 use app\Controller\Github
;
7 class RepoHook
extends Github
9 function __invoke(array $args = null) {
10 if ($this->checkToken()) {
11 if ($this->app
->getRequest()->getRequestMethod() != "POST") {
12 // user had to re-authenticate, and was redirected here
13 $this->app
->redirect($this->app
->getBaseUrl()->mod([
14 "path" => "./github/repo/" . $args["owner"] ."/". $args["name"],
15 "query" => "modal=hook&hook=" . $args["action"]
18 switch ($args["action"]) {
20 $this->updateHook($args["owner"], $args["name"]);
24 $this->addHook($args["owner"], $args["name"]);
28 $this->delHook($args["owner"], $args["name"]);
35 function addHook($owner, $repo) {
36 $hook_conf = $this->app
->getRequest()->getForm();
37 $this->github
->createRepoHook("$owner/$repo", $hook_conf, function($hook) use($owner, $repo) {
38 if (($cache = $this->github
->getCacheStorage())) {
39 $cache->del($this->github
->getCacheKey("hooks:$owner/$repo"));
41 if (($back = $this->app
->getRequest()->getForm("returnback")) && isset($this->session
->previous
)) {
42 $this->app
->redirect($this->app
->getBaseUrl()->mod($this->session
->previous
));
44 $this->app
->redirect($this->app
->getBaseUrl()->mod("./github/repo/$owner/$repo"));
49 function delHook($owner, $repo) {
50 $this->github
->fetchRepo("$owner/$repo", function($repo) {
51 $this->github
->fetchHooks($repo->full_name
, function($hooks) use($repo) {
52 $repo->hooks
= $hooks;
53 if (($hook = $this->checkRepoHook($repo))) {
54 $this->github
->deleteRepoHook($repo->full_name
, $hook->id
, function() use($repo) {
55 if (($cache = $this->github
->getCacheStorage())) {
56 $cache->del($this->github
->getCacheKey("hooks:" . $repo->full_name
));
58 if (($back = $this->app
->getRequest()->getForm("returnback")) && isset($this->session
->previous
)) {
59 $this->app
->redirect($this->app
->getBaseUrl()->mod($this->session
->previous
));
61 $this->app
->redirect($this->app
->getBaseUrl()->mod("./github/repo/" . $repo->full_name
));