function setStatus(\NamelessCoder\Gizzle\Payload $payload, \Milo\Github\Api $api, $state, $buildNumber) { $token = $api->getToken(); $head = $payload->getHead(); if (TRUE === empty($token) || TRUE === empty($head)) { return; } $url = sprintf('/repos/%s/%s/statuses/%s', $payload->getRepository()->getOwner()->getName(), $payload->getRepository()->getName(), $head->getId()); switch ($state) { case 'pending': $description = 'Waiting to hear from Gizzle...'; break; case 'success': $description = 'Gizzle build was successful!'; break; case 'error': $description = 'Gizzle reported an error!'; break; case 'failure': $description = 'Gizzle was unable to run the build!'; break; default: } $data = array('state' => $state, 'target_url' => 'http://github.com/NamelessCoder/gizzle', 'context' => $payload->getRepository()->getFullName() . '-gizzle-build-' . $buildNumber, 'description' => $description); $api->post($url, $data); }
public function __construct(Github\OAuth\Login $login, Github\Api $api, Nette\Http\Session $session) { $session = $session->getSection('milo.github.nette-extension.user'); if ($login->hasToken()) { $token = $login->getToken(); $hash = sha1($token->getValue()); if ($session->hash !== $hash) { $info = $this->defaults; $user = $api->decode($api->get('/user')); $info['id'] = $user->id; $info['login'] = $user->login; $info['name'] = $user->name; $info['avatarUrl'] = $user->avatar_url; if ($token->hasScope('user:email')) { $emails = $api->decode($api->get('/user/emails')); foreach ($emails as $email) { $info['email'] = $email->email; if ($email->primary) { break; } } } $session->info = $info; $session->hash = $hash; } $this->isLoggedIn = TRUE; } else { $session->remove(); $session->info = $this->defaults; } $this->info = $session->info; }
public function init() { parent::init(); // search projects http://developer.github.com/v3/search/#search-repositories $api = new GitHubApi(); $this->search = $api->get('/search/repositories?q=' . str_replace(' ', '+', $this->search), []); $this->search = (array) $api->decode($this->search); $this->search = $this->search['items']; }
public function __construct($id, $url) { $this->content = apcu_fetch('cachecontrol_' . $id); if (!$this->content || isset($_GET['nocache'])) { $api = new Github\Api(); $response = $api->get($url); $this->content = $api->decode($response); apcu_store('cachecontrol_' . $id, $this->content, 300); } }
/** * Creates a new instance of the API library to use later. * * @throws InvalidArgumentException */ protected function createApiInstance() { $configToken = $this->getConfig('token'); if ($configToken === null) { throw new InvalidArgumentException('API token has not been set in the config.'); } $token = new Token($configToken); $this->api = new Api(); $this->api->setToken($token); }
public function init() { parent::init(); $api = new GitHubApi(); //$token = new MyToken('833e3c356b24acecf75b52aa815ab48c82ad21ef'); //$api->setToken($token); //$api->getToken(); // project's info http://developer.github.com/v3/repos/#get $this->response_proj = $api->get('/repos/:owner/:repo', ['owner' => $this->owner, 'repo' => $this->repo]); $this->response_proj = (array) $api->decode($this->response_proj); // contributor's info http://developer.github.com/v3/repos/#list-contributors $this->response_contributor = $api->get('/repos/:owner/:repo/contributors', ['owner' => $this->owner, 'repo' => $this->repo]); $this->response_contributor = (array) $api->decode($this->response_contributor); }
public function init() { parent::init(); $api = new GitHubApi(); //$token = new MyToken('833e3c356b24acecf75b52aa815ab48c82ad21ef'); //$api->setToken($token); //$api->getToken(); // contributors' info http://developer.github.com/v3/users/#get-a-single-user $this->user = $api->get('/users/:username', ['username' => $this->user]); $this->user = (array) $api->decode($this->user); // define contributors' status $this->status = GithubUsers::find()->where(['id_user' => $this->user['id']])->one(); $this->status = $this->status['status_user']; }
/** * @return string */ public function getPanel() { $user = $this->user; $token = $this->api->getToken(); $client = $this->api->getClient(); if ($this->rateLimit) { $freshLimit = TRUE; $rateLimit = $this->rateLimit; } elseif ($this->session->rateLimit) { $freshLimit = FALSE; $rateLimit = $this->session->rateLimit; } else { $freshLimit = FALSE; $rateLimit = NULL; } $messages = $this->messages; ob_start(); require __DIR__ . '/Panel.phtml'; return ob_get_clean(); }
<?php include '../php/github-api.php'; use Milo\Github; $contributorcache = "../cache/contributors.json"; $cachetime = 60 * 60 * 12; // 12 hours $contributors; if (file_exists($contributorcache) && time() - $cachetime < filemtime($contributorcache)) { // $cachedata = file_get_contents($contributorcache); // $contributors = json_decode($cachedata); } else { $contributors = array(); $contributorsMin = array(); try { $api = new Github\Api(); $token = new Github\OAuth\Token("{{site.github_key}}"); $api->setToken($token); foreach ($api->paginator('/repos/amplab/tachyon/contributors') as $response) { array_push($contributors, $api->decode($response)); } foreach ($contributors as $contributorPage) { foreach ($contributorPage as $contributor) { array_push($contributorsMin, array('login' => $contributor->login, 'avatar_url' => $contributor->avatar_url, 'contributions' => $contributor->contributions)); } } $contributors = $contributorsMin; } catch (Exception $e) { //echo $e->getMessage(); } $fp = fopen($contributorcache, "w");
echo $e->getMessage(); } $res = $response->results; foreach ($res as $event) { if ($event->time / 1000 > microtime(true) - $pastNewsLimit) { if (strlen($event->name) > 45) { $event->name = substr($event->name, 0, 45) . "..."; } array_push($events, array("title" => $event->name, "date" => $event->time, "desc" => substr(strip_tags(html_entity_decode($event->description)), 0, 120), "link" => $event->event_url, "type" => "meetup")); } } } catch (Exception $e) { //echo $e->getMessage(); } try { $api = new Github\Api(); $token = new Github\OAuth\Token("{{site.github_key}}"); $api->setToken($token); foreach ($api->paginator('/repos/amplab/tachyon/contributors') as $response) { array_push($contributors, $api->decode($response)); } foreach ($contributors as $contributorPage) { foreach ($contributorPage as $contributor) { array_push($contributorsMin, array('login' => $contributor->login, 'avatar_url' => $contributor->avatar_url, 'contributions' => $contributor->contributions)); } } $response = $api->get('/repos/amplab/tachyon'); $repoInfo = $api->decode($response); $stars = $repoInfo->stargazers_count; $commits = 0; foreach ($contributorsMin as $contributor) {