diff --git a/module/repo/model.php b/module/repo/model.php index dcf7fe8366..2b44460bfd 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -2637,7 +2637,14 @@ class repoModel extends model ->add('execution', $bug->execution) ->get(); - $changes = $this->bug->resolve($newBug); + $changes = array(); + $result = $this->bug->resolve($newBug); + if($result) + { + $newBug = $this->bug->getByID($bugID); + $changes = common::createChanges($bug, $newBug); + } + foreach($changes as $change) $changes[] = $change; if($changes) { diff --git a/module/repo/test/model/saveaction2pms.php b/module/repo/test/model/saveaction2pms.php new file mode 100644 index 0000000000..f579a10856 --- /dev/null +++ b/module/repo/test/model/saveaction2pms.php @@ -0,0 +1,66 @@ +#!/usr/bin/env php +saveAction2PMS(); +timeout=0 +cid=1 + +- 开始任务 + - 第1条的status属性 @doing + - 第1条的consumed属性 @4 + - 第1条的left属性 @3 +- 完成任务 + - 第2条的status属性 @done + - 第2条的consumed属性 @14 + - 第2条的left属性 @0 +- 工时计算 + - 第8条的status属性 @doing + - 第8条的consumed属性 @11 + - 第8条的left属性 @3 +- 修复bug1 + - 第1条的status属性 @resolved + - 第1条的resolution属性 @fixed +- 修复bug2 + - 第2条的status属性 @resolved + - 第2条的resolution属性 @fixed + +*/ + +zdTable('task')->gen(10); +$bug = zdTable('bug'); +$bug->execution->range('0'); +$bug->gen(10); +zdTable('repo')->config('repo')->gen(4); + +$repoID = 1; +$repoRoot = ''; +$scm = 'gitlab'; + +$log = new stdclass(); +$log->revision = '61e51cadb1aa21ef3d2b51e3f193be3cc19cfef6'; +$log->committer = 'root'; +$log->time = '2023-12-29 10:44:36'; +$log->comment = 'Start Task #1 Cost:1h Left:3h,Effort Task #8 Cost:1h Left:3h,Finish Task #2 Cost:10h'; +$log->author = 'user4'; +$log->msg = 'Start Task #1 Cost:1h Left:3h,Effort Task #8 Cost:1h Left:3h,Finish Task #2 Cost:10h'; +$log->date = '2023-12-29 10:44:36'; +$log->files = array('M' => array('/README.md')); +$log->change = array('/README.md' => array('action' => 'M', 'kind' => 'file', 'oldPath' => '')); + +$repo = new repoTest(); +$repo->saveAction2PMSTest($log, $repoID); +$result = $tester->loadModel('task')->getByIdList(array(1,2,8)); +r($result) && p('1:status,consumed,left') && e('doing,4,3'); //开始任务 +r($result) && p('2:status,consumed,left') && e('done,14,0'); //完成任务 +r($result) && p('8:status,consumed,left') && e('doing,11,3'); //工时计算 + +$log->msg = $log->comment = 'Fix bug#1,2'; +$repo->saveAction2PMSTest($log, $repoID); +$result = $tester->loadModel('bug')->getByIdList(array(1,2)); +r($result) && p('1:status,resolution') && e('resolved,fixed'); //修复bug1 +r($result) && p('2:status,resolution') && e('resolved,fixed'); //修复bug2 diff --git a/module/repo/test/model/saverecord.php b/module/repo/test/model/saverecord.php new file mode 100644 index 0000000000..3052cea4e2 --- /dev/null +++ b/module/repo/test/model/saverecord.php @@ -0,0 +1,54 @@ +#!/usr/bin/env php +saveRecord(); +timeout=0 +cid=1 + +- 保存一条记录 + - 属性action @gitcommited + - 属性extra @61e51cadb1 +- 更新已有记录属性actor @admin +- 查看历史记录属性field @git + +*/ + +zdTable('task')->gen(10); +zdTable('repo')->config('repo')->gen(4); + +$taskID = 1; +$repoRoot = ''; +$scm = 'gitlab'; + +$log = new stdclass(); +$log->revision = '61e51cadb1aa21ef3d2b51e3f193be3cc19cfef6'; +$log->committer = 'root'; +$log->time = '2023-12-29 10:44:36'; +$log->comment = 'Start Task #64250 Cost:1h Left:3h Finish Task #64247 Cost:10h'; +$log->author = ''; +$log->msg = 'Start Task #64250 Cost:1h Left:3h Finish Task #64247 Cost:10h'; +$log->date = '2023-12-29 10:44:36'; +$log->files = array('M' => array('/README.md')); +$log->change = array('/README.md' => array('action' => 'M', 'kind' => 'file', 'oldPath' => '')); + +$action = new stdclass(); +$action->actor = 'user4'; +$action->date = '2023-12-29 13:14:36'; +$action->extra = $scm == 'svn' ? $log->revision : substr($log->revision, 0, 10); +$action->objectType = 'task'; +$action->objectID = $taskID; +$action->action = 'gitcommited'; + +$repo = new repoTest(); + +r($repo->saveRecordTest($action, $log, $repoRoot, $scm)) && p('action,extra') && e('gitcommited,61e51cadb1'); //保存一条记录 + +$action->actor = 'admin'; +r($repo->saveRecordTest($action, $log, $repoRoot, $scm)) && p('actor') && e('admin'); //更新已有记录 + +r($repo->saveRecordTest($action, $log, $repoRoot, $scm, true)) && p('field') && e('git'); //查看历史记录 diff --git a/module/repo/test/repo.class.php b/module/repo/test/repo.class.php index 157ecf69b9..ce0f67e1b8 100644 --- a/module/repo/test/repo.class.php +++ b/module/repo/test/repo.class.php @@ -500,22 +500,37 @@ class repoTest return $objects; } - public function saveAction2PMSTest($objects, $log, $repoRoot = '', $encodings = 'utf-8', $scm = 'svn', $gitlabAccountPairs = array()) + public function saveAction2PMSTest($log, $repoID, $scm = 'git', $gitlabAccountPairs = array()) { - $objects = $this->objectModel->saveAction2PMS($objects, $log, $repoRoot, $encodings, $scm, $gitlabAccountPairs); + $repo = $this->objectModel->getByID($repoID); + $objects = $this->objectModel->parseComment($log->msg); + + $result = $this->objectModel->saveAction2PMS($objects, $log, $repo->path, $repo->encoding, $scm, $gitlabAccountPairs); if(dao::isError()) return dao::getError(); - - return $objects; + return $result; } - public function saveRecordTest($action, $changes) + public function saveRecordTest(object $action, object $log, string $repoRoot, string $scm, bool $returnHistory = false) { - $objects = $this->objectModel->saveRecord($action, $changes); + $action->comment = $this->objectModel->lang->repo->revisionA . ': #' . $action->extra . "
" . htmlSpecialString($this->objectModel->iconvComment($log->msg, 'utf-8')); + + $changes = $this->objectModel->createActionChanges($log, $repoRoot, $scm); + $this->objectModel->saveRecord($action, $changes); if(dao::isError()) return dao::getError(); - return $objects; + $record = $this->objectModel->dao->select('*')->from(TABLE_ACTION) + ->where('objectType')->eq($action->objectType) + ->andWhere('objectID')->eq($action->objectID) + ->andWhere('extra')->eq($action->extra) + ->andWhere('action')->eq($action->action) + ->fetch(); + if($returnHistory) + { + return $this->objectModel->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($record->id)->fetch(); + } + return $record; } public function createActionChangesTest($log, $repoRoot, $scm = 'svn')