Example #1
0
 /**
  * 合并到master    ---------后期要重新优化代码@-----------
  * @param $mergeIds
  * @throws \Exception
  */
 function _mergemaster_action()
 {
     $mergeIds = $this->post('merge_ids');
     if (empty($mergeIds)) {
         throw new \Exception('firegit.merge_id_empty');
     }
     $repoTmp = TMP_ROOT . '/merge/';
     $api = new \firegit\app\mod\git\Merge();
     foreach ($mergeIds as $mergeId) {
         $repoDir = $repoTmp . '/master';
         if (is_dir($repoDir)) {
             //  stat beta
             system('rm ' . $repoDir . ' -rf');
         }
         mkdir($repoDir, 0777, true);
         chdir($repoDir);
         $mergeinfo = $api->getMerge($mergeId);
         if (!$mergeinfo) {
             throw new \Exception('firegit.u_notfound');
         }
         // 检查合并状态  只允许预上线已确认的
         if ($mergeinfo['deploy_status'] != 4) {
             throw new \Exception('firegit.u_mergeedFailed');
         }
         $origDir = GIT_REPO . $mergeinfo['repo_group'] . '/' . $mergeinfo['repo_name'] . '.git';
         // clone远程分支
         $cmd = sprintf('git clone %s -b master ./', $origDir);
         exec($cmd, $outputs, $code);
         unset($outputs);
         system('git config user.name ' . $this->user);
         system('git config user.email ' . $this->user . '@hunbasha.com');
         $cmd = sprintf('git fetch origin %s:%s', $mergeinfo['orig_branch'], $mergeinfo['orig_branch']);
         exec($cmd, $outputs, $code);
         unset($outputs);
         $cmd = sprintf('git merge -m "Merge remote-tracking branch \'%s\' into %s" %s', $mergeinfo['orig_branch'], 'master', $mergeinfo['orig_branch']);
         exec($cmd, $outputs, $code);
         $merge = new \firegit\app\mod\git\Merge();
         if ($code) {
             $merge->endMerge($mergeId, false, implode("\n", $outputs));
             throw new \Exception('firegit.merge_master_error:' . $mergeinfo['orig_branch']);
         }
         unset($outputs);
         //push 到远程
         $cmd = sprintf('git push origin master:master');
         exec($cmd, $outputs, $code);
         if ($code != 0) {
             throw new \Exception('firegit.push_master_error:' . $mergeinfo['orig_branch']);
         }
         $repo = new \firegit\git\Reposite($mergeinfo['repo_group'], $mergeinfo['repo_name']);
         //删除合并的分支
         if (!$repo->isProtected($mergeinfo['orig_branch'])) {
             $repo->delBranch($mergeinfo['orig_branch']);
             $repos = new \firegit\app\mod\git\Reposite();
             $repos->delBranch($mergeinfo['repo_group'], $mergeinfo['repo_name'], $mergeinfo['orig_branch']);
             \firegit\log\Logger::trace('merge.delBranch branch=%s hash=%s', $mergeinfo['orig_branch'], $mergeinfo['orig_hash']);
         }
         $merge->updateDeployStatus($mergeId, 0x11);
     }
 }
Example #2
0
 /**
  * 将指定的合并对应的合并请求标志为合并成功
  * @param $repoGroup
  * @param $repoName
  * @param $merges
  * @return array
  */
 function handleMerges($repoGroup, $repoName, $merges)
 {
     // 现获取所有的合并
     $db = Db::get('firegit');
     $rows = $db->table('fg_merge')->field('merge_id', 'orig_branch', 'orig_hash', 'dest_hash', 'dest_branch')->where(array('repo_group' => $repoGroup, 'repo_name' => $repoName, 'merge_status!' => MERGE_STATUS_CANCELED))->order('merge_id', false)->get();
     // 合并完的分支自动删除
     $repo = new \firegit\git\Reposite($repoGroup, $repoName);
     foreach ($merges as $key => $merge) {
         foreach ($rows as $key => $row) {
             if ($merge['orig'] == $row['orig_hash'] && $merge['dest'] == $row['dest_hash']) {
                 \firegit\log\Logger::trace('merge.chageStatus merge_id=%d orig=%s dest=%s', $row['merge_id'], $merge['orig'], $merge['dest']);
                 $this->endMerge($row['merge_id'], MERGE_STATUS_MERGED);
                 $this->updateDeployStatus($row['merge_id'], DEPLOY_STATUS_BETA);
                 //                    合并之后不删除分支 等合并到mater的时候在删除
                 if ($row['dest_branch'] == 'master' && !$repo->isProtected($row['orig_branch'])) {
                     $repo->delBranch($row['orig_branch']);
                     $repos = new \firegit\app\mod\git\Reposite();
                     $repos->delBranch($repoGroup, $repoName, $row['orig_branch']);
                     \firegit\log\Logger::trace('merge.delBranch branch=%s hash=%s', $row['orig_branch'], $row['orig_hash']);
                 }
                 unset($rows[$key]);
             }
         }
     }
 }
Example #3
0
 /**
  * 当出现错误时
  */
 public static function onError($errno, $errstr, $errfile, $errline)
 {
     if (!(error_reporting() & $errno)) {
         return;
     }
     switch ($errno) {
         case E_USER_ERROR:
             echo "<b>My ERROR</b> [{$errno}] {$errstr}<br />\n";
             echo "  Fatal error on line {$errline} in file {$errfile}";
             echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
             echo "Aborting...<br />\n";
             Logger::error("[file:%s line:%d] %s", $errfile, $errline, $errstr);
             break;
         case E_USER_WARNING:
             echo "<b>My WARNING</b> [{$errno}] {$errstr} in {$errfile}[line {$errline}]<br />\n";
             Logger::warn("[file:%s line:%d] %s", $errfile, $errline, $errstr);
             break;
         case E_USER_NOTICE:
             echo "<b>My NOTICE</b> [{$errno}] {$errstr} in {$errfile}[line {$errline}]<br />\n";
             Logger::notice("[file:%s line:%d] %s", $errfile, $errline, $errstr);
             break;
         default:
             echo "Unknown error type: [{$errno}] {$errstr} in {$errfile}[line {$errline}]<br />\n";
             Logger::fatal("[file:%s line:%d] %s", $errfile, $errline, $errstr);
             break;
     }
     exit(1);
 }