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();
 }
예제 #2
0
 $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);
             }
         }
         $have->status = $notifyObject->pull_request->state;
         $pr->save($have);
     } else {
         //Queue::push('PullRequestBuild', array('siteId' => $siteId, 'commit' => $commit), DeployInfo::PR_BUILD_QUEUE);
         $class = Config::get('worker.queue.prbuild');
         \Eleme\Worker\Supervisor::push($class, array('siteId' => $siteId, 'commit' => $commit, 'pullNumber' => $pullNumber), 'prbuild');
         $pr->add($notifyObject);
 public function rebuild($siteId)
 {
     $commit = Input::get('commit');
     $pr = new PullRequest($siteId);
     $prCommit = $pr->get($commit);
     if ($prCommit->testStatus == 'Error' || $prCommit->buildStatus == 'Error') {
         $prCommit->testStatus = 'Waiting';
         $prCommit->errorMsg = NULL;
         $prCommit->buildStatus = 'Waiting';
         $res = 0;
         $info = '';
         //Queue::push('PullRequestBuild', array('siteId' => $siteId, 'commit' => $commit), DeployInfo::PR_BUILD_QUEUE);
         $class = Config::get('worker.queue.prbuild');
         Supervisor::push($class, array('siteId' => $siteId, 'commit' => $commit, 'pullNumber' => $prCommit->pullNumber), 'prbuild');
         $pr->save($prCommit);
     } else {
         $res = 1;
         $info = '当前Commit的状态不可Rebuild';
     }
     return Response::json(array('res' => $res, 'info' => $info));
 }
예제 #4
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";