public function __construct() { $sites = (new WebSite())->getList(); $user = GithubLogin::getLoginUser(); $validSites = array(); $adminSites = array(); foreach ($sites as $m) { if (!empty($user->permissions[$m['siteId']])) { $validSites[] = $m; if (DeployPermissions::havePermission(DeployPermissions::WRITE, $user->permissions[$m['siteId']])) { $adminSites[] = $m['siteId']; } } } $isSuperUser = false; $i = 0; while (!empty($_ENV["SUPER_USERS.{$i}"])) { if ($_ENV["SUPER_USERS.{$i}"] == $user->login) { $isSuperUser = true; break; } $i++; } $this->validSites = $validSites; View::share('sites', $validSites); View::share('isSuperUser', $isSuperUser); View::share('adminSites', $adminSites); }
public static function getLoginUser() { if (empty(self::$loginUser)) { $jstr = Session::get(self::$sessionKey); self::$loginUser = GithubUser::loadFromJson($jstr); } return self::$loginUser; }
public function commit() { $siteId = Input::get('siteId'); $commit = Input::get('commit'); $hostType = Input::get('remote'); $deploy = array('branch' => '---', 'commit' => $commit, 'hosttype' => $hostType, 'user' => GithubLogin::getLoginUser()->login, 'type' => 'Deploy To ' . $hostType, 'time' => date('Y-m-d H:i:s'), 'last_time' => '0000-00-00 00:00:00', 'result' => 'Deploy Waiting', 'errMsg' => ' ', 'errOut' => "<div class='text-center'>----------- ERROR OUTPUT -----------</div>\n", 'standOut' => "<div class='text-center'>----------- STANDED OUTPUT -----------</div>\n"); $id = (new DeployInfo($siteId))->add($deploy); $class = Config::get('worker.queue.deploy'); Supervisor::push($class, array('siteId' => $siteId, 'commit' => $commit, 'hostType' => $hostType, 'id' => $id), 'deploy'); return Response::json(array('res' => 0)); }
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); } }
srkSend((object) array('res' => 'successful')); } else { srkSend((object) array('res' => 'Failed to write data')); } } } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'logout') { unset($_SESSION['userId']); srkSend((object) array('res' => 'successful')); } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'edit') { $user = new UserData(); $user->readUser($_SESSION['userId']); srkSend($user->update($_POST)); } } elseif ($srkEnv->reqURLLength == 2 && $srkEnv->reqURL[2] == 'github') { require_once $srkEnv->appPath . '/modules/thirdpartylogin/github.php'; $loginRes = GithubLogin::fetchInfo(); if ($loginRes) { srkRender('error', array('error' => array('status' => -1, 'stack' => $loginRes))); } else { header("Location: /"); } } elseif ($srkEnv->reqURLLength >= 2 && $srkEnv->reqURL[2] == 'query') { if ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'whoami') { $userId = $_SESSION['userId']; if (!isset($userId)) { srkSend((object) array('error' => 'not logged in')); } else { srkSend((object) array('userId' => $userId)); } } elseif ($srkEnv->reqURLLength == 4 && $srkEnv->reqURL[4] == 'avatarurl') { $user = new UserData();
public function toDeploy($siteId) { $commit = Input::get('commit'); $hostType = Input::get('remote'); $date = date('Y-m-d H:i:s'); $user = GithubLogin::getLoginUser(); $pr = new PullRequest($siteId); $prCommit = $pr->get($commit); $prd = new PullRequestDeploy($siteId); $pri = $prd->add($prCommit->prId, $prCommit->title, $commit, $prCommit->user, $user->login, $hostType, $date, $date, 'Waiting'); //Queue::push('DeployCommit', array('id' => $pri->id, 'type' => DeployCommit::TYPE_PULL_REQUEST, 'hostType' => $hostType, 'siteId' => $siteId, 'commit' => $commit), DeployInfo::DEPLOY_QUEUE); $class = Config::get('worker.queue.deploy'); Supervisor::push($class, array('siteId' => $siteId, 'commit' => $commit, 'type' => DeployCommit::TYPE_PULL_REQUEST, 'hostType' => $hostType, 'id' => $pri->id), 'deploy'); return Response::json(array('res' => 0)); }
$cookie = GithubLogin::login($user->login, $email, $accessToken, $orgTeams); return Redirect::to('/')->withCookie($cookie); } else { return "ORG ERROR"; } }); Route::get('/user/permissions/refresh', function () { $user = GithubLogin::getLoginUser(); $user->sitePermission(); $user->set(); GithubLogin::sessionUser($user); return Redirect::to('/'); }); Route::get('/user/team/repos', function () { $repos = array(); $user = GithubLogin::getLoginUser(); foreach ($user->teams as $team) { $repos = array_merge($repos, (new TeamRepos($team->id, $user->token))->repos()); } //var_dump($repos); return Response::json(array('res' => 0, 'data' => $repos)); }); Route::get('/', 'SystemController@index'); Route::post('/system/config/save', 'SystemController@systemConfig'); Route::post('/hostType/add', 'SystemController@addHostType'); Route::post('/hostType/del', 'SystemController@delHostType'); Route::post('/site/add', 'SystemController@addSite'); Route::post('/site/del', 'SystemController@delSite'); Route::post('/config/save', 'ConfigController@saveConfig'); Route::get('/test', function () { //Mail::send('emails.deploy', array('siteId' => 'web2', 'status' => 'Success', 'hostType' => 'testing', 'commit' => 'f548a32fd929500d28966d60c432d833c0391167', 'repoName' => 'heimonsy/eleme-deploy'), function($message)
public function notWatch($siteId) { $user = GithubLogin::getLoginUser(); (new Watch($user->login, $siteId))->notWatch(); return Response::json(array('res' => 0)); }