3 namespace app\Controller
;
13 abstract class Github
implements Controller
21 * @var \app\Github\API
30 function __construct(Web
$app, API
$github, Session
$session) {
32 $this->github
= $github;
33 $this->session
= $session;
34 $this->app
->getView()->addData(compact("session") +
[
35 "location" => "github",
38 $this->app
->getView()->registerFunction("check", [$this, "checkRepoHook"]);
41 protected function checkToken() {
42 if ($this->github
->hasToken()) {
45 $this->app
->redirect($this->app
->getBaseUrl()->mod([
46 "path" => "github/signin",
47 "query" => new QueryString(["returnto" => $this->session
->current
])
53 * Check if the pharext webhook is set for the repo and return its id
57 function checkRepoHook($repo) {
59 foreach ($repo->hooks
as $hook) {
60 if ($hook->name
=== "web" && $hook->config
->url
=== $this->github
->getConfig()->hook
->url
) {
68 function createLinkGenerator($links) {
69 return function($which) use($links) {
70 if (!isset($links[$which])) {
71 if ($which !== "next" ||
!isset($links["last"])) {
77 $url = new Url($links[$which], null, 0);
78 $qry = new QueryString($url->query
);
79 return $qry->getInt("page", 1);