class Index extends Github
{
function __invoke(array $args = null) {
- if ($this->checkToken()) {
- $this->github->listRepos(
- $this->app->getRequest()->getQuery("page")
- )->then(
- new ReposCallback($this->github)
- )->done(function($results) {
- list(list($repos, $links)) = $results;
- $this->app->display("github/index", compact("repos", "links"));
- });
-
- $this->github->drain();
+ if (!$this->checkToken()) {
+ return;
}
+ $this->github->listRepos(
+ $this->app->getRequest()->getQuery("page")
+ )->then(
+ new ReposCallback($this->github)
+ )->done(function($results) {
+ list(list($repos, $links)) = $results;
+ $this->app->display("github/index", compact("repos", "links"));
+ });
+
+ $this->github->drain();
}
}
class Release extends Github
{
function __invoke(array $args = null) {
+ if (!$this->checkToken()) {
+ return;
+ }
+
extract($args);
- if ($this->checkToken()) {
- $this->github->readRepo("$owner/$name")->then(
- new RepoCallback($this->github)
- )->then(function($result) use(&$repo) {
- list($repo,,,$releases) = $result;
- $config = $this->app->getRequest()->getForm();
-
- foreach ($releases as $release) {
- if ($release->tag_name === $config["tag"]) {
- return $this->github->uploadAssetForRelease($repo, $release, $config);
- }
+ $this->github->readRepo("$owner/$name")->then(
+ new RepoCallback($this->github)
+ )->then(function($result) use(&$repo) {
+ list($repo,,,$releases) = $result;
+ $config = $this->app->getRequest()->getForm();
+
+ foreach ($releases as $release) {
+ if ($release->tag_name === $config["tag"]) {
+ return $this->github->uploadAssetForRelease($repo, $release, $config);
}
-
- return $this->github->createReleaseFromTag($repo, $config["tag"], $config);
- })->done(function() use(&$repo) {
- $this->app->redirect($this->app->getBaseUrl()->mod("./github/repo/" . $repo->full_name));
- });
-
- $this->github->drain();
-
- $hook = $this->github->checkRepoHook($repo);
- $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
-
- if (($modal = $this->app->getRequest()->getQuery("modal"))) {
- $action = $this->app->getRequest()->getQuery($modal);
- $this->app->getView()->addData(compact("modal", "action"));
}
- $this->app->display("github/repo");
+ return $this->github->createReleaseFromTag($repo, $config["tag"], $config);
+ })->done(function() use(&$repo) {
+ $this->app->redirect($this->app->getBaseUrl()->mod(":./github/repo/" . $repo->full_name));
+ });
+
+ $this->github->drain();
+
+ $hook = $this->github->checkRepoHook($repo);
+ $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
+
+ if (($modal = $this->app->getRequest()->getQuery("modal"))) {
+ $action = $this->app->getRequest()->getQuery($modal);
+ $this->app->getView()->addData(compact("modal", "action"));
}
+
+ $this->app->display("github/repo");
}
}
class Repo extends Github
{
function __invoke(array $args = null) {
- extract($args);
- if ($this->checkToken()) {
- $this->github->readRepo("$owner/$name")->then(
- new RepoCallback($this->github)
- )->done(function($result) use($owner, $name) {
- list($repo) = $result;
- $hook = $this->github->checkRepoHook($repo);
-
- $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
- });
-
- $this->github->drain();
+ if (!$this->checkToken()) {
+ return;
}
+ extract($args);
+ $this->github->readRepo("$owner/$name")->then(
+ new RepoCallback($this->github)
+ )->done(function($result) use($owner, $name) {
+ list($repo) = $result;
+ $hook = $this->github->checkRepoHook($repo);
+
+ $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
+ });
+
+ $this->github->drain();
+
if (($modal = $this->app->getRequest()->getQuery("modal"))) {
$action = $this->app->getRequest()->getQuery($modal);
$this->app->getView()->addData(compact("modal", "action"));
class RepoHook extends Github
{
function __invoke(array $args = null) {
- if ($this->checkToken()) {
- if ($this->app->getRequest()->getRequestMethod() != "POST") {
- // user had to re-authenticate, and was redirected here
- $this->app->redirect($this->app->getBaseUrl()->mod([
- "path" => "./github/repo/" . $args["owner"] ."/". $args["name"],
- "query" => "modal=hook&hook=" . $args["action"]
- ]));
- } else {
- $this->changeHook($args)->done(function() use($args) {
- $this->redirectBack($args["owner"]."/".$args["name"]);
- });
- $this->github->drain();
- }
+ if (!$this->checkToken()) {
+ return;
+ }
+ if ($this->app->getRequest()->getRequestMethod() != "POST") {
+ // user had to re-authenticate, and was redirected here
+ $this->app->redirect($this->app->getBaseUrl()->mod([
+ "path" => "./github/repo/" . $args["owner"] ."/". $args["name"],
+ "query" => "modal=hook&hook=" . $args["action"]
+ ]));
+ } else {
+ $this->changeHook($args)->done(function() use($args) {
+ $this->redirectBack($args["owner"]."/".$args["name"]);
+ });
+ $this->github->drain();
}
}
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));
+ $this->app->redirect($this->app->getBaseUrl()->mod(":./github/repo/" . $repo));
}
}
}
}
function hasToken() {
- return $this->tokens->get("access_token");
+ if ($this->tokens->get("access_token", $token)) {
+ $access_token = $token->getValue();
+ if (isset($access_token)) {
+ return true;
+ }
+ $this->dropToken();
+ }
+ return false;
}
function setToken($token) {
function fetchToken($code, $state) {
if (!$this->tokens->get("state", $orig_state, true)) {
if (isset($orig_state)) {
- $this->logger->notice("State expired", $orig_state);
+ $this->logger->notice("State expired", compact("state", "orig_state"));
throw new Exception\StateExpired($orig_state->getLTL());
}
throw new Exception\StateNotSet;
$this->request(),
function($response) {
try {
- $this->deferred->resolve($this->response($response));
+ $result = $this->response($response);
+ if (!($result instanceof Promise\PromiseInterface)) {
+ $this->deferred->resolve($result);
+ }
} catch (\Exception $e) {
$this->deferred->reject($e);
}
return false;
}
if (!$cache->get($key, $cached)) {
+ if ($cached) {
+ $this->api->getLogger()->debug(
+ sprintf("Cache-Stale: $this [TTL=%d]", $cached->getTTL()),
+ $this->args);
+ } else {
+ $this->api->getLogger()->debug("Cache-Miss: $this", $this->args);
+ }
return false;
}
if (null !== $this->api->getMaxAge() && $cached->getAge() > $this->api->getMaxAge()) {
+ $this->api->getLogger()->debug("Cache-Refresh: $this", $this->args);
return false;
}
$this->api->getLogger()->debug("Cache-Hit: $this", $this->args);
$key = $this->getCacheKey();
$cache->set($key, new Item($fresh, $ttl));
+ $this->api->getLogger()->debug("Cache-Push: $this", $this->args);
}
}
if (($cache = $this->api->getCacheStorage())) {
$key = $this->getCacheKey();
$cache->del($key);
+ $this->api->getLogger()->debug("Cache-Drop: $this", $this->args);
}
}
}
class CreateHook extends Call
{
function request() {
- $url = $this->url->mod("./repos/". $this->args["repo"] ."/hooks");
+ $url = $this->url->mod(":./repos/". $this->args["repo"] ."/hooks");
$request = new Request("POST", $url, [
"Authorization" => "token " . $this->api->getToken(),
"Accept" => $this->config->api->accept,