예제 #1
0
 /**
  * @return array
  */
 public function toGitHubApiDataArray()
 {
     $data = array('body' => $this->body);
     if (TRUE === $this->commit instanceof Commit) {
         if (NULL !== $this->path) {
             $data['commit_id'] = $this->commit->getId();
             $data['path'] = $this->path;
             $data['position'] = $this->position;
         }
     } elseif (TRUE === $this->pullRequest instanceof PullRequest) {
         $data['sha1'] = $this->pullRequest->getId();
     }
     return $data;
 }
 public function fire($job, $message)
 {
     Log::info("\n---------------------------\njob id : {$job->getJobId()} start");
     $commit = $message['commit'];
     $siteId = $message['siteId'];
     $pr = new PullRequest($siteId);
     $commitInfo = $pr->get($commit);
     $repoName = $commitInfo->repo;
     $gitOrigin = "git@github.com:{$repoName}.git";
     $dc = new DC($siteId);
     $branch = $commitInfo->branch;
     $root = (new SystemConfig())->get(SystemConfig::WORK_ROOT_FIELD) . '/' . $siteId;
     $branchRoot = "{$root}/pull_requests/repo/{$repoName}";
     $commitPath = "{$root}/pull_requests/commit/{$commit}";
     $progress = 0;
     $cmd = '';
     $lock = new Eleme\Rlock\Lock(app('redis')->connection(), JobLock::pullRequestBuildLock($repoName), array('timeout' => 600000, 'blocking' => false));
     if (!$lock->acquire()) {
         Log::info("Job locked, now {$job->getJobId()} Release");
         $job->release(30);
         return;
     }
     try {
         if (!File::exists($branchRoot)) {
             Log::info('Git clone');
             $cmd = 'mkdir -p ' . $branchRoot;
             (new Process($cmd))->mustRun();
             $cmd = "mkdir -p {$root}/pull_requests/commit/";
             (new Process($cmd))->mustRun();
             $progress = 1;
             $cmd = "git clone {$gitOrigin} {$branchRoot} --depth 10";
             (new Process($cmd))->setTimeout(600)->mustRun();
             $progress = 2;
         }
         Log::info("git fetch origin");
         $cmd = "git fetch -f origin {$branch}:{$branch} --depth 20";
         (new Process($cmd, $branchRoot))->setTimeout(600)->mustRun();
         if (File::exists($commitPath)) {
             $cmd = "rm -rf {$commitPath}";
             (new Process($cmd))->setTimeout(600)->mustRun();
         }
         $progress = 3;
         $cmd = "cp -r {$branchRoot} {$commitPath}";
         Log::info($cmd);
         (new Process($cmd))->setTimeout(600)->mustRun();
         $cmd = "git checkout {$branch}";
         Log::info($cmd);
         (new Process($cmd, $commitPath))->mustRun();
         $cmd = "git checkout {$commit}";
         Log::info($cmd);
         (new Process($cmd, $commitPath))->mustRun();
         $commitInfo->buildStatus = 'Building';
         $pr->save($commitInfo);
         $progress = 4;
         $cmd = $dc->get(DC::BUILD_COMMAND);
         Log::info($cmd);
         (new Process($cmd, $commitPath))->setTimeout(600)->mustRun();
         $commitInfo->buildStatus = 'Success';
         $pr->save($commitInfo);
         $progress = 5;
         $commitInfo->testStatus = 'Testing';
         $pr->save($commitInfo);
         $cmd = $dc->get(DC::TEST_COMMAND);
         if (!empty($cmd)) {
             Log::info($cmd);
             (new Process($cmd, $commitPath))->setTimeout(600)->mustRun();
         }
         $commitInfo->testStatus = 'Success';
         $pr->save($commitInfo);
     } catch (Exception $e) {
         Log::info("ERROR!!! : " . $e->getMessage());
         $commitInfo->buildStatus = 'Error';
         $commitInfo->testStatus = 'Error';
         $commitInfo->errorMsg = "Command : {$cmd}\nError Message : {$e->getMessage()}";
         switch ($progress) {
             case 5:
                 $commitInfo->buildStatus = 'Success';
                 break;
             case 4:
                 (new Process("rm -rf {$commitPath}"))->run();
             case 3:
             case 2:
                 $commitInfo->testStatus = 'Abort';
                 break;
             case 1:
                 (new Process("rm -rf {$branchRoot}"))->run();
                 $commitInfo->testStatus = 'Abort';
                 break;
         }
         $pr->save($commitInfo);
     }
     $lock->release();
     Log::info("progress : {$progress}");
     Log::info("job id : {$job->getJobId()} finish");
     $job->delete();
 }
 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));
 }
예제 #4
0
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::post('/playload', function () {
    if (Request::header('X-GitHub-Event') == 'pull_request') {
        $content = file_get_contents('php://input');
        $notifyObject = json_decode($content);
        $repoFullName = $notifyObject->pull_request->base->repo->full_name;
        $siteId = WebSite::getSiteIdByFullName($repoFullName);
        $commit = $notifyObject->pull_request->head->sha;
        $pullNumber = $notifyObject->pull_request->number;
        if ($siteId !== NULL) {
            $pr = new PullRequest($siteId);
            $have = $pr->get($commit);
            if ($have !== NULL) {
                if ($notifyObject->action == 'closed') {
                    $mgb = $notifyObject->pull_request->merged_by;
                    $have->mergedBy = empty($mgb) ? '' : $mgb->login;
                    $commitList = $pr->getListByPRId($notifyObject->pull_request->id);
                    foreach ($commitList as $m) {
                        $m->status = 'closed';
                        $pr->save($m);
                    }
                } elseif ($notifyObject->action == 'reopened') {
                    $commitList = $pr->getListByPRId($notifyObject->pull_request->id);
                    foreach ($commitList as $m) {
                        $m->status = 'open';
                        $pr->save($m);
예제 #5
0
파일: scanpulls.php 프로젝트: ELN/metahub
 */
// filterマッチしなかったものを先にupdate
foreach ($cursorlist as $rid => $cursor) {
    if (!isset($alerted_pulls[$rid])) {
        RepositoryDb::updateCursor($rid, $cursor);
    }
}
// アラートがあるものはrepo毎のトランザクションで一括保存
$con = mfwDBConnection::getPDO('default_master');
$repoids = array_keys($alerted_pulls);
foreach ($repoids as $rid) {
    echo "save: {$repos[$rid]->getName()} ... ";
    $con->beginTransaction();
    try {
        foreach ($alerts[$rid] as $alert) {
            $pra = new PullRequestAlert($alert);
            $pra->save($con);
        }
        foreach ($alerted_pulls[$rid] as $p) {
            $pr = new PullRequest(array('repo_id' => $rid, 'number' => $p['number'], 'user' => $p['user']['login'], 'title' => $p['title'], 'pull_created_at' => $p['created_at']));
            $pr->save($con);
        }
        RepositoryDb::updateCursor($rid, $cursorlist[$rid], $con);
        $con->commit();
    } catch (Exception $e) {
        $con->rollback();
        throw $e;
    }
    echo "done.\n";
}
echo "complete.\n";
예제 #6
0
 public static function selectByPullRequest(PullRequest $pull, $con = null)
 {
     $query = 'WHERE repo_id = :repo_id AND number = :number';
     $bind = array(':repo_id' => $pull->getRepoId(), ':number' => $pull->getNumber());
     return self::selectSet($query, $bind, $con);
 }