diff --git a/module/git/test/git.class.php b/module/git/test/git.class.php index e1952ffcc1..ded180f44d 100755 --- a/module/git/test/git.class.php +++ b/module/git/test/git.class.php @@ -53,4 +53,52 @@ class gitTest return $this->gitModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('id')->eq(2)->fetch(); } + + /** + * Test saveCommits method. + * + * @param int $repoID + * @param string $param linked|job|empty + * @access public + * @return object|null|array + */ + public function saveCommitsTest(int $repoID, string $param): object|null|array + { + $repo = $this->gitModel->loadModel('repo')->getByID($repoID); + + $logs = array(); + $jobs = array(); + + $noLink = new stdclass(); + $noLink->revision = 'abc12'; + $noLink->committer = 'test'; + $noLink->author = 'test'; + $noLink->date = '2023-01-01 00:00:00'; + $noLink->time = '2023-01-01 00:00:00'; + $noLink->msg = 'test'; + $noLink->comment = 'test'; + $noLink->change = array(); + + $linked = new stdclass(); + $linked->revision = 'abc123'; + $linked->committer = 'test'; + $linked->author = 'test'; + $linked->date = '2023-01-02 00:00:00'; + $linked->time = '2023-01-02 00:00:00'; + $linked->msg = '* Code for task #1.'; + $linked->comment = '* Code for task #1.'; + $linked->change = array(); + if(strpos($param, 'linked') !== false) $logs[] = $linked; + if(strpos($param, 'nolink') !== false) $logs[] = $noLink; + + $job = new stdclass(); + $job->id = 1; + $job->comment = 'task'; + if(strpos($param, 'job') !== false) $jobs[] = $job; + + $res = $this->gitModel->saveCommits($repo, 'master', $logs, 1, $jobs, array(), false); + if(!$res) return dao::getError(); + + return $this->gitModel->loadModel('repo')->getByID($repoID); + } } diff --git a/module/git/test/model/savecommits.php b/module/git/test/model/savecommits.php new file mode 100755 index 0000000000..5c47a0f8c5 --- /dev/null +++ b/module/git/test/model/savecommits.php @@ -0,0 +1,42 @@ +#!/usr/bin/env php +saveCommits(); +timeout=0 +cid=1 + +- 没有提交信息 + - 属性id @0 + - 属性commits @0 +- 没有关联信息 + - 属性id @1 + - 属性commits @0 +- 有关联信息 + - 属性id @1 + - 属性commits @0 +- 一条没有关联信息,一条有关联信息 + - 属性id @1 + - 属性commits @0 +- 一条没有关联信息,一条有关联信息,有关联构建 + - 属性id @1 + - 属性commits @0 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/git.class.php'; + +zdTable('repo')->config('repo')->gen(1); +zdTable('repohistory')->gen(0); +su('admin'); + +$git = new gitTest(); + +r($git->saveCommitsTest(1, 'empty')) && p('id,commits') && e('0,0'); // 没有提交信息 +r($git->saveCommitsTest(1, 'nolink')) && p('id,commits') && e('1,0'); // 没有关联信息 +r($git->saveCommitsTest(1, 'linked')) && p('id,commits') && e('1,0'); // 有关联信息 + +r($git->saveCommitsTest(1, 'nolink|linked')) && p('id,commits') && e('1,0'); // 一条没有关联信息,一条有关联信息 +r($git->saveCommitsTest(1, 'nolink|linked|job')) && p('id,commits') && e('1,0'); // 一条没有关联信息,一条有关联信息,有关联构建 \ No newline at end of file diff --git a/module/svn/model.php b/module/svn/model.php index ff4f884c1e..7d7121faa6 100644 --- a/module/svn/model.php +++ b/module/svn/model.php @@ -54,7 +54,7 @@ class svnModel extends model * Sync commit info by cron. * * @access public - * @return boo; + * @return bool */ public function run(): bool {