public function __construct($teamId, $userToken = null) { if ($userToken == NULL) { $user = GithubLogin::getLoginUser(); $userToken = $user->token; } $this->teamId = $teamId; $this->redis = app('redis')->connection(); $this->expires = 432000; // 5 day $jstr = $this->redis->get($this->key()); if (empty($jstr)) { //$user = GithubLogin::getLoginUser(); $client = new \Eleme\Github\GithubClient($userToken); $this->repos = array(); $page = 1; $url = $client->catUrl('teams/' . $teamId . '/repos'); do { $tempRepos = $client->get($url); if (empty($tempRepos->message)) { foreach ($tempRepos as $m) { if ($m->owner->login == Config::get('github.organization')) { $this->repos[] = new GithubRepo($m->id, $m->name, $m->full_name, $m->ssh_url); } } } else { throw new Exception('teamId doesn\'t found'); } $header = $client->getResponse()->getHeader('Link'); preg_match('/<(.+?)>; rel="next"/', $header, $matchs); if (count($matchs) != 2) { break; } $url = $matchs[1]; } while (!empty($url)); $this->save(); } else { $this->repos = json_decode($jstr); } }
public function sendStatus($siteId, $token, $git_url, $commit, $status, $message) { try { $pattern = '/:([\\w\\d-_\\.]+\\/[\\w\\d-_\\.]+)\\.git$/i'; if (preg_match($pattern, $git_url, $matchs)) { if (empty($token)) { Log::info("Site {$siteId} github token dosen't confiured"); return ''; } $client = new \Eleme\Github\GithubClient($token); $response = $client->request('repos/' . $matchs[1] . '/statuses/' . $commit, json_encode(array('state' => $status, "target_url" => url("/{$siteId}/pull_request/info"), "description" => $message, "context" => "eleme deploy")), true); Log::info("Send Status To Github: {$status}"); } else { Log::info("Send Status Error, Can't Find Full Repo Name: {$git_url}"); } } catch (Exception $e) { Log::info($e); Log::info($e->getResponse()->getBody(true)); Log::info("Send Status Error"); } }
$cookie = GithubLogin::logout(); return Redirect::to('/github/oauth/confirm')->withCookie($cookie); }); Route::get('/github/oauth/callback', function () { if (GithubLogin::check()) { return Redirect::to('/'); } $code = Input::get('code'); if ($code == '') { return 'CODE ERROR'; } $accessToken = \Eleme\Github\GithubAuthorize::accessToken($code); if ($accessToken == NULL) { echo "CODE ERROR"; } $client = new \Eleme\Github\GithubClient($accessToken); $teams = $client->request('user/teams'); $haveEleme = false; $orgTeams = array(); foreach ($teams as $team) { if ($team->organization->login == Config::get('github.organization')) { $haveEleme = true; $orgTeams[] = $gt = new GithubTeam($team); TeamRepos::delByTeamId($gt->id); } } if ($haveEleme) { $user = $client->request('user'); $email = isset($user->email) ? $user->email : ''; $cookie = GithubLogin::login($user->login, $email, $accessToken, $orgTeams); return Redirect::to('/')->withCookie($cookie);