app\components\Git::getCommitList PHP Méthode

getCommitList() public méthode

获取提交历史
public getCommitList ( string $branch = 'master', integer $count = 20 ) : array
$branch string
$count integer
Résultat array
    public function getCommitList($branch = 'master', $count = 20)
    {
        // 先更新
        $destination = Project::getDeployFromDir();
        $this->updateRepo($branch, $destination);
        $cmd[] = sprintf('cd %s ', $destination);
        $cmd[] = '/usr/bin/env git log -' . $count . ' --pretty="%h - %an %s" ';
        $command = join(' && ', $cmd);
        $result = $this->runLocalCommand($command);
        if (!$result) {
            throw new \Exception(\yii::t('walle', 'get commit log failed') . $this->getExeLog());
        }
        $history = [];
        // 总有一些同学没有团队协作意识,不设置好编码:(
        $log = htmlspecialchars(GlobalHelper::convert2Utf8($this->getExeLog()));
        $list = explode(PHP_EOL, $log);
        foreach ($list as $item) {
            $commitId = substr($item, 0, strpos($item, '-') - 1);
            $history[] = ['id' => $commitId, 'message' => $item];
        }
        return $history;
    }

Usage Example

 /**
  * 获取commit历史
  *
  * @param $projectId
  */
 public function actionGetCommitHistory($projectId, $branch = 'master')
 {
     $git = new Git();
     $conf = Project::getConf($projectId);
     $git->setConfig($conf);
     if ($conf->git_type == Project::GIT_TAG) {
         $list = $git->getTagList();
     } else {
         $list = $git->getCommitList($branch);
     }
     $this->renderJson($list);
 }