X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FController%2FGithub.php;h=364f0e584424fa2a1438605f746f14ecf655c5b6;hb=77b6c7f9f75740e15d745d34e7263111a73391a8;hp=0dfc5b00d0e09ea017a2e536a95219beead41216;hpb=4c462ab66e6c65c15df7bd5fe6d2673884c639a0;p=pharext%2Fpharext.org diff --git a/app/Controller/Github.php b/app/Controller/Github.php index 0dfc5b0..364f0e5 100644 --- a/app/Controller/Github.php +++ b/app/Controller/Github.php @@ -8,7 +8,7 @@ use app\Session; use app\Web; use http\QueryString; -use http\Url; +use http\Header; abstract class Github implements Controller { @@ -26,7 +26,7 @@ abstract class Github implements Controller * @var \app\Session */ protected $session; - + function __construct(Web $app, API $github, Session $session) { $this->app = $app; $this->github = $github; @@ -36,6 +36,15 @@ abstract class Github implements Controller "title" => "Github" ]); $this->app->getView()->registerFunction("check", [$this, "checkRepoHook"]); + + if (($header = $this->app->getRequest()->getHeader("Cache-Control", Header::class))) { + $params = $header->getParams(); + if (!empty($params["no-cache"])) { + $this->github->setMaxAge(0); + } elseif (!empty($params["max-age"])) { + $this->github->setMaxAge($params["max-age"]["value"]); + } + } } protected function checkToken() { @@ -49,30 +58,19 @@ abstract class Github implements Controller return false; } + /** + * Check if the pharext webhook is set for the repo and return it + * @param object $repo + * @return int hook id + */ function checkRepoHook($repo) { if ($repo->hooks) { foreach ($repo->hooks as $hook) { if ($hook->name === "web" && $hook->config->url === $this->github->getConfig()->hook->url) { - return true; + return $hook; } } } - return false; + return null; } - - function createLinkGenerator($links) { - return function($which) use($links) { - if (!isset($links[$which])) { - if ($which !== "next" || !isset($links["last"])) { - return null; - } else { - $which = "last"; - } - } - $url = new Url($links[$which], null, 0); - $qry = new QueryString($url->query); - return $qry->getInt("page", 1); - }; - } - }