From 685f11f3e5a3a700a8e53ecf86faa54f37e11799 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 12 Aug 2021 12:15:01 +0800 Subject: [PATCH 001/154] * Add MR to DevOps menu. --- module/common/lang/menu.php | 10 ++++++---- module/common/lang/zh-cn.php | 1 + module/mr/control.php | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 module/mr/control.php diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index ce273b17eb..b6337eee94 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -317,6 +317,7 @@ $lang->qa->dividerMenu = ',bug,testtask,caselib,'; $lang->devops->menu = new stdclass(); $lang->devops->menu->code = array('link' => "{$lang->repo->common}|repo|browse|repoID=%s", 'alias' => 'diff,view,revision,log,blame,showsynccommit'); $lang->devops->menu->compile = array('link' => "{$lang->devops->compile}|job|browse", 'subModule' => 'compile,job'); +$lang->devops->menu->mr = array('link' => "{$lang->devops->mr}|mr|browse"); $lang->devops->menu->gitlab = array('link' => "GitLab|gitlab|browse", 'alias' => 'create,edit'); $lang->devops->menu->jenkins = array('link' => "Jenkins|jenkins|browse", 'alias' => 'create,edit'); $lang->devops->menu->maintain = array('link' => "{$lang->devops->repo}|repo|maintain", 'alias' => 'create,edit'); @@ -324,10 +325,11 @@ $lang->devops->menu->rules = array('link' => "{$lang->devops->rules}|repo|set $lang->devops->menuOrder[5] = 'code'; $lang->devops->menuOrder[10] = 'compile'; -$lang->devops->menuOrder[15] = 'gitlab'; -$lang->devops->menuOrder[20] = 'jenkins'; -$lang->devops->menuOrder[25] = 'maintain'; -$lang->devops->menuOrder[30] = 'rules'; +$lang->devops->menuOrder[15] = 'mr'; +$lang->devops->menuOrder[20] = 'gitlab'; +$lang->devops->menuOrder[25] = 'jenkins'; +$lang->devops->menuOrder[30] = 'maintain'; +$lang->devops->menuOrder[35] = 'rules'; /* Doc menu. */ $lang->doc->menu = new stdclass(); diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 26f60abb64..8935a7ceed 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -237,6 +237,7 @@ $lang->testcase->testsuite = '套件'; $lang->testcase->caselib = '用例库'; $lang->devops->compile = '构建'; +$lang->devops->mr = '合并请求'; $lang->devops->repo = '版本库'; $lang->devops->rules = '指令'; diff --git a/module/mr/control.php b/module/mr/control.php new file mode 100644 index 0000000000..206829c536 --- /dev/null +++ b/module/mr/control.php @@ -0,0 +1,22 @@ + Date: Thu, 12 Aug 2021 13:39:27 +0800 Subject: [PATCH 002/154] * Show gitlab project list in MR. --- module/mr/control.php | 28 +++++++++++++++++-- module/mr/lang/zh-cn.php | 3 ++ module/mr/view/browse.html.php | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 module/mr/lang/zh-cn.php create mode 100644 module/mr/view/browse.html.php diff --git a/module/mr/control.php b/module/mr/control.php index 206829c536..fe9515a75c 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -1,9 +1,33 @@ loadModel('repo'); + + $repoList = $this->repo->getList(0, $orderBy); + foreach($repoList as $id => $repo) + { + if(strtolower($repo->SCM) != 'gitlab') unset($repoList[$id]); + } + + /* Pager. */ + $this->app->loadClass('pager', $static = true); + $recTotal = count($repoList); + $pager = new pager($recTotal, $recPerPage, $pageID); + $repoList = array_chunk($repoList, $pager->recPerPage); + + $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->browse; + $this->view->position[] = $this->lang->repo->common; + $this->view->position[] = $this->lang->repo->browse; + + $this->view->orderBy = $orderBy; + $this->view->objectID = $objectID; + $this->view->pager = $pager; + $this->view->repoList = empty($repoList) ? $repoList: $repoList[$pageID - 1];; + $this->view->products = $this->loadModel('product')->getPairs(); + + $this->display(); } public function create() diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php new file mode 100644 index 0000000000..4462a51b5e --- /dev/null +++ b/module/mr/lang/zh-cn.php @@ -0,0 +1,3 @@ +mr->common = "合并请求"; +$lang->mr->create = "创建{$lang->mr->common}"; diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php new file mode 100644 index 0000000000..83b6e793bf --- /dev/null +++ b/module/mr/view/browse.html.php @@ -0,0 +1,50 @@ + +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> + + + + + + + + + + + + + + + + + + +
repo->id); ?>repo->type); ?>repo->name); ?>repo->product); ?>actions; ?>
id; ?>repo->scmList, $repo->SCM); ?>createLink('repo', 'browse', "repoID={$repo->id}&branchID=&objectID=$objectID"), $repo->name);?> + product)); + if(isset($productList) and $productList[0]) + { + foreach($productList as $productID) + { + if(!isset($products[$productID])) continue; + echo ' ' . html::a($this->createLink('product', 'browse', "productID=$productID"), zget($products, $productID, $productID)); + } + } + ?> + + id&objectID=$objectID", '', 'list', 'edit'); + common::printIcon('mr', 'create', "repo={$repo->id}", $lang->mr->create, 'list', 'review'); + if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); + ?> +
+ + + +
+
+ From 0c2f5fd11e837ba53ac5c65ff5688ed5332937e7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 12 Aug 2021 14:02:07 +0800 Subject: [PATCH 003/154] * Add creating a gitlab project from repo. --- module/mr/lang/zh-cn.php | 1 + module/mr/view/browse.html.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 4462a51b5e..a479894d8d 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -1,3 +1,4 @@ mr->common = "合并请求"; $lang->mr->create = "创建{$lang->mr->common}"; +$lang->mr->add = "添加GitLab项目"; diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 83b6e793bf..7636aacabf 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,4 +1,9 @@ +
@@ -33,8 +38,8 @@ From b8113c047b6734464f1f4a9bd557c0c93421bbb4 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 12 Aug 2021 06:24:48 +0000 Subject: [PATCH 004/154] * Add Language configuration items. --- module/mr/lang/zh-cn.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index a479894d8d..d853f2844f 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -2,3 +2,12 @@ $lang->mr->common = "合并请求"; $lang->mr->create = "创建{$lang->mr->common}"; $lang->mr->add = "添加GitLab项目"; + + +$lang->mr->id = 'ID'; +$lang->mr->name = '名称'; +$lang->mr->source = '源项目分支'; +$lang->mr->targer = '目标分支'; +$lang->mr->pipeline = '流水线'; +$lang->mr->audit = '审核状态'; +$lang->mr->execute = '执行状态'; From 4a43e87e35ac2f25b59080dc05b31be26e4a7d37 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 13:57:24 +0800 Subject: [PATCH 005/154] * Add zt_mr database table. --- db/zentao.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/db/zentao.sql b/db/zentao.sql index ab4f9f3beb..f46d4d97d6 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -544,6 +544,24 @@ CREATE TABLE IF NOT EXISTS `zt_module` ( KEY `type` (`type`), KEY `path` (`path`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- DROP TABLE IF EXISTS `zt_mr`; +CREATE TABLE `zt_mr` ( + `id` int NOT NULL, + `repoID` int NOT NULL, + `gitlabID` int NOT NULL, + `projectID` int NOT NULL, + `mrID` int NOT NULL, + `title` varchar(255) NOT NULL, + `description` text NOT NULL, + `assignees` varchar(255) NOT NULL, + `reviewers` varchar(255) NOT NULL, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) NOT NULL, + `editedDate` datetime NOT NULL, + `deleted` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_notify`; CREATE TABLE IF NOT EXISTS `zt_notify` ( `id` mediumint unsigned NOT NULL AUTO_INCREMENT, From c7f53c574a9799e49e274a0ddb25d42872ce7142 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 15:47:01 +0800 Subject: [PATCH 006/154] * Add TABLE_MR config. --- config/zentaopms.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/zentaopms.php b/config/zentaopms.php index fe193d98ca..a1c86bc2e2 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -210,9 +210,10 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`'); define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); -define('TABLE_PIPELINE', '`' . $config->db->prefix . 'pipeline`'); +define('TABLE_PIPELINE', '`' . $config->db->prefix . 'pipeline`'); define('TABLE_JOB', '`' . $config->db->prefix . 'job`'); define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`'); +define('TABLE_MR', '`' . $config->db->prefix . 'mr`'); define('TABLE_REPO', '`' . $config->db->prefix . 'repo`'); define('TABLE_RELATION', '`' . $config->db->prefix . 'relation`'); @@ -255,6 +256,7 @@ $config->objectTables['stakeholder'] = TABLE_STAKEHOLDER; $config->objectTables['job'] = TABLE_JOB; $config->objectTables['team'] = TABLE_TEAM; $config->objectTables['pipeline'] = TABLE_PIPELINE; +$config->objectTables['mr'] = TABLE_MR; /* Program privs.*/ $config->programPriv = new stdclass(); From 5466c2ed0282415eac09841c362582c9d15beecc Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 16:19:07 +0800 Subject: [PATCH 007/154] + Add gitlab MR model. --- module/mr/model.php | 199 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 module/mr/model.php diff --git a/module/mr/model.php b/module/mr/model.php new file mode 100644 index 0000000000..55e3003690 --- /dev/null +++ b/module/mr/model.php @@ -0,0 +1,199 @@ + + * @package mr + * @version $Id$ + * @link http://www.zentao.net + */ +class mrModel extends model +{ + /** + * The construc method, to do some auto things. + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->loadModel('gitlab'); + } + + /** + * Get a MR by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + return $this->dao->select(*)->from(TABLE_MR)->where('id')->eq($id)->fetch(); + } + + /** + * Get MR list of gitlab project. + * + * @param int $orderBy + * @param object $pager + * @access public + * @return array + */ + public function getList($repoID, $orderBy = 'id_desc', $pager = null) + { + return $this->dao->select('*') + ->from(TABLE_MR) + ->where('deleted')->eq('0') + ->AndWhere('repoID')->eq($repoID) + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } + + /** + * Get gitlab pairs. + * + * @access public + * @return array + */ + public function getPairs($repoID) + { + $mr = $this->dao->select('id,title') + ->from(TABLE_MR) + ->where('deleted')->eq('0') + ->AndWhere('repoID')->eq($repoID) + ->orderBy('id')->fetchPairs('id', 'title'); + return array('' => '') + $mr; + } + + /** + * Get gitlab api base url by gitlab ID. + * + * @param int $gitlabID + * @access public + * @return string + */ + public function getApiRoot($gitlabID) + { + return $this->gitlab->getAppRoot($gitlabID); + } + + /** + * Create MR by API. + * + * @param int $gitlabID + * @param int $projectID + * @param object $params + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#create-mr + */ + public function apiCreateMR($gitlabID, $projectID, $params) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); + return json_decode(commonModel::http($url)); + } + + /** + * Get MR list by API. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests + */ + public function apiListMR($gitlabID, $projectID) + { + } + + /** + * Get single MR by API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr + */ + public function apiGetSingleMR($gitlabID, $projectID, $mrID) + { + } + + /** + * Update MR by API. + * + * @param int $gitlabID + * @param int $projectID + * @param object $params + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#update-mr + */ + public function apiUpdateMR($gitlabID, $projectID, $params) + { + } + + /** + * Delete MR by API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request + */ + public function apiDeleteMR($gitlabID, $projectID, $mrID) + { + } + + /** + * Accept MR by API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr + */ + public function apiAcceptMR($gitlabID, $projectID, $mrID) + { + } + + /** + * Get MR diff versions by API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-mr-diff-versions + */ + public function apiGetDiffVersions($gitlabID, $projectID, $mrID) + { + } + + /** + * Get single diff version by API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @param int $versionID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-mr-diff-version + */ + public function apiGetSingleDiffVersion($gitlabID, $projectID, $mrID, $versionID) + { + } +} + From 9b23391900d0b73688e46092ac9897cf6ccce3fd Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 16:33:48 +0800 Subject: [PATCH 008/154] * Update MR model. --- module/mr/model.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 55e3003690..b2bb07040e 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -95,7 +95,8 @@ class mrModel extends model public function apiCreateMR($gitlabID, $projectID, $params) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); - return json_decode(commonModel::http($url)); + $mr = new stdclass; + return json_decode(commonModel::http($url, $mr)); } /** @@ -107,8 +108,10 @@ class mrModel extends model * @return object * @docs https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests */ - public function apiListMR($gitlabID, $projectID) + public function apiGetMRList($gitlabID, $projectID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); + return json_decode(commonModel::http($url)); } /** @@ -123,6 +126,8 @@ class mrModel extends model */ public function apiGetSingleMR($gitlabID, $projectID, $mrID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + return json_decode(commonModel::http($url)); } /** @@ -130,13 +135,17 @@ class mrModel extends model * * @param int $gitlabID * @param int $projectID + * @param int $mrID * @param object $params * @access public * @return object * @docs https://docs.gitlab.com/ee/api/merge_requests.html#update-mr */ - public function apiUpdateMR($gitlabID, $projectID, $params) + public function apiUpdateMR($gitlabID, $projectID, $mrID, $params) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + $mr = new stdclass; + return json_decode(commonModel::http($url, $mr, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** @@ -151,6 +160,8 @@ class mrModel extends model */ public function apiDeleteMR($gitlabID, $projectID, $mrID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } /** @@ -165,6 +176,8 @@ class mrModel extends model */ public function apiAcceptMR($gitlabID, $projectID, $mrID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + return json_decode(commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** @@ -179,6 +192,8 @@ class mrModel extends model */ public function apiGetDiffVersions($gitlabID, $projectID, $mrID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + return json_decode(commonModel::http($url)); } /** @@ -194,6 +209,8 @@ class mrModel extends model */ public function apiGetSingleDiffVersion($gitlabID, $projectID, $mrID, $versionID) { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID/versions/$versionID"); + return json_decode(commonModel::http($url)); } } From e0b0777126f44cbe6ebab58c1b2dab2a0e9d1042 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 17:33:32 +0800 Subject: [PATCH 009/154] * Update MR model. --- module/mr/model.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index b2bb07040e..1d205cc85a 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -12,7 +12,7 @@ class mrModel extends model { /** - * The construc method, to do some auto things. + * The construct method, to do some auto things. * * @access public * @return void @@ -23,6 +23,18 @@ class mrModel extends model $this->loadModel('gitlab'); } + public function getGitlabProjectByRepo($repoID) + { + $repo = $this->loadModel('repo')->getRepoByID($repoID); + + $gitlab = new stdclass; + $gitlab->product = explode(',', $repo->product); + $gitlab->gitlabID = $repo->gitlab; + $gitlab->projectID = $repo->project; + + return $gitlab; + } + /** * Get a MR by id. * @@ -32,7 +44,7 @@ class mrModel extends model */ public function getByID($id) { - return $this->dao->select(*)->from(TABLE_MR)->where('id')->eq($id)->fetch(); + return $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); } /** @@ -79,7 +91,7 @@ class mrModel extends model */ public function getApiRoot($gitlabID) { - return $this->gitlab->getAppRoot($gitlabID); + return $this->gitlab->getApiRoot($gitlabID); } /** From 753fb1b2cd956bb08561aa51115b58af19a9b375 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 13 Aug 2021 17:35:29 +0800 Subject: [PATCH 010/154] * Add list function for mr control(staging). --- module/mr/control.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index fe9515a75c..53b84ee298 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -30,6 +30,14 @@ class mr extends control $this->display(); } + public function list($repoID) + { + $gitlab = $this->mr->getGitlabProjectByRepo($repoID); + $resp = $this->mr->apiGetMRList($gitlab->gitlabID, $gitlab->projectID); + a($resp); + return $resp; + } + public function create() { } @@ -38,7 +46,6 @@ class mr extends control { } - public function update() { } From fa062b6b8446b24ff3e3b2b231dd4f9b03cc1596 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 16 Aug 2021 14:37:04 +0800 Subject: [PATCH 011/154] * Create MR view. --- module/mr/control.php | 16 ++++++++++ module/mr/js/create.js | 23 ++++++++++++++ module/mr/lang/zh-cn.php | 28 ++++++++++++----- module/mr/model.php | 29 +++++++++++++++++ module/mr/view/browse.html.php | 7 +++-- module/mr/view/create.html.php | 57 ++++++++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 module/mr/js/create.js create mode 100644 module/mr/view/create.html.php diff --git a/module/mr/control.php b/module/mr/control.php index 53b84ee298..4589882398 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -40,6 +40,22 @@ class mr extends control public function create() { + $this->loadModel('repo'); + if($_POST) + { + $mrID = $this->mr->create(); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $repoID)); + $link = helper::createLink('mr', 'browse', '', '', false); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); + } + + $this->view->title = $this->lang->mr->create; + $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); + + $this->display(); } public function delete() diff --git a/module/mr/js/create.js b/module/mr/js/create.js new file mode 100644 index 0000000000..e2df836950 --- /dev/null +++ b/module/mr/js/create.js @@ -0,0 +1,23 @@ +$(function() +{ + $('#gitlabID').change(function() + { + host = $('#gitlabID').val(); + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); + if(host == '') return false; + + $.get(url, function(response) + { + $('#projectID').html('').append(response); + $('#projectID').chosen().trigger("chosen:updated");; + }); + }); + + $('#projectID').change(function() + { + $option = $(this).find('option:selected'); + $('#name').val($option.data('name')); + }); + +}); + diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index d853f2844f..bad4505a98 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -1,13 +1,27 @@ mr->common = "合并请求"; $lang->mr->create = "创建{$lang->mr->common}"; +$lang->mr->browse = "浏览{$lang->mr->common}"; +$lang->mr->list = $lang->mr->browse; +$lang->mr->edit = "编辑{$lang->mr->common}"; +$lang->mr->delete = "删除{$lang->mr->common}"; $lang->mr->add = "添加GitLab项目"; -$lang->mr->id = 'ID'; -$lang->mr->name = '名称'; -$lang->mr->source = '源项目分支'; -$lang->mr->targer = '目标分支'; -$lang->mr->pipeline = '流水线'; -$lang->mr->audit = '审核状态'; -$lang->mr->execute = '执行状态'; +$lang->mr->id = 'ID'; +$lang->mr->name = '名称'; +$lang->mr->source = '源项目分支'; +$lang->mr->targer = '目标分支'; +$lang->mr->pipeline = '流水线'; +$lang->mr->audit = '审核状态'; +$lang->mr->execute = '执行状态'; + +$lang->mr->sourceProject = '源项目'; +$lang->mr->sourceBranch = '源分支'; +$lang->mr->targetProject = '目标项目'; +$lang->mr->targetBranch = '目标分支'; + +$lang->mr->compareBranch = '比较分支'; +$lang->mr->and = '并'; +$lang->mr->continue = '继续'; +$lang->mr->cmpAndContinue = $lang->mr->compareBranch . $lang->mr->and . $lang->mr->continue; diff --git a/module/mr/model.php b/module/mr/model.php index 1d205cc85a..3554ee895a 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -82,6 +82,19 @@ class mrModel extends model return array('' => '') + $mr; } + public function create() + { + $gitlabID = $this->post->gitlabID; + $projectID = $this->post->projectID; + + $sourceProject = $this->post->sourceProject; + $sourceBranch = $this->post->sourceBranch; + $targetProject = $this->post->targetProject; + $targetBranch = $this->post->targetBranch; + + + } + /** * Get gitlab api base url by gitlab ID. * @@ -94,6 +107,22 @@ class mrModel extends model return $this->gitlab->getApiRoot($gitlabID); } + /** + * Get Forks of a project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project + */ + public function apiGetForks($gitlabID, $projectID) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/forks"); + $mr = new stdclass; + return json_decode(commonModel::http($url)); + } + /** * Create MR by API. * diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 7636aacabf..dbf0992872 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -38,9 +38,10 @@ diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php new file mode 100644 index 0000000000..86270b559f --- /dev/null +++ b/module/mr/view/create.html.php @@ -0,0 +1,57 @@ + + +
+
+
+ +
id}", $lang->mr->common, 'list', 'review'); common::printIcon('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', 'list', 'edit'); - common::printIcon('mr', 'create', "repo={$repo->id}", $lang->mr->create, 'list', 'review'); if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); ?> id}", $lang->mr->common, 'list', 'review'); - common::printIcon('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', 'list', 'edit'); - if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); + common::printLink('mr', 'list', "repo={$repo->id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'create', "repo={$repo->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); + common::printLink('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?>
+ + + + + + + + + + + + + + + + + + +
repo->gitlabHost;?>repo->placeholder->gitlabHost}'");?> +
repo->gitlabProject;?> +
mr->sourceProject;?> +
+ + mr->sourceBranch ?> + +
+
mr->targetProject;?> +
+ + mr->targetBranch ?> + +
+
+ mr->cmpAndContinue); ?> + goback, '', 'class="btn btn-wide"');?> +
+
+
+ + + From 92cac9b4c2f2ffbd70dea08ba29d6b1fede65496 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 16 Aug 2021 07:29:19 +0000 Subject: [PATCH 012/154] * Adjust the gitlab validation style. --- module/gitlab/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 22d0ed511f..7c8d75630e 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -186,7 +186,7 @@ class gitlab extends control $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); if(!is_object($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); - if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->hostError, 'locate' => 'parent')); } /** From fc3a74c1d4e5ed1b96c9a643301d795aa43d4c8c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 16 Aug 2021 17:44:52 +0800 Subject: [PATCH 013/154] * Add merge request list view. --- module/mr/control.php | 19 +++++++++++--- module/mr/js/create.js | 2 ++ module/mr/lang/zh-cn.php | 15 ++++++----- module/mr/model.php | 1 + module/mr/view/browse.html.php | 2 +- module/mr/view/create.html.php | 1 + module/mr/view/list.html.php | 46 ++++++++++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 module/mr/view/list.html.php diff --git a/module/mr/control.php b/module/mr/control.php index 4589882398..18b1bca7c9 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -30,12 +30,23 @@ class mr extends control $this->display(); } - public function list($repoID) + public function list($repoID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { + $this->loadModel('gitlab'); $gitlab = $this->mr->getGitlabProjectByRepo($repoID); - $resp = $this->mr->apiGetMRList($gitlab->gitlabID, $gitlab->projectID); - a($resp); - return $resp; + $mrList = $this->mr->apiGetMRList($gitlab->gitlabID, $gitlab->projectID); + + $this->app->loadClass('pager', $static = true); + $recTotal = count($mrList); + $pager = new pager($recTotal, $recPerPage, $pageID); + $mrList = array_chunk($mrList, $pager->recPerPage); + + $this->view->title = $this->lang->mr->browse; + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; + + $this->display(); } public function create() diff --git a/module/mr/js/create.js b/module/mr/js/create.js index e2df836950..21f3b6954a 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -10,6 +10,8 @@ $(function() { $('#projectID').html('').append(response); $('#projectID').chosen().trigger("chosen:updated");; + $('#sourceProject').html('').append(response); + $('#sourceProject').chosen().trigger("chosen:updated");; }); }); diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index bad4505a98..9434a0ced6 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -5,16 +5,19 @@ $lang->mr->browse = "浏览{$lang->mr->common}"; $lang->mr->list = $lang->mr->browse; $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; -$lang->mr->add = "添加GitLab项目"; +$lang->mr->detail = "详情"; +$lang->mr->addGitlab = "添加GitLab项目"; $lang->mr->id = 'ID'; +$lang->mr->iid = "{$lang->mr->common}ID"; $lang->mr->name = '名称'; -$lang->mr->source = '源项目分支'; -$lang->mr->targer = '目标分支'; -$lang->mr->pipeline = '流水线'; -$lang->mr->audit = '审核状态'; -$lang->mr->execute = '执行状态'; +$lang->mr->title = $lang->mr->name; +$lang->mr->status = '状态'; +$lang->mr->author = '创建人'; +$lang->mr->assignee = '指派给'; +$lang->mr->reviewer = '评审人'; +$lang->mr->link = 'GitLab链接'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/model.php b/module/mr/model.php index 3554ee895a..9a9e1e9e23 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -92,6 +92,7 @@ class mrModel extends model $targetProject = $this->post->targetProject; $targetBranch = $this->post->targetBranch; + if($projectID != $sourceProject) return false; } diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index dbf0992872..877916ca42 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,7 +1,7 @@
diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 86270b559f..917b1520a8 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -26,6 +26,7 @@ mr->sourceProject;?>
+ mr->sourceBranch ?> diff --git a/module/mr/view/list.html.php b/module/mr/view/list.html.php new file mode 100644 index 0000000000..36fdadf0e5 --- /dev/null +++ b/module/mr/view/list.html.php @@ -0,0 +1,46 @@ + + +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> + + + + + + + + + + + + + + + + + + + + +
mr->id); ?>mr->name); ?>mr->sourceProject); ?>mr->targetProject); ?>mr->status); ?>actions; ?>
id; ?>createLink('mr', 'browse', "mrID={$mr->id}"), $mr->title);?>source_project_id . ":" . $mr->source_branch;?>target_project_id . ":" . $mr->target_branch;?>state;?> + id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); + common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + ?> +
+ + + +
+
+ From d23d3adf03d869ac948bf67dd523561fa26bcb61 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 17 Aug 2021 09:47:22 +0800 Subject: [PATCH 014/154] * Remove extra project selector in create view. --- module/mr/js/create.js | 4 +--- module/mr/view/create.html.php | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/module/mr/js/create.js b/module/mr/js/create.js index 21f3b6954a..dc117c16f7 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -8,14 +8,12 @@ $(function() $.get(url, function(response) { - $('#projectID').html('').append(response); - $('#projectID').chosen().trigger("chosen:updated");; $('#sourceProject').html('').append(response); $('#sourceProject').chosen().trigger("chosen:updated");; }); }); - $('#projectID').change(function() + $('#sourceProject').change(function() { $option = $(this).find('option:selected'); $('#name').val($option.data('name')); diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 917b1520a8..1e4323582a 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -18,10 +18,6 @@ repo->gitlabHost;?> repo->placeholder->gitlabHost}'");?> - - repo->gitlabProject;?> - - mr->sourceProject;?> From 3dc7a2111b1755c7e08a0824a3a6369c2d6261fb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 17 Aug 2021 17:44:58 +0800 Subject: [PATCH 015/154] + Get project branches. --- module/gitlab/control.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 7c8d75630e..0193f67792 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -349,4 +349,25 @@ class gitlab extends control } return $this->send($options); } + + /** + * AJAX: Get project branches. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function ajaxGetProjectBranches($gitlabID, $projectID) + { + if(!$gitlabID or !$projectID) return $this->send(array('message' => array())); + + $branches = $this->gitlab->apiGetBranches($gitlabID, $projectID); + $options = ""; + foreach($branches as $index =>$branch) + { + $options .= ""; + } + return $this->send($options); + } } From 5728c38e66ba84c4243449cd731ba10461e17bc4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 17 Aug 2021 17:49:47 +0800 Subject: [PATCH 016/154] * Remove and correct useless statements. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e80bbf41e2..8b49ceda0c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -277,8 +277,8 @@ class gitlabModel extends model public function getRefOptions($gitlabID, $projectID) { $refList = array(); - $branches = $this->loadModel('gitlab')->apiGetBranches($gitlabID, $projectID); - $tags = $this->loadModel('gitlab')->apiGetTags($gitlabID, $projectID); + $branches = $this->apiGetBranches($gitlabID, $projectID); + $tags = $this->apiGetTags($gitlabID, $projectID); foreach($branches as $branch) $refList[] = "Branch::" . $branch->name; foreach($tags as $tag) $refList[] = "Tag::" . $tag->name; return $refList; From d9683594db29515294c4ab2730f3022c81101ae4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 17 Aug 2021 17:52:05 +0800 Subject: [PATCH 017/154] + Get forked projects. --- module/mr/control.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/module/mr/control.php b/module/mr/control.php index 18b1bca7c9..100d6928df 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -76,5 +76,29 @@ class mr extends control public function update() { } + + /** + * AJAX: Get forked projects. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function ajaxGetForkedProjects($gitlabID, $projectID) + { + $projects = $this->mr->apiGetForks($gitlabID, $projectID); + + if(!$projects) return $this->send(array('message' => array())); + $projectIdList = $projectIdList ? explode(',', $projectIdList) : null; + $options = ""; + foreach($projects as $project) + { + if(!empty($projectIdList) and $project and !in_array($project->id, $projectIdList)) continue; + $options .= ""; + } + + return $this->send($options); + } } From 549ea9bbde37743868293fdff517707939a7320c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 17 Aug 2021 17:52:55 +0800 Subject: [PATCH 018/154] * Create MR(staging). --- module/mr/js/create.js | 11 ++++++++++- module/mr/view/create.html.php | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/module/mr/js/create.js b/module/mr/js/create.js index dc117c16f7..3ab3aa2b2f 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -3,8 +3,8 @@ $(function() $('#gitlabID').change(function() { host = $('#gitlabID').val(); - url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); if(host == '') return false; + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); $.get(url, function(response) { @@ -17,6 +17,15 @@ $(function() { $option = $(this).find('option:selected'); $('#name').val($option.data('name')); + project = $('#sourceProject').val(); + url = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + host + "&projectID=" + project); + $.get(url, function(response) + { + $('#sourceBranch').html('').append(response); + $('#sourceBranch').chosen().trigger("chosen:updated");; + }); + + $('#targetProject').chosen().trigger("chosen:updated");; }); }); diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 1e4323582a..d05a6824db 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -22,7 +22,6 @@ mr->sourceProject;?>
- mr->sourceBranch ?> From 8ebe5b4cc9dc7c666a4ced2e719c7b8c5fa60321 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 17 Aug 2021 11:14:56 +0000 Subject: [PATCH 019/154] * adjust the GitLab list function --- module/gitlab/model.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e80bbf41e2..aa350199fb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -34,12 +34,40 @@ class gitlabModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager); + $pipeline = $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager); + + $lists = array(); + foreach ($pipeline as $pipelineGitlab) + { + $token = $this->apiGetCurrentUser($pipelineGitlab->url,$pipelineGitlab->token); + + $list = new stdclass; + + $list->id = $pipelineGitlab->id; + $list->type = $pipelineGitlab->type; + $list->name = $pipelineGitlab->name; + $list->url = $pipelineGitlab->url; + $list->account = $pipelineGitlab->account; + $list->password = $pipelineGitlab->password; + $list->token = $pipelineGitlab->token; + $list->private = $pipelineGitlab->private; + $list->createdBy = $pipelineGitlab->createdBy; + $list->createdDate = $pipelineGitlab->createdDate; + $list->editedBy = $pipelineGitlab->editedBy; + $list->editedDate = $pipelineGitlab->editedDate; + $list->deleted = $pipelineGitlab->deleted; + $list->is_admin = $token->is_admin; + + $lists[] = $list; + } + + return $lists; } /** * Get gitlab pairs. * + * @access public * @return array */ From 474b438db778d8cd2d662e5c82aa7f8bdbeb5564 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 18 Aug 2021 10:27:31 +0800 Subject: [PATCH 020/154] * Optimize main page of MR. --- module/mr/control.php | 20 +++++-------- module/mr/lang/zh-cn.php | 5 ++-- module/mr/model.php | 3 +- module/mr/view/browse.html.php | 53 +++++++++++++++------------------- 4 files changed, 34 insertions(+), 47 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 100d6928df..ac5617884d 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -3,28 +3,22 @@ class mr extends control { public function browse($objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - $this->loadModel('repo'); - - $repoList = $this->repo->getList(0, $orderBy); - foreach($repoList as $id => $repo) - { - if(strtolower($repo->SCM) != 'gitlab') unset($repoList[$id]); - } + $mrList = $this->mr->getList($orderBy); /* Pager. */ $this->app->loadClass('pager', $static = true); - $recTotal = count($repoList); + $recTotal = count($mrList); $pager = new pager($recTotal, $recPerPage, $pageID); - $repoList = array_chunk($repoList, $pager->recPerPage); + $mrList = array_chunk($mrList, $pager->recPerPage); - $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->browse; - $this->view->position[] = $this->lang->repo->common; - $this->view->position[] = $this->lang->repo->browse; + $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; + $this->view->position[] = $this->lang->mr->common; + $this->view->position[] = $this->lang->mr->browse; $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->pager = $pager; - $this->view->repoList = empty($repoList) ? $repoList: $repoList[$pageID - 1];; + $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; $this->view->products = $this->loadModel('product')->getPairs(); $this->display(); diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 9434a0ced6..323ff634c8 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -7,17 +7,16 @@ $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; $lang->mr->detail = "详情"; -$lang->mr->addGitlab = "添加GitLab项目"; - $lang->mr->id = 'ID'; $lang->mr->iid = "{$lang->mr->common}ID"; -$lang->mr->name = '名称'; +$lang->mr->name = "{$lang->mr->common}名称"; $lang->mr->title = $lang->mr->name; $lang->mr->status = '状态'; $lang->mr->author = '创建人'; $lang->mr->assignee = '指派给'; $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; +$lang->mr->project = 'GitLab项目'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/model.php b/module/mr/model.php index 9a9e1e9e23..d06cceab92 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -55,12 +55,11 @@ class mrModel extends model * @access public * @return array */ - public function getList($repoID, $orderBy = 'id_desc', $pager = null) + public function getList($orderBy = 'id_desc', $pager = null) { return $this->dao->select('*') ->from(TABLE_MR) ->where('deleted')->eq('0') - ->AndWhere('repoID')->eq($repoID) ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 877916ca42..ce554da339 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,56 +1,51 @@
+ +
+

+ noData . $lang->mr->common;?> + + createLink('mr', 'create'), " " . $lang->mr->create, '', "class='btn btn-info'");?> + +

+
+
recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> - - - - + + - + - - - - + +
repo->id); ?>repo->type); ?>repo->name); ?>repo->product); ?>mr->id); ?>mr->project); ?> actions; ?>
id; ?>repo->scmList, $repo->SCM); ?>createLink('repo', 'browse', "repoID={$repo->id}&branchID=&objectID=$objectID"), $repo->name);?> - product)); - if(isset($productList) and $productList[0]) - { - foreach($productList as $productID) - { - if(!isset($products[$productID])) continue; - echo ' ' . html::a($this->createLink('product', 'browse', "productID=$productID"), zget($products, $productID, $productID)); - } - } - ?> - id; ?>createLink('mr', 'browse', "mrID={$mr->id}&branchID=&objectID=$objectID"), $mr->projectID);?> - id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'create', "repo={$repo->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); - common::printLink('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); - ?> + id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); + common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + ?>
- +
+
From 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 18 Aug 2021 10:40:15 +0800 Subject: [PATCH 021/154] * Rename getObjectNameForJob to getProjectName. --- module/gitlab/model.php | 5 +++-- module/job/view/browse.html.php | 2 +- module/job/view/view.html.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 087721d341..9cc0439aa1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -283,11 +283,12 @@ class gitlabModel extends model /** * Get gitlab project name of one gitlab project. * - * @param int $jobID + * @param int $gitlabID + * @param int $projectID * @access public * @return string|false */ - public function getObjectNameForJob($gitlabID, $projectID) + public function getProjectName($gitlabID, $projectID) { $project = $this->apiGetSingleProject($gitlabID, $projectID); if(isset($project->name)) return $project->name; diff --git a/module/job/view/browse.html.php b/module/job/view/browse.html.php index 8e3d0139d5..7e0b15f941 100644 --- a/module/job/view/browse.html.php +++ b/module/job/view/browse.html.php @@ -56,7 +56,7 @@ repoName;?> job->engineList, $job->engine);?> job->frameList, $job->frame);?> - engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getObjectNameForJob($job->server, $job->pipeline);?> + engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getProjectName($job->server, $job->pipeline);?> pipeline) . '@' . $job->jenkinsName;?> job->getTriggerConfig($job);?> diff --git a/module/job/view/view.html.php b/module/job/view/view.html.php index cab49151d0..95a6d3cd61 100644 --- a/module/job/view/view.html.php +++ b/module/job/view/view.html.php @@ -55,7 +55,7 @@ job->server;?> - engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getObjectNameForJob($job->server, $job->pipeline);?> + engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getProjectName($job->server, $job->pipeline);?> pipeline) . '@' . $jenkins->name;?> From 2ae9360cdfc57cc011ae4bb3931f891ae64f5e59 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 18 Aug 2021 02:57:36 +0000 Subject: [PATCH 022/154] * Add Gitlab MR List Function. --- module/mr/control.php | 29 +++++++++----------- module/mr/lang/zh-cn.php | 21 ++++++++------- module/mr/model.php | 28 +++++++++++++++++--- module/mr/view/browse.html.php | 48 +++++++++++++++------------------- 4 files changed, 70 insertions(+), 56 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 100d6928df..fc7ea45d7a 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -3,37 +3,32 @@ class mr extends control { public function browse($objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - $this->loadModel('repo'); + $this->loadModel('mr'); - $repoList = $this->repo->getList(0, $orderBy); - foreach($repoList as $id => $repo) - { - if(strtolower($repo->SCM) != 'gitlab') unset($repoList[$id]); - } + $mrList = $this->mr->getList(0, $orderBy); /* Pager. */ $this->app->loadClass('pager', $static = true); - $recTotal = count($repoList); + $recTotal = count($mrList); $pager = new pager($recTotal, $recPerPage, $pageID); - $repoList = array_chunk($repoList, $pager->recPerPage); + $mrList = array_chunk($mrList, $pager->recPerPage); - $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->browse; - $this->view->position[] = $this->lang->repo->common; - $this->view->position[] = $this->lang->repo->browse; + $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; + $this->view->position[] = $this->lang->mr->common; + $this->view->position[] = $this->lang->mr->browse; $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->pager = $pager; - $this->view->repoList = empty($repoList) ? $repoList: $repoList[$pageID - 1];; - $this->view->products = $this->loadModel('product')->getPairs(); + $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; $this->display(); } - public function list($repoID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function list($mrID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $this->loadModel('gitlab'); - $gitlab = $this->mr->getGitlabProjectByRepo($repoID); + $gitlab = $this->mr->getGitlabProjectByRepo($mrID); $mrList = $this->mr->apiGetMRList($gitlab->gitlabID, $gitlab->projectID); $this->app->loadClass('pager', $static = true); @@ -51,14 +46,14 @@ class mr extends control public function create() { - $this->loadModel('repo'); + $this->loadModel('mr'); if($_POST) { $mrID = $this->mr->create(); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $repoID)); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $mrID)); $link = helper::createLink('mr', 'browse', '', '', false); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 9434a0ced6..24251ffcab 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -9,15 +9,18 @@ $lang->mr->detail = "详情"; $lang->mr->addGitlab = "添加GitLab项目"; -$lang->mr->id = 'ID'; -$lang->mr->iid = "{$lang->mr->common}ID"; -$lang->mr->name = '名称'; -$lang->mr->title = $lang->mr->name; -$lang->mr->status = '状态'; -$lang->mr->author = '创建人'; -$lang->mr->assignee = '指派给'; -$lang->mr->reviewer = '评审人'; -$lang->mr->link = 'GitLab链接'; +$lang->mr->id = 'ID'; +$lang->mr->iid = "{$lang->mr->common}ID"; +$lang->mr->name = '名称'; +$lang->mr->title = $lang->mr->name; +$lang->mr->status = '状态'; +$lang->mr->author = '创建人'; +$lang->mr->assignee = '指派给'; +$lang->mr->reviewer = '评审人'; +$lang->mr->link = 'GitLab链接'; +$lang->mr->pipeline = '流水线'; +$lang->mr->auditStatus = '审核状态'; +$lang->mr->lastExec = '执行状态'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/model.php b/module/mr/model.php index 9a9e1e9e23..377c998b88 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -55,15 +55,37 @@ class mrModel extends model * @access public * @return array */ - public function getList($repoID, $orderBy = 'id_desc', $pager = null) + public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*') + $mrList = $this->dao->select('*') ->from(TABLE_MR) ->where('deleted')->eq('0') - ->AndWhere('repoID')->eq($repoID) ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); + + if(!empty($mrList)) + { + $lists = array(); + foreach($mrList as $mr) + { + foreach($this->apiGetMRList($mr->gitlabID, $mr->projectID) as $subMR) + { + $list = new stdclass; + + $list->id = $subMR->id; + $list->name = $subMR->title; + $list->target_branch = $subMR->target_branch; + $list->source_branch = $subMR->source_branch; + $list->pipeline = $subMR->merge_when_pipeline_succeeds; + $list->auditStatus = $subMR->state; + $list->lastExec = $subMR->merge_status; + + $lists[] = $list; + } + } + return $lists; + } } /** diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 877916ca42..960ee7a6f0 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,7 +1,7 @@
@@ -10,45 +10,39 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> - repo->id); ?> - repo->type); ?> - repo->name); ?> - repo->product); ?> + mr->id); ?> + mr->name); ?> + mr->sourceBranch); ?> + mr->targetBranch); ?> + mr->pipeline); ?> + mr->auditStatus); ?> + mr->lastExec); ?> actions; ?> - + - id; ?> - repo->scmList, $repo->SCM); ?> - createLink('repo', 'browse', "repoID={$repo->id}&branchID=&objectID=$objectID"), $repo->name);?> - - product)); - if(isset($productList) and $productList[0]) - { - foreach($productList as $productID) - { - if(!isset($products[$productID])) continue; - echo ' ' . html::a($this->createLink('product', 'browse', "productID=$productID"), zget($products, $productID, $productID)); - } - } - ?> - + id; ?> + name; ?> + target_branch; ?> + source_branch; ?> + pipeline; ?> + auditStatus; ?> + lastExec; ?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'create', "repo={$repo->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); - common::printLink('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + common::printLink('mr', 'list', "mr={$mr->id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); + common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> - + From 6648beb06776ed1238020dd5a6bd7df841e2dd4e Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 18 Aug 2021 03:05:02 +0000 Subject: [PATCH 023/154] * MR code merge. --- module/mr/control.php | 9 --------- module/mr/lang/zh-cn.php | 13 ------------- module/mr/view/browse.html.php | 19 ------------------- 3 files changed, 41 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 7146e75753..49dc131b63 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -3,13 +3,9 @@ class mr extends control { public function browse($objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { -<<<<<<< HEAD $this->loadModel('mr'); $mrList = $this->mr->getList(0, $orderBy); -======= - $mrList = $this->mr->getList($orderBy); ->>>>>>> 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd /* Pager. */ $this->app->loadClass('pager', $static = true); @@ -25,11 +21,6 @@ class mr extends control $this->view->objectID = $objectID; $this->view->pager = $pager; $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; -<<<<<<< HEAD -======= - $this->view->products = $this->loadModel('product')->getPairs(); ->>>>>>> 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd - $this->display(); } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 6c61e31098..24251ffcab 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -7,7 +7,6 @@ $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; $lang->mr->detail = "详情"; -<<<<<<< HEAD $lang->mr->addGitlab = "添加GitLab项目"; $lang->mr->id = 'ID'; @@ -22,18 +21,6 @@ $lang->mr->link = 'GitLab链接'; $lang->mr->pipeline = '流水线'; $lang->mr->auditStatus = '审核状态'; $lang->mr->lastExec = '执行状态'; -======= -$lang->mr->id = 'ID'; -$lang->mr->iid = "{$lang->mr->common}ID"; -$lang->mr->name = "{$lang->mr->common}名称"; -$lang->mr->title = $lang->mr->name; -$lang->mr->status = '状态'; -$lang->mr->author = '创建人'; -$lang->mr->assignee = '指派给'; -$lang->mr->reviewer = '评审人'; -$lang->mr->link = 'GitLab链接'; -$lang->mr->project = 'GitLab项目'; ->>>>>>> 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index feb9d59e92..55f67c6bd8 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,11 +1,7 @@
@@ -25,16 +21,12 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> mr->id); ?> -<<<<<<< HEAD mr->name); ?> mr->sourceBranch); ?> mr->targetBranch); ?> mr->pipeline); ?> mr->auditStatus); ?> mr->lastExec); ?> -======= - mr->project); ?> ->>>>>>> 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd actions; ?> @@ -42,7 +34,6 @@ id; ?> -<<<<<<< HEAD name; ?> target_branch; ?> source_branch; ?> @@ -56,16 +47,6 @@ common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> -======= - createLink('mr', 'browse', "mrID={$mr->id}&branchID=&objectID=$objectID"), $mr->projectID);?> - - id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); - common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); - ?> ->>>>>>> 14de596bc0f1fc905a6c0cea6ac0eefd839e61fd From 34391dbe4cbd427a92224002e0ea6d2c7ffa513c Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 18 Aug 2021 08:49:02 +0000 Subject: [PATCH 024/154] * Adjust Gitlab list function. --- module/gitlab/control.php | 9 ++++++++- module/gitlab/model.php | 29 ++--------------------------- module/gitlab/view/browse.html.php | 7 ++++--- module/group/lang/resource.php | 10 ++++++++-- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0193f67792..d5d3e7ceef 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -29,8 +29,15 @@ class gitlab extends control $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); + $gitlabList = $this->gitlab->getList($orderBy, $pager); + foreach($gitlabList as $gitlab) + { + $token = $this->gitlab->apiGetCurrentUser($gitlab->url,$gitlab->token); + $gitlab->isAdminToken = $token->is_admin; + } + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; - $this->view->gitlabList = $this->gitlab->getList($orderBy, $pager); + $this->view->gitlabList = $gitlabList; $this->view->orderBy = $orderBy; $this->view->pager = $pager; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 9cc0439aa1..4b91dbc2d4 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -34,34 +34,9 @@ class gitlabModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - $pipeline = $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager); + $gitlabList = $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager); - $lists = array(); - foreach ($pipeline as $pipelineGitlab) - { - $token = $this->apiGetCurrentUser($pipelineGitlab->url,$pipelineGitlab->token); - - $list = new stdclass; - - $list->id = $pipelineGitlab->id; - $list->type = $pipelineGitlab->type; - $list->name = $pipelineGitlab->name; - $list->url = $pipelineGitlab->url; - $list->account = $pipelineGitlab->account; - $list->password = $pipelineGitlab->password; - $list->token = $pipelineGitlab->token; - $list->private = $pipelineGitlab->private; - $list->createdBy = $pipelineGitlab->createdBy; - $list->createdDate = $pipelineGitlab->createdDate; - $list->editedBy = $pipelineGitlab->editedBy; - $list->editedDate = $pipelineGitlab->editedDate; - $list->deleted = $pipelineGitlab->deleted; - $list->is_admin = $token->is_admin; - - $lists[] = $list; - } - - return $lists; + return $gitlabList; } /** diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 3ddbdcdf5a..c4a5663170 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -46,9 +46,10 @@ url;?> createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); + $disabled = !empty($gitlab->isAdminToken) ? '' : 'disabled'; + common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary {$disabled}'"); + common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$lang->gitlab->bindUser} class='btn btn-primary {$disabled}'"); + if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn {$disabled}'"); ?> diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index ebabdcb63d..bb693f5039 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -63,6 +63,7 @@ $lang->moduleOrder[205] = 'cron'; $lang->moduleOrder[210] = 'dev'; $lang->moduleOrder[215] = 'message'; $lang->moduleOrder[220] = 'gitlab'; +$lang->moduleOrder[225] = 'mr'; $lang->resource = new stdclass(); @@ -1132,13 +1133,13 @@ $lang->svn->methodOrder[15] = 'apiSync'; /* GitLab. */ $lang->resource->gitlab = new stdclass(); -$lang->resource->gitlab->browse = 'browse'; $lang->resource->gitlab->create = 'create'; $lang->resource->gitlab->edit = 'edit'; $lang->resource->gitlab->importIssue = 'importIssue'; $lang->resource->gitlab->delete = 'delete'; $lang->resource->gitlab->bindUser = 'bindUser'; $lang->resource->gitlab->bindProduct = 'bindProduct'; + //$lang->resource->gitlab->webhook = 'webhook'; $lang->gitlab->methodOrder[5] = 'browse'; @@ -1147,9 +1148,14 @@ $lang->gitlab->methodOrder[15] = 'edit'; $lang->gitlab->methodOrder[20] = 'importIssue'; $lang->gitlab->methodOrder[30] = 'delete'; $lang->gitlab->methodOrder[35] = 'bindUser'; -$lang->gitlab->methodOrder[40] = 'bindProduct'; //$lang->gitlab->methodOrder[45] = 'webhook'; +/* merge request. */ +$lang->resource->mr = new stdclass(); +$lang->resource->mr->common = "common"; + +$lang->mr->methodOrder[5] = 'common'; + /* Git. */ $lang->resource->git = new stdclass(); $lang->resource->git->diff = 'diff'; From 8551ba49e303e5c1af6683ab2ecec7a8fe11d2af Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 19 Aug 2021 00:46:15 +0000 Subject: [PATCH 025/154] * Adjust mr control browse function. --- module/mr/control.php | 13 +++++++++++-- module/mr/lang/zh-cn.php | 4 +--- module/mr/model.php | 5 ++--- module/mr/view/browse.html.php | 10 ++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 49dc131b63..8940fc16b4 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -1,6 +1,17 @@ loadModel('mr'); @@ -14,8 +25,6 @@ class mr extends control $mrList = array_chunk($mrList, $pager->recPerPage); $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; - $this->view->position[] = $this->lang->mr->common; - $this->view->position[] = $this->lang->mr->browse; $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 24251ffcab..d814172873 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -18,9 +18,7 @@ $lang->mr->author = '创建人'; $lang->mr->assignee = '指派给'; $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; -$lang->mr->pipeline = '流水线'; -$lang->mr->auditStatus = '审核状态'; -$lang->mr->lastExec = '执行状态'; +$lang->mr->mrStatus = '合并状态'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/model.php b/module/mr/model.php index 377c998b88..806214cfde 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -77,9 +77,8 @@ class mrModel extends model $list->name = $subMR->title; $list->target_branch = $subMR->target_branch; $list->source_branch = $subMR->source_branch; - $list->pipeline = $subMR->merge_when_pipeline_succeeds; - $list->auditStatus = $subMR->state; - $list->lastExec = $subMR->merge_status; + $list->status = $subMR->state; + $list->mrStatus = $subMR->merge_status; $lists[] = $list; } diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 55f67c6bd8..3b3c60e385 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -24,9 +24,8 @@ mr->name); ?> mr->sourceBranch); ?> mr->targetBranch); ?> - mr->pipeline); ?> - mr->auditStatus); ?> - mr->lastExec); ?> + mr->status); ?> + mr->mrStatus); ?> actions; ?> @@ -37,9 +36,8 @@ name; ?> target_branch; ?> source_branch; ?> - pipeline; ?> - auditStatus; ?> - lastExec; ?> + status; ?> + mrStatus; ?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); From 120a2cd068cf04c5c14e2d1304db3a01c40c900f Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 19 Aug 2021 10:20:38 +0800 Subject: [PATCH 026/154] * Fix create zt_mr table sql. --- db/zentao.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/zentao.sql b/db/zentao.sql index f46d4d97d6..98f0e527f2 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -546,11 +546,11 @@ CREATE TABLE IF NOT EXISTS `zt_module` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_mr`; CREATE TABLE `zt_mr` ( - `id` int NOT NULL, - `repoID` int NOT NULL, - `gitlabID` int NOT NULL, - `projectID` int NOT NULL, - `mrID` int NOT NULL, + `id` mediumint(8) unsigned NOT NULL auto_increment, + `repoID` mediumint(8) unsigned NOT NULL, + `gitlabID` mediumint(8) unsigned NOT NULL, + `projectID` mediumint(8) unsigned NOT NULL, + `mrID` mediumint(8) unsigned NOT NULL, `title` varchar(255) NOT NULL, `description` text NOT NULL, `assignees` varchar(255) NOT NULL, From e5e0ec2c8d1bdf3932f00ab1ba0be28ac5222507 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 19 Aug 2021 02:37:48 +0000 Subject: [PATCH 027/154] * Add delete MR function.* Add delete MR function.* Add delete MR function.* Add delete MR function.* Add delete MR function.* Add delete MR function.* Add delete MR function.* Add delete MR function. --- module/mr/control.php | 17 ++++++++++++++++- module/mr/lang/zh-cn.php | 1 + module/mr/model.php | 23 +++++++++++++++++++++++ module/mr/view/browse.html.php | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 8940fc16b4..5b856ef19b 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -72,8 +72,23 @@ class mr extends control $this->display(); } - public function delete() + /** + * Delete a mr. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return void + */ + public function delete($gitlabID, $projectID, $mrID, $confim = 'no') { + if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "productID=$projectID&gitlabID=$gitlabID&mrID=$mrID&confirm=yes"))); + + $this->mr->apiDeleteMR($gitlabID, $projectID, $mrID); + + $this->gitlab->delete(TABLE_PIPELINE, $id); + die(js::reload('parent')); } public function update() diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index d814172873..b4da6d65be 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -20,6 +20,7 @@ $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; $lang->mr->mrStatus = '合并状态'; +$lang->mr->confirmDelete = '确认删除该merge request吗?'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; $lang->mr->targetProject = '目标项目'; diff --git a/module/mr/model.php b/module/mr/model.php index 806214cfde..1b9cd670fd 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -74,6 +74,9 @@ class mrModel extends model $list = new stdclass; $list->id = $subMR->id; + $list->projectID = $subMR->project_id; + $list->gitlabID = $mr->gitlabID; + $list->mrID = $subMR->iid; $list->name = $subMR->title; $list->target_branch = $subMR->target_branch; $list->source_branch = $subMR->source_branch; @@ -87,6 +90,26 @@ class mrModel extends model } } + /** + * Delete MR. + * + * condition: when user deleting a repo. + * + * @param int $gitlabID + * @param int $projectID + * @param int $mrID + * @access public + * @return void + */ + public function deleteMR($gitlabID, $projectID, $mrID ) + { + $this->dao->delete()->from(TABLE_MR) + ->where('gitlabID')->eq($gitlabID) + ->andWhere('projectID')->eq($projectID) + ->andWhere('mrID')->eq($mrID) + ->exec(); + } + /** * Get gitlab pairs. * diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 3b3c60e385..2580ba3acf 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -43,7 +43,7 @@ common::printLink('mr', 'list', "mr={$mr->id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "productID=$mr->projectID&gitlabID=$mr->gitlabID&mrID=$mr->mrID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> From e215bc47f3eaeea83b4498ad95ef42ae3132294b Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 19 Aug 2021 13:27:17 +0800 Subject: [PATCH 028/154] * Review codes. --- module/mr/control.php | 81 ++++++------------ module/mr/js/create.js | 2 - module/mr/lang/zh-cn.php | 28 +++--- module/mr/model.php | 178 +++++++++++++++++---------------------- 4 files changed, 114 insertions(+), 175 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 5b856ef19b..cf57c98c72 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -14,56 +14,30 @@ class mr extends control */ public function browse($objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - $this->loadModel('mr'); - - $mrList = $this->mr->getList(0, $orderBy); - - /* Pager. */ $this->app->loadClass('pager', $static = true); - $recTotal = count($mrList); - $pager = new pager($recTotal, $recPerPage, $pageID); - $mrList = array_chunk($mrList, $pager->recPerPage); - - $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; + $pager = new pager($recTotal, $recPerPage, $pageID); + $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; + $this->view->MRList = $this->mr->getList(0, $orderBy, $pager); $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->pager = $pager; - $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; - $this->display(); - } - - public function list($mrID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) - { - $this->loadModel('gitlab'); - $gitlab = $this->mr->getGitlabProjectByRepo($mrID); - $mrList = $this->mr->apiGetMRList($gitlab->gitlabID, $gitlab->projectID); - - $this->app->loadClass('pager', $static = true); - $recTotal = count($mrList); - $pager = new pager($recTotal, $recPerPage, $pageID); - $mrList = array_chunk($mrList, $pager->recPerPage); - - $this->view->title = $this->lang->mr->browse; - $this->view->orderBy = $orderBy; - $this->view->pager = $pager; - $this->view->mrList = empty($mrList) ? $mrList: $mrList[$pageID - 1];; - $this->display(); } + /** + * Create MR function. + * + * @access public + * @return void + */ public function create() { - $this->loadModel('mr'); if($_POST) { - $mrID = $this->mr->create(); - + $this->mr->create(); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - - if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $mrID)); - $link = helper::createLink('mr', 'browse', '', '', false); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } $this->view->title = $this->lang->mr->create; @@ -73,28 +47,29 @@ class mr extends control } /** - * Delete a mr. + * update * - * @param int $gitlabID - * @param int $projectID - * @param int $mrID * @access public * @return void */ - public function delete($gitlabID, $projectID, $mrID, $confim = 'no') - { - if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "productID=$projectID&gitlabID=$gitlabID&mrID=$mrID&confirm=yes"))); - - $this->mr->apiDeleteMR($gitlabID, $projectID, $mrID); - - $this->gitlab->delete(TABLE_PIPELINE, $id); - die(js::reload('parent')); - } - public function update() { } + /** + * Delete a mr. + * + * @param int $MR + * @access public + * @return void + */ + public function delete($MR, $confim = 'no') + { + if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "productID=$projectID&gitlabID=$gitlabID&MR=$MR&confirm=yes"))); + $this->mr->apiDeleteMR($MR); + die(js::reload('parent')); + } + /** * AJAX: Get forked projects. * @@ -109,6 +84,7 @@ class mr extends control if(!$projects) return $this->send(array('message' => array())); $projectIdList = $projectIdList ? explode(',', $projectIdList) : null; + $options = ""; foreach($projects as $project) { @@ -116,7 +92,6 @@ class mr extends control $options .= ""; } - return $this->send($options); + $this->send($options); } } - diff --git a/module/mr/js/create.js b/module/mr/js/create.js index 3ab3aa2b2f..a1492677f9 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -27,6 +27,4 @@ $(function() $('#targetProject').chosen().trigger("chosen:updated");; }); - }); - diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index b4da6d65be..326919596f 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -5,28 +5,20 @@ $lang->mr->browse = "浏览{$lang->mr->common}"; $lang->mr->list = $lang->mr->browse; $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; -$lang->mr->detail = "详情"; +$lang->mr->view = "详情"; -$lang->mr->addGitlab = "添加GitLab项目"; - -$lang->mr->id = 'ID'; -$lang->mr->iid = "{$lang->mr->common}ID"; -$lang->mr->name = '名称'; -$lang->mr->title = $lang->mr->name; -$lang->mr->status = '状态'; -$lang->mr->author = '创建人'; -$lang->mr->assignee = '指派给'; -$lang->mr->reviewer = '评审人'; -$lang->mr->link = 'GitLab链接'; -$lang->mr->mrStatus = '合并状态'; +$lang->mr->id = 'ID'; +$lang->mr->iid = "MR原始ID"; +$lang->mr->name = '名称'; +$lang->mr->status = '状态'; +$lang->mr->author = '创建人'; +$lang->mr->assignee = '指派给'; +$lang->mr->reviewer = '评审人'; +$lang->mr->link = 'GitLab链接'; +$lang->mr->canMerge = '是否可合并'; $lang->mr->confirmDelete = '确认删除该merge request吗?'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; $lang->mr->targetProject = '目标项目'; $lang->mr->targetBranch = '目标分支'; - -$lang->mr->compareBranch = '比较分支'; -$lang->mr->and = '并'; -$lang->mr->continue = '继续'; -$lang->mr->cmpAndContinue = $lang->mr->compareBranch . $lang->mr->and . $lang->mr->continue; diff --git a/module/mr/model.php b/module/mr/model.php index 1b9cd670fd..91c2ccb20c 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -23,18 +23,6 @@ class mrModel extends model $this->loadModel('gitlab'); } - public function getGitlabProjectByRepo($repoID) - { - $repo = $this->loadModel('repo')->getRepoByID($repoID); - - $gitlab = new stdclass; - $gitlab->product = explode(',', $repo->product); - $gitlab->gitlabID = $repo->gitlab; - $gitlab->projectID = $repo->project; - - return $gitlab; - } - /** * Get a MR by id. * @@ -50,63 +38,58 @@ class mrModel extends model /** * Get MR list of gitlab project. * - * @param int $orderBy - * @param object $pager + * @param string $orderBy + * @param object $pager * @access public * @return array */ public function getList($orderBy = 'id_desc', $pager = null) { - $mrList = $this->dao->select('*') - ->from(TABLE_MR) - ->where('deleted')->eq('0') - ->orderBy($orderBy) - ->page($pager) - ->fetchAll('id'); + $MRList = $this->dao->select('*') + ->from(TABLE_MR) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); - if(!empty($mrList)) - { - $lists = array(); - foreach($mrList as $mr) - { - foreach($this->apiGetMRList($mr->gitlabID, $mr->projectID) as $subMR) - { - $list = new stdclass; + foreach($MRList as $MR) $MR = $this->processMR($MR); - $list->id = $subMR->id; - $list->projectID = $subMR->project_id; - $list->gitlabID = $mr->gitlabID; - $list->mrID = $subMR->iid; - $list->name = $subMR->title; - $list->target_branch = $subMR->target_branch; - $list->source_branch = $subMR->source_branch; - $list->status = $subMR->state; - $list->mrStatus = $subMR->merge_status; - - $lists[] = $list; - } - } - return $lists; - } + return $MRList; } /** - * Delete MR. + * ProcessMR info by api. + * + * @param object $MR + * @access public + * @return object + */ + public function processMR($MR) + { + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->id); + + $MR->name = $rawMR->title; + $MR->targetBranch = $rawMR->target_branch; + $MR->sourceBranch = $rawMR->source_branch; + $MR->targetProject = $rawMR->target_project_id; + $MR->canMerge = $rawMR->merge_status; + $MR->status = $rawMR->state; + return $MR; + } + + /** + * Delete one MR. * * condition: when user deleting a repo. * - * @param int $gitlabID - * @param int $projectID - * @param int $mrID + * @param int $MRID * @access public * @return void */ - public function deleteMR($gitlabID, $projectID, $mrID ) + public function deleteMR($MRID) { $this->dao->delete()->from(TABLE_MR) - ->where('gitlabID')->eq($gitlabID) - ->andWhere('projectID')->eq($projectID) - ->andWhere('mrID')->eq($mrID) + ->andWhere('mrID')->eq($MRID) ->exec(); } @@ -118,14 +101,20 @@ class mrModel extends model */ public function getPairs($repoID) { - $mr = $this->dao->select('id,title') - ->from(TABLE_MR) - ->where('deleted')->eq('0') - ->AndWhere('repoID')->eq($repoID) - ->orderBy('id')->fetchPairs('id', 'title'); - return array('' => '') + $mr; + $MR = $this->dao->select('id,title') + ->from(TABLE_MR) + ->where('deleted')->eq('0') + ->AndWhere('repoID')->eq($repoID) + ->orderBy('id')->fetchPairs('id', 'title'); + return array('' => '') + $MR; } + /** + * Create MR function. + * + * @access public + * @return bool + */ public function create() { $gitlabID = $this->post->gitlabID; @@ -137,62 +126,48 @@ class mrModel extends model $targetBranch = $this->post->targetBranch; if($projectID != $sourceProject) return false; - - } - - /** - * Get gitlab api base url by gitlab ID. - * - * @param int $gitlabID - * @access public - * @return string - */ - public function getApiRoot($gitlabID) - { - return $this->gitlab->getApiRoot($gitlabID); } /** * Get Forks of a project. * + * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project * @param int $gitlabID * @param int $projectID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project */ public function apiGetForks($gitlabID, $projectID) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/forks"); - $mr = new stdclass; return json_decode(commonModel::http($url)); } /** * Create MR by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#create-mr * @param int $gitlabID * @param int $projectID * @param object $params * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#create-mr */ public function apiCreateMR($gitlabID, $projectID, $params) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); - $mr = new stdclass; - return json_decode(commonModel::http($url, $mr)); + $MR = new stdclass; + return json_decode(commonModel::http($url, $MR)); } /** * Get MR list by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests * @param int $gitlabID * @param int $projectID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests */ public function apiGetMRList($gitlabID, $projectID) { @@ -203,99 +178,98 @@ class mrModel extends model /** * Get single MR by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr */ - public function apiGetSingleMR($gitlabID, $projectID, $mrID) + public function apiGetSingleMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url)); } /** * Update MR by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#update-mr * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @param object $params * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#update-mr */ - public function apiUpdateMR($gitlabID, $projectID, $mrID, $params) + public function apiUpdateMR($gitlabID, $projectID, $MRID, $params) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); - $mr = new stdclass; - return json_decode(commonModel::http($url, $mr, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + return json_decode(commonModel::http($url, $MR, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** * Delete MR by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request */ - public function apiDeleteMR($gitlabID, $projectID, $mrID) + public function apiDeleteMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } /** * Accept MR by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr */ - public function apiAcceptMR($gitlabID, $projectID, $mrID) + public function apiAcceptMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** * Get MR diff versions by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-mr-diff-versions * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-mr-diff-versions */ - public function apiGetDiffVersions($gitlabID, $projectID, $mrID) + public function apiGetDiffVersions($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url)); } /** * Get single diff version by API. * + * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-mr-diff-version * @param int $gitlabID * @param int $projectID - * @param int $mrID + * @param int $MRID * @param int $versionID * @access public * @return object - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-mr-diff-version */ - public function apiGetSingleDiffVersion($gitlabID, $projectID, $mrID, $versionID) + public function apiGetSingleDiffVersion($gitlabID, $projectID, $MRID, $versionID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$mrID/versions/$versionID"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/versions/$versionID"); return json_decode(commonModel::http($url)); } } From 080f26ae86e85114e984d8deed23e48bfc2aff13 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 14:01:07 +0800 Subject: [PATCH 029/154] * Change getApiRoot to from gitlab module. --- module/mr/model.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 91c2ccb20c..0d9320ebf6 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -139,7 +139,7 @@ class mrModel extends model */ public function apiGetForks($gitlabID, $projectID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/forks"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/forks"); return json_decode(commonModel::http($url)); } @@ -155,7 +155,7 @@ class mrModel extends model */ public function apiCreateMR($gitlabID, $projectID, $params) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); $MR = new stdclass; return json_decode(commonModel::http($url, $MR)); } @@ -171,7 +171,7 @@ class mrModel extends model */ public function apiGetMRList($gitlabID, $projectID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); return json_decode(commonModel::http($url)); } @@ -187,7 +187,7 @@ class mrModel extends model */ public function apiGetSingleMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url)); } @@ -204,7 +204,7 @@ class mrModel extends model */ public function apiUpdateMR($gitlabID, $projectID, $MRID, $params) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, $MR, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } @@ -220,7 +220,7 @@ class mrModel extends model */ public function apiDeleteMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } @@ -236,7 +236,7 @@ class mrModel extends model */ public function apiAcceptMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } @@ -252,7 +252,7 @@ class mrModel extends model */ public function apiGetDiffVersions($gitlabID, $projectID, $MRID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url)); } @@ -269,7 +269,7 @@ class mrModel extends model */ public function apiGetSingleDiffVersion($gitlabID, $projectID, $MRID, $versionID) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/versions/$versionID"); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/versions/$versionID"); return json_decode(commonModel::http($url)); } } From 1b14499cae461d4e4eec9947ff92862089c37555 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 15:08:52 +0800 Subject: [PATCH 030/154] * Revert checkToken function. --- module/gitlab/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index d5d3e7ceef..50a2c8f94f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -193,7 +193,7 @@ class gitlab extends control $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); if(!is_object($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); - if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->hostError, 'locate' => 'parent')); + if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); } /** From 9b20bfdf192efe55e0d4a90e9b8e37bbe999d3a3 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 19 Aug 2021 08:20:09 +0000 Subject: [PATCH 031/154] * Adjust jihuMR zh. --- module/gitlab/lang/zh-cn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 4a37a0cbc4..f48412f833 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -40,6 +40,7 @@ $lang->gitlab->placeholder->token = "请填写具有admin权限账户的access t $lang->gitlab->noImportableIssues = "目前没有可供导入的issue。"; $lang->gitlab->tokenError = "当前token非管理员权限。"; +$lang->gitlab->tokenLimit = "GitLab Token权限不足,无法使用当前功能。请更换为有管理员权限的GitLab Token。"; $lang->gitlab->hostError = "无效的GitLab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; $lang->gitlab->importIssueError = "未选择该issue所属的执行。"; From b14f5af220d695fc53bdeab0fb0dcb4b9a10ed6f Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 19 Aug 2021 08:28:59 +0000 Subject: [PATCH 032/154] * Add GitLab Token authority verification. --- module/gitlab/control.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 50a2c8f94f..4128af9db8 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -101,6 +101,11 @@ class gitlab extends control { $userPairs = $this->loadModel('user')->getPairs(); + $gitlab = $this->gitlab->getByID($gitlabID); + $user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); + if(!isset($user->is_admin) or !$user->is_admin) die(js::alert($this->lang->gitlab->tokenLimit) . js::locate($this->createLink('gitlab', 'edit', array('gitlabID' => $gitlabID)))); + + if($_POST) { $users = $this->post->zentaoUsers; @@ -140,7 +145,6 @@ class gitlab extends control return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } - $gitlab = $this->gitlab->getByID($gitlabID); $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $this->view->title = $this->lang->gitlab->bindUser; From 5537f3500a43c43943e878a74c4bdd53726fcc0a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 19 Aug 2021 16:32:40 +0800 Subject: [PATCH 033/154] * Remove extra line. --- module/gitlab/control.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4128af9db8..2d38990e42 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -105,7 +105,6 @@ class gitlab extends control $user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); if(!isset($user->is_admin) or !$user->is_admin) die(js::alert($this->lang->gitlab->tokenLimit) . js::locate($this->createLink('gitlab', 'edit', array('gitlabID' => $gitlabID)))); - if($_POST) { $users = $this->post->zentaoUsers; From 2d16d4302daaf6674d73084c999cf955c35fa944 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:11:41 +0800 Subject: [PATCH 034/154] * Remove addGitlab. --- module/mr/view/browse.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 2580ba3acf..fd22d53608 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,7 +1,7 @@
From 66c69c04c91b456c9f6b987983c5fe750153f86b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:13:08 +0800 Subject: [PATCH 035/154] * Correct ajaxGetProjectBranches function. --- module/gitlab/control.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 50a2c8f94f..34ed846e49 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -363,7 +363,7 @@ class gitlab extends control * @param int $gitlabID * @param int $projectID * @access public - * @return object + * @return void */ public function ajaxGetProjectBranches($gitlabID, $projectID) { @@ -373,8 +373,8 @@ class gitlab extends control $options = ""; foreach($branches as $index =>$branch) { - $options .= ""; + $options .= ""; } - return $this->send($options); + $this->send($options); } } From 1dc911db569ebd68903797102ae78c2d5ea5f885 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:14:53 +0800 Subject: [PATCH 036/154] + Add apiGetUpstream,apiGetForks, getUserIdRealnamePairs. --- module/gitlab/model.php | 50 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4b91dbc2d4..3ad8662b2e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -66,7 +66,25 @@ class gitlabModel extends model } /** - * Get gitlab user id zentao account pairs of one gitlab. + * Get gitlab user id and realname pairs of one gitlab. + * + * @param int $gitlabID + * @access public + * @return void + */ + public function getUserIdRealnamePairs($gitlabID) + { + return $this->dao->select('oauth.openID as openID,user.realname as realname') + ->from(TABLE_OAUTH)->alias('oauth') + ->leftJoin(TABLE_USER)->alias('user') + ->on("oauth.account = user.account") + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->fetchPairs(); + } + + /** + * Get gitlab user id and zentao account pairs of one gitlab. * * @param int $gitlab * @access public @@ -432,6 +450,36 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + /** + * Get Forks of a project by API. + * + * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiGetForks($gitlabID, $projectID) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/forks"); + return json_decode(commonModel::http($url)); + } + + /** + * Get upstream project by API. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function apiGetUpstream($gitlabID,$projectID) + { + $currentProject = $this->apiGetSingleProject($gitlabID, $projectID); + if(isset($currentProject->forked_from_project)) return $currentProject->forked_from_project; + return array(); + } + /** * Get hooks. * From 2999fd6e49552f8bf9d246e29603e25b910ac3c0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:18:56 +0800 Subject: [PATCH 037/154] * Finish the view of creating MR(staging). --- module/mr/js/create.js | 31 ++++++++++++++++++++----------- module/mr/lang/zh-cn.php | 1 + module/mr/view/create.html.php | 22 +++++++++++++++++++--- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/module/mr/js/create.js b/module/mr/js/create.js index a1492677f9..d324201335 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -2,10 +2,10 @@ $(function() { $('#gitlabID').change(function() { - host = $('#gitlabID').val(); + host = $('#gitlabID').val(); if(host == '') return false; - url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); $.get(url, function(response) { $('#sourceProject').html('').append(response); @@ -13,18 +13,27 @@ $(function() }); }); - $('#sourceProject').change(function() + $('#sourceProject,#targetProject').change(function() { - $option = $(this).find('option:selected'); - $('#name').val($option.data('name')); - project = $('#sourceProject').val(); - url = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + host + "&projectID=" + project); - $.get(url, function(response) + sourceProject = $(this).val(); + var branchSelect = $(this).parents('td').find('select[name*=Branch]'); + branchUrl = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + host + "&projectID=" + sourceProject); + $.get(branchUrl, function(response) { - $('#sourceBranch').html('').append(response); - $('#sourceBranch').chosen().trigger("chosen:updated");; + branchSelect.html('').append(response); + branchSelect.chosen().trigger("chosen:updated");; }); - $('#targetProject').chosen().trigger("chosen:updated");; + }); + + $('#sourceProject').change(function() + { + sourceProject = $(this).val(); + projectUrl = createLink('mr', 'ajaxGetMRTragetProjects', "gitlabID=" + host + "&projectID=" + sourceProject); + $.get(projectUrl, function(response) + { + $('#targetProject').html('').append(response); + $('#targetProject').chosen().trigger("chosen:updated");; + }); }); }); diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 326919596f..130955462d 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -17,6 +17,7 @@ $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; $lang->mr->canMerge = '是否可合并'; +$lang->mr->description = '描述'; $lang->mr->confirmDelete = '确认删除该merge request吗?'; $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index d05a6824db..6acccf70ee 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -15,8 +15,8 @@
- - + @@ -38,10 +38,26 @@ + + + + + + + + + + + + + + + + From d95711841d4895003443c3e5df70d4fdd3bc7ff0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:22:42 +0800 Subject: [PATCH 038/154] * Add some functions to creating MR(staging). --- module/mr/control.php | 25 +++++++++++++++++++------ module/mr/model.php | 32 ++++++++++---------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index cf57c98c72..ff28a8efb4 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -42,7 +42,7 @@ class mr extends control $this->view->title = $this->lang->mr->create; $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); - + $this->view->users = $this->gitlab->getUserIdRealnamePairs(14); $this->display(); } @@ -71,24 +71,37 @@ class mr extends control } /** - * AJAX: Get forked projects. + * AJAX: Get MR target projects. * * @param int $gitlabID * @param int $projectID * @access public * @return void */ - public function ajaxGetForkedProjects($gitlabID, $projectID) + public function ajaxGetMRTragetProjects($gitlabID, $projectID) { - $projects = $this->mr->apiGetForks($gitlabID, $projectID); + $this->loadModel('gitlab'); + /* First step: get forks. */ + $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); + /* Second step: get project itself. */ + $projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + + /* Last step: find its upstream recursively. */ + $project = $this->gitlab->apiGetUpstream($gitlabID, $projectID); + if(!empty($project)) $projects[] = $project; + + while(!empty($project) and isset($project->id)) + { + $project = $this->gitlab->apiGetUpstream($gitlabID, $project->id); + if(empty($project)) break; + $projects[] = $project; + } if(!$projects) return $this->send(array('message' => array())); - $projectIdList = $projectIdList ? explode(',', $projectIdList) : null; $options = ""; foreach($projects as $project) { - if(!empty($projectIdList) and $project and !in_array($project->id, $projectIdList)) continue; $options .= ""; } diff --git a/module/mr/model.php b/module/mr/model.php index 0d9320ebf6..f2e1195416 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -120,27 +120,16 @@ class mrModel extends model $gitlabID = $this->post->gitlabID; $projectID = $this->post->projectID; - $sourceProject = $this->post->sourceProject; - $sourceBranch = $this->post->sourceBranch; - $targetProject = $this->post->targetProject; - $targetBranch = $this->post->targetBranch; + $MR = new stdclass; + $MR->target_project_id = $this->post->targetProject; + $MR->source_branch = $this->post->sourceBranch; + $MR->target_branch = $this->post->targetBranch; + $MR->title = $this->post->title; + $MR->description = $this->post->description; + $MR->assignee_ids = $this->post->assignee; + $MR->reviewer_ids = $this->post->reviewer; - if($projectID != $sourceProject) return false; - } - - /** - * Get Forks of a project. - * - * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project - * @param int $gitlabID - * @param int $projectID - * @access public - * @return object - */ - public function apiGetForks($gitlabID, $projectID) - { - $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/forks"); - return json_decode(commonModel::http($url)); + $rawMR = $this->apiCreateMR($gitlabID, $projectID, $MR); } /** @@ -156,8 +145,7 @@ class mrModel extends model public function apiCreateMR($gitlabID, $projectID, $params) { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); - $MR = new stdclass; - return json_decode(commonModel::http($url, $MR)); + return json_decode(commonModel::http($url, $data=$params, $options = array())); } /** From c5a67c28086941f037f0be96c97c45c7ad21f7a8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 00:45:10 +0000 Subject: [PATCH 039/154] * Adjust the gitlab permission to judge the presentation. --- module/gitlab/view/browse.html.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index c4a5663170..90fce72305 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -40,14 +40,15 @@ $gitlab): ?> + - + $gitlab): ?> - From 6bd20ecaaf0dc59f085dc8a8cc7d0392e8483c8f Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 01:28:54 +0000 Subject: [PATCH 041/154] * Adjust GitLab admin token fix bug. --- module/gitlab/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 2053da23ff..99f19d7d54 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -33,7 +33,7 @@ class gitlab extends control foreach($gitlabList as $gitlab) { $token = $this->gitlab->apiGetCurrentUser($gitlab->url,$gitlab->token); - $gitlab->isAdminToken = $token->is_admin; + $gitlab->isAdminToken = !isset($token->is_admin) ? $token->is_admin : 0; } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; From 60f9f418ea1bf0ee667e9553c981fd40a8d67052 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 01:53:14 +0000 Subject: [PATCH 042/154] * Adjust gitlab token Permissions code. --- module/gitlab/control.php | 2 +- module/gitlab/view/browse.html.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 99f19d7d54..4f9408b36a 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -33,7 +33,7 @@ class gitlab extends control foreach($gitlabList as $gitlab) { $token = $this->gitlab->apiGetCurrentUser($gitlab->url,$gitlab->token); - $gitlab->isAdminToken = !isset($token->is_admin) ? $token->is_admin : 0; + $gitlab->isAdminToken = isset($token->is_admin) ? $token->is_admin : 0; } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 582e10fabd..586860b235 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -46,10 +46,11 @@ From 90e660b38848646d3488f9161512f9cbca2bed1b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 12:11:37 +0800 Subject: [PATCH 043/154] * Get MR user pairs to select assignee_ids and reviewer_ids. --- module/gitlab/control.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4f9408b36a..ae65e37916 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -374,9 +374,29 @@ class gitlab extends control $branches = $this->gitlab->apiGetBranches($gitlabID, $projectID); $options = ""; - foreach($branches as $index =>$branch) + foreach($branches as $branch) { - $options .= ""; + $options .= ""; + } + $this->send($options); + } + + /** + * AJAX: Get MR user pairs to select assignee_ids and reviewer_ids. + * + * @param int $gitlabID + * @access public + * @return void + */ + public function ajaxGetMRUserPairs($gitlabID) + { + if(!$gitlabID) return $this->send(array('message' => array())); + + $users = $this->gitlab->getUserIdRealnamePairs($gitlabID); + $options = ""; + foreach($users as $index => $user) + { + $options .= ""; } $this->send($options); } From 84b7170f9c021b2ac199dabdbf073b8682e44c3f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 12:12:56 +0800 Subject: [PATCH 044/154] * Finish the control and view for creating MR. --- module/mr/control.php | 1 - module/mr/js/create.js | 22 +++++++++++++++++----- module/mr/lang/zh-cn.php | 2 ++ module/mr/view/create.html.php | 11 +++++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index ff28a8efb4..6e74f224cc 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -42,7 +42,6 @@ class mr extends control $this->view->title = $this->lang->mr->create; $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); - $this->view->users = $this->gitlab->getUserIdRealnamePairs(14); $this->display(); } diff --git a/module/mr/js/create.js b/module/mr/js/create.js index d324201335..ae7c6decb1 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -2,22 +2,34 @@ $(function() { $('#gitlabID').change(function() { - host = $('#gitlabID').val(); - if(host == '') return false; + gitlabID = $('#gitlabID').val(); + if(gitlabID == '') return false; - url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); + url = createLink('repo', 'ajaxgetgitlabprojects', "gitlabID=" + gitlabID); $.get(url, function(response) { $('#sourceProject').html('').append(response); $('#sourceProject').chosen().trigger("chosen:updated");; }); + + var assignee = $("#assignee").parents('td').find('select[name*=assignee]'); + var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]'); + usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID); + $.get(usersUrl, function(response) + { + assignee.html('').append(response); + assignee.chosen().trigger("chosen:updated");; + reviewer.html('').append(response); + reviewer.chosen().trigger("chosen:updated");; + }); + }); $('#sourceProject,#targetProject').change(function() { sourceProject = $(this).val(); var branchSelect = $(this).parents('td').find('select[name*=Branch]'); - branchUrl = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + host + "&projectID=" + sourceProject); + branchUrl = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + gitlabID + "&projectID=" + sourceProject); $.get(branchUrl, function(response) { branchSelect.html('').append(response); @@ -29,7 +41,7 @@ $(function() $('#sourceProject').change(function() { sourceProject = $(this).val(); - projectUrl = createLink('mr', 'ajaxGetMRTragetProjects', "gitlabID=" + host + "&projectID=" + sourceProject); + projectUrl = createLink('mr', 'ajaxGetMRTragetProjects', "gitlabID=" + gitlabID + "&projectID=" + sourceProject); $.get(projectUrl, function(response) { $('#targetProject').html('').append(response); diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 130955462d..8708c0be55 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -23,3 +23,5 @@ $lang->mr->sourceProject = '源项目'; $lang->mr->sourceBranch = '源分支'; $lang->mr->targetProject = '目标项目'; $lang->mr->targetBranch = '目标分支'; + +$lang->mr->usersTips = '提示:如果无法选择指派人和评审人,请先前往GitLab页面绑定用户。'; diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 6acccf70ee..2ffc1dd4a4 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -12,6 +12,9 @@
+
+

mr->create;?>

+
repo->gitlabHost;?>repo->placeholder->gitlabHost}'");?> + gitlab->common;?>
mr->sourceProject;?>
mr->name;?>
mr->description; ?>
mr->assignee;?>
mr->reviewer;?>
- mr->cmpAndContinue); ?> + goback, '', 'class="btn btn-wide"');?>
name;?>url;?>url;?> isAdminToken) ? '' : 'disabled'; - common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary {$disabled}'"); + common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary {$disabled}', 'disabled'"); common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$lang->gitlab->bindUser} class='btn btn-primary {$disabled}'"); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn {$disabled}'"); ?> From 26a3ee3782e30a2a25b692380816f7cae0c78b62 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 01:01:53 +0000 Subject: [PATCH 040/154] *Adjust GitLab code. --- module/gitlab/view/browse.html.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 90fce72305..582e10fabd 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -40,7 +40,6 @@
name;?>url;?> isAdminToken) ? '' : 'disabled'; - common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary {$disabled}', 'disabled'"); - common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$lang->gitlab->bindUser} class='btn btn-primary {$disabled}'"); - if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn {$disabled}'"); + $disabled = !empty($gitlab->isAdminToken) ? '' : 'disabled'; + $bindUserLang = !empty($gitlab->isAdminToken) ? $lang->gitlab->bindUser : $lang->gitlab->tokenError; + common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary'"); + common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$bindUserLang} class='btn btn-primary {$disabled}' ,'disabled'"); + if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); ?>
@@ -48,11 +51,15 @@ - + - + + + + + From 08f9e8e572a8354b43a52e388c047264b551455e Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 06:27:58 +0000 Subject: [PATCH 045/154] * Adjust GitLab MR Delete function. --- module/gitlab/control.php | 1 + module/gitlab/view/browse.html.php | 2 +- module/mr/control.php | 10 +++++++--- module/mr/model.php | 6 +++--- module/mr/view/browse.html.php | 14 +++++++------- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4f9408b36a..deb6400639 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -33,6 +33,7 @@ class gitlab extends control foreach($gitlabList as $gitlab) { $token = $this->gitlab->apiGetCurrentUser($gitlab->url,$gitlab->token); + $gitlab->isAdminToken = isset($token->is_admin) ? $token->is_admin : 0; } diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 586860b235..b905dfd9c1 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -16,7 +16,7 @@ " . $lang->gitlab->create, '', "class='btn btn-primary'");?> - +

noData;?> diff --git a/module/mr/control.php b/module/mr/control.php index ff28a8efb4..9b50a2e0b9 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -63,10 +63,14 @@ class mr extends control * @access public * @return void */ - public function delete($MR, $confim = 'no') + public function delete($id, $confim = 'no') { - if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "productID=$projectID&gitlabID=$gitlabID&MR=$MR&confirm=yes"))); - $this->mr->apiDeleteMR($MR); + if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); + + $MRList = $this->mr->getByID($id); + + $this->mr->apiDeleteMR($MRList->gitlabID, $MRList->projectID, $MRList->mrID); + $this->mr->deleteMR($id); die(js::reload('parent')); } diff --git a/module/mr/model.php b/module/mr/model.php index f2e1195416..b23869ed30 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -82,14 +82,14 @@ class mrModel extends model * * condition: when user deleting a repo. * - * @param int $MRID + * @param int $id * @access public * @return void */ - public function deleteMR($MRID) + public function deleteMR($id) { $this->dao->delete()->from(TABLE_MR) - ->andWhere('mrID')->eq($MRID) + ->andWhere('id')->eq($id) ->exec(); } diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index fd22d53608..01c02e9546 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -25,32 +25,32 @@

- + - + - - + + - +
mr->assignee;?>
mr->reviewer;?>
mr->usersTips;?>
mr->sourceBranch); ?> mr->targetBranch); ?> mr->status); ?>mr->mrStatus); ?>mr->canMerge); ?> actions; ?>
id; ?> name; ?>target_branch; ?>source_branch; ?>targetBranch; ?>sourceBranch; ?> status; ?>mrStatus; ?>canMerge; ?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "productID=$mr->projectID&gitlabID=$mr->gitlabID&mrID=$mr->mrID"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?>
- +
From 2056fc52ff2e6aeade6443c0761d0e76c9e4a560 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 15:13:30 +0800 Subject: [PATCH 046/154] + Add getBranches functions. --- module/gitlab/model.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 3ad8662b2e..0320cd7472 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -306,6 +306,26 @@ class gitlabModel extends model return $refList; } + /** + * Get branches. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return array + */ + public function getBranches($gitlabID, $projectID) + { + $rawBranches = $this->apiGetBranches($gitlabID, $projectID); + + $branches = array(); + foreach($rawBranches as $branch) + { + $branches[] = $branch->name; + } + return $branches; + } + /** * Create a gitlab. * From 08aff43f08c95e3f31d66fd2cdfba3803be00d7f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 15:16:18 +0800 Subject: [PATCH 047/154] * Finish creating MR in model. --- module/mr/config.php | 5 +++++ module/mr/control.php | 18 ++++++++++++++--- module/mr/model.php | 45 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 module/mr/config.php diff --git a/module/mr/config.php b/module/mr/config.php new file mode 100644 index 0000000000..da874423db --- /dev/null +++ b/module/mr/config.php @@ -0,0 +1,5 @@ +MR = new stdclass(); +$config->MR->create = new stdclass(); +$config->MR->create->requiredFields = 'gitlabID,projectID,mrID,title'; +$config->MR->create->skippedFields = 'sourceProject,sourceBranch,targetProject,targetBranch'; diff --git a/module/mr/control.php b/module/mr/control.php index 6e74f224cc..8134df0fdf 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -35,7 +35,9 @@ class mr extends control { if($_POST) { - $this->mr->create(); + $rawMR = $this->mr->create(); + if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => $rawMR->message)); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -46,13 +48,23 @@ class mr extends control } /** - * update + * Update/Edit MR function. * * @access public * @return void */ - public function update() + public function update($MRID) { + if($_POST) + { + $this->mr->update(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + } + + $this->view->MR = $this->mr->getByID($MRID); + $this->view->title = $this->lang->mr->update; + $this->display(); } /** diff --git a/module/mr/model.php b/module/mr/model.php index f2e1195416..30b5f20c55 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -32,7 +32,8 @@ class mrModel extends model */ public function getByID($id) { - return $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); + $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); + return $this->processMR($MR); } /** @@ -58,7 +59,7 @@ class mrModel extends model } /** - * ProcessMR info by api. + * Process MR info by api. * * @param object $MR * @access public @@ -66,7 +67,7 @@ class mrModel extends model */ public function processMR($MR) { - $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->id); + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); $MR->name = $rawMR->title; $MR->targetBranch = $rawMR->target_branch; @@ -118,7 +119,7 @@ class mrModel extends model public function create() { $gitlabID = $this->post->gitlabID; - $projectID = $this->post->projectID; + $projectID = $this->post->sourceProject; $MR = new stdclass; $MR->target_project_id = $this->post->targetProject; @@ -130,6 +131,42 @@ class mrModel extends model $MR->reviewer_ids = $this->post->reviewer; $rawMR = $this->apiCreateMR($gitlabID, $projectID, $MR); + + /* Another open merge request already exists for this source branch. */ + if(isset($rawMR->message) and !isset($rawMR->iid)) return $rawMR; + + /* Create MR failed. */ + if(!isset($rawMR->iid)) return false; + + $MR = fixer::input('post') + ->add('repoID', 0) + ->add('gitlabID', $gitlabID) + ->add('projectID', $projectID) + ->add('mrID', $rawMR->iid) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->get(); + + /* Remove extra fields before inserting db table. */ + foreach(explode(',', $this->config->MR->create->skippedFields) as $field) unset($MR->$field); + + $this->dao->insert(TABLE_MR)->data($MR) + ->batchCheck($this->config->MR->create->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + if(dao::isError()) return false; + + return $this->dao->lastInsertId(); + } + + /** + * Update MR function. + * + * @access public + * @return void + */ + public function update() + { } /** From 7e4610ce9b73a8626850c279420be4f552bdee87 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 20 Aug 2021 07:17:40 +0000 Subject: [PATCH 048/154] * Adjust gitlab code. --- module/gitlab/control.php | 1 - module/gitlab/view/browse.html.php | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4d770b5230..ae65e37916 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -33,7 +33,6 @@ class gitlab extends control foreach($gitlabList as $gitlab) { $token = $this->gitlab->apiGetCurrentUser($gitlab->url,$gitlab->token); - $gitlab->isAdminToken = isset($token->is_admin) ? $token->is_admin : 0; } diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index b905dfd9c1..c8469121b2 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -16,7 +16,7 @@ " . $lang->gitlab->create, '', "class='btn btn-primary'");?>
- +

noData;?> @@ -43,13 +43,12 @@ name;?> - url;?> - + url;?> + isAdminToken) ? '' : 'disabled'; - $bindUserLang = !empty($gitlab->isAdminToken) ? $lang->gitlab->bindUser : $lang->gitlab->tokenError; + $disabled = !empty($gitlab->isAdminToken) ? '' : 'disabled'; common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary'"); - common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$bindUserLang} class='btn btn-primary {$disabled}' ,'disabled'"); + common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$lang->gitlab->bindUser} class='btn btn-primary {$disabled}' ,'disabled'"); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); ?> From 0a8c4b40f10de81390a87f2a7adc7264290fdcfe Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 15:37:15 +0800 Subject: [PATCH 049/154] * Change plural to singulative. --- db/zentao.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/zentao.sql b/db/zentao.sql index 98f0e527f2..4ccd0bf73f 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -553,8 +553,8 @@ CREATE TABLE `zt_mr` ( `mrID` mediumint(8) unsigned NOT NULL, `title` varchar(255) NOT NULL, `description` text NOT NULL, - `assignees` varchar(255) NOT NULL, - `reviewers` varchar(255) NOT NULL, + `assignee` varchar(255) NOT NULL, + `reviewer` varchar(255) NOT NULL, `createdBy` varchar(30) NOT NULL, `createdDate` datetime NOT NULL, `editedBy` varchar(30) NOT NULL, From e7089866bcdf154692d25e1bc71da1b15de26258 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 16:29:54 +0800 Subject: [PATCH 050/154] * Update processMR function and bug fix. --- module/mr/model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 3cbdc65a21..6e3635fed7 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -70,9 +70,10 @@ class mrModel extends model $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); $MR->name = $rawMR->title; - $MR->targetBranch = $rawMR->target_branch; + $MR->sourceProject = $rawMR->source_project_id; $MR->sourceBranch = $rawMR->source_branch; $MR->targetProject = $rawMR->target_project_id; + $MR->targetBranch = $rawMR->target_branch; $MR->canMerge = $rawMR->merge_status; $MR->status = $rawMR->state; return $MR; @@ -141,7 +142,7 @@ class mrModel extends model $MR = fixer::input('post') ->add('repoID', 0) ->add('gitlabID', $gitlabID) - ->add('projectID', $projectID) + ->add('projectID', $rawMR->project_id) /* sourceProject can be not project of the created MR. */ ->add('mrID', $rawMR->iid) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) From 11356d714a23fb4fdbc1af27ea519096cf76331f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 20 Aug 2021 16:31:37 +0800 Subject: [PATCH 051/154] * Make browse MR work. --- module/mr/control.php | 2 +- module/mr/view/browse.html.php | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 7eb9bb791d..aee1de5c78 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -18,7 +18,7 @@ class mr extends control $pager = new pager($recTotal, $recPerPage, $pageID); $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; - $this->view->MRList = $this->mr->getList(0, $orderBy, $pager); + $this->view->MRList = $this->mr->getList($orderBy, $pager); $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->pager = $pager; diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 01c02e9546..d1491e98fb 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -5,7 +5,7 @@

- +

noData . $lang->mr->common;?> @@ -21,8 +21,10 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> mr->id); ?> - mr->name); ?> + mr->name); ?> + mr->sourceProject); ?> mr->sourceBranch); ?> + mr->targetProject); ?> mr->targetBranch); ?> mr->status); ?> mr->canMerge); ?> @@ -34,15 +36,16 @@ id; ?> name; ?> - targetBranch; ?> + loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->sourceProject)->name_with_namespace; ?> sourceBranch; ?> + loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->targetProject)->name_with_namespace; ?> + targetBranch; ?> status; ?> canMerge; ?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); - common::printLink('mr', 'edit', "mrID=$mr->id&objectID=$objectID", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + common::printLink('mr', 'update', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> From 30f4e190965cb58a658a6307776e603bf71000ee Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Sun, 22 Aug 2021 16:53:33 +0800 Subject: [PATCH 052/154] * Add disable attribute on disabled link. --- module/repo/control.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index 4d61974532..3b6e311637 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -87,9 +87,9 @@ class repo extends control /* Pager. */ $this->app->loadClass('pager', $static = true); - $recTotal = count($repoList); - $pager = new pager($recTotal, $recPerPage, $pageID); - $repoList = array_chunk($repoList, $pager->recPerPage); + $recTotal = count($repoList); + $pager = new pager($recTotal, $recPerPage, $pageID); + $repoList = array_chunk($repoList, $pager->recPerPage); $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->browse; $this->view->position[] = $this->lang->repo->common; From 852120191b688b3c3b9db7932d81961dca6c4b4c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 09:20:58 +0800 Subject: [PATCH 053/154] * Edit/Update a MR. --- module/mr/config.php | 3 ++ module/mr/control.php | 4 +- module/mr/model.php | 42 +++++++++++++++---- module/mr/view/update.html.php | 76 ++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 module/mr/view/update.html.php diff --git a/module/mr/config.php b/module/mr/config.php index da874423db..9a4b3d1253 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -3,3 +3,6 @@ $config->MR = new stdclass(); $config->MR->create = new stdclass(); $config->MR->create->requiredFields = 'gitlabID,projectID,mrID,title'; $config->MR->create->skippedFields = 'sourceProject,sourceBranch,targetProject,targetBranch'; + +$config->MR->update = new stdclass(); +$config->MR->update->requiredFields = 'title'; diff --git a/module/mr/control.php b/module/mr/control.php index aee1de5c78..8e9c38a734 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -57,13 +57,13 @@ class mr extends control { if($_POST) { - $this->mr->update(); + $this->mr->update($MRID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } $this->view->MR = $this->mr->getByID($MRID); - $this->view->title = $this->lang->mr->update; + $this->view->title = $this->lang->mr->edit; $this->display(); } diff --git a/module/mr/model.php b/module/mr/model.php index 6e3635fed7..1eb7282aca 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -27,13 +27,16 @@ class mrModel extends model * Get a MR by id. * * @param int $id + * @param bool $process * @access public * @return object */ - public function getByID($id) + public function getByID($id, $process = true) { $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); - return $this->processMR($MR); + + if($process) return $this->processMR($MR); + return $MR; } /** @@ -59,7 +62,7 @@ class mrModel extends model } /** - * Process MR info by api. + * Process MR info by api. Append extra attributes in GitLab. * * @param object $MR * @access public @@ -115,7 +118,7 @@ class mrModel extends model * Create MR function. * * @access public - * @return bool + * @return int|bool|object */ public function create() { @@ -166,9 +169,32 @@ class mrModel extends model * @access public * @return void */ - public function update() + public function update($MRID) { - } + /* Get MR in zentao database and do not append extra attributes in GitLab. */ + $MR = $this->getByID($MRID, $process = false); + $MR->title = $this->post->title; + $MR->description = $this->post->description; + $MR->assignee = $this->post->assignee; + $MR->reviewer = $this->post->reviewer; + + /* Update MR in GitLab. */ + $newMR = new stdclass; + $newMR->title = $MR->title; + $newMR->description = $MR->description; + $newMR->assignee = $MR->assignee; + $newMR->reviewer = $MR->reviewer; + $newMR->targetBranch = $this->post->targetBranch; + $this->apiUpdateMR($MR->gitlabID, $MR->projectID, $MR->mrID, $newMR); + + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($MR) + ->batchCheck($this->config->MR->update->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + if(dao::isError()) return false; + + } /** * Create MR by API. @@ -224,11 +250,11 @@ class mrModel extends model * @param int $gitlabID * @param int $projectID * @param int $MRID - * @param object $params + * @param object $MR * @access public * @return object */ - public function apiUpdateMR($gitlabID, $projectID, $MRID, $params) + public function apiUpdateMR($gitlabID, $projectID, $MRID, $MR) { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); return json_decode(commonModel::http($url, $MR, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); diff --git a/module/mr/view/update.html.php b/module/mr/view/update.html.php new file mode 100644 index 0000000000..ce3fb48440 --- /dev/null +++ b/module/mr/view/update.html.php @@ -0,0 +1,76 @@ + + +

+
+
+
+

mr->edit;?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->common;?>loadModel('gitlab')->getByID($MR->gitlabID)->name;?>
mr->sourceProject;?> +
+ loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject)->name_with_namespace; ?> + mr->sourceBranch ?> + sourceBranch;?> +
+
mr->targetProject;?> +
+ loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject)->name_with_namespace;?> + mr->targetBranch ?> + loadModel('gitlab')->getBranches($MR->gitlabID, $MR->targetProject), '', "class='form-control chosen'");?> +
+
mr->name;?>name, "class='form-control'"); ?>
mr->description; ?>description, "rows='3' class='form-control'"); ?>
mr->assignee;?>assignee, "class='form-control chosen'")?>
mr->reviewer;?>reviewer, "class='form-control chosen'")?>
mr->usersTips;?>
+ + goback, '', 'class="btn btn-wide"');?> +
+
+
+
+
+ From 2c0afdeedcb301a0a77e2edbb8d78b7638308122 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 10:40:34 +0800 Subject: [PATCH 054/154] * Correct bad syntax. --- module/job/view/edit.html.php | 2 +- module/mr/view/{update.html.php => edit.html.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename module/mr/view/{update.html.php => edit.html.php} (100%) diff --git a/module/job/view/edit.html.php b/module/job/view/edit.html.php index 82f235fe65..3d0894484b 100644 --- a/module/job/view/edit.html.php +++ b/module/job/view/edit.html.php @@ -12,7 +12,7 @@ ?> - + triggerType);?> pipeline);?> job->dirChange);?> diff --git a/module/mr/view/update.html.php b/module/mr/view/edit.html.php similarity index 100% rename from module/mr/view/update.html.php rename to module/mr/view/edit.html.php From 807ad4b4e855278f7499bdff88fff2e7c01cc9e7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 10:41:37 +0800 Subject: [PATCH 055/154] * Bug fix for editing a MR. --- module/mr/config.php | 4 ++-- module/mr/control.php | 11 +++++++---- module/mr/model.php | 7 +++---- module/mr/view/browse.html.php | 2 +- module/mr/view/edit.html.php | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index 9a4b3d1253..b0535585c1 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -4,5 +4,5 @@ $config->MR->create = new stdclass(); $config->MR->create->requiredFields = 'gitlabID,projectID,mrID,title'; $config->MR->create->skippedFields = 'sourceProject,sourceBranch,targetProject,targetBranch'; -$config->MR->update = new stdclass(); -$config->MR->update->requiredFields = 'title'; +$config->MR->edit = new stdclass(); +$config->MR->edit->requiredFields = 'title'; diff --git a/module/mr/control.php b/module/mr/control.php index 8e9c38a734..305d671217 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -48,22 +48,25 @@ class mr extends control } /** - * Update/Edit MR function. + * Edit MR function. * * @access public * @return void */ - public function update($MRID) + public function edit($MRID) { if($_POST) { - $this->mr->update($MRID); + $this->mr->edit($MRID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } - $this->view->MR = $this->mr->getByID($MRID); + $MR = $this->mr->getByID($MRID); + $this->view->MR = $MR; $this->view->title = $this->lang->mr->edit; + $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); /* Get user list for assignee and reviewer. */ + $this->display(); } diff --git a/module/mr/model.php b/module/mr/model.php index 1eb7282aca..be700b5779 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -164,12 +164,12 @@ class mrModel extends model } /** - * Update MR function. + * Edit MR function. * * @access public * @return void */ - public function update($MRID) + public function edit($MRID) { /* Get MR in zentao database and do not append extra attributes in GitLab. */ $MR = $this->getByID($MRID, $process = false); @@ -189,11 +189,10 @@ class mrModel extends model /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) - ->batchCheck($this->config->MR->update->requiredFields, 'notempty') + ->batchCheck($this->config->MR->edit->requiredFields, 'notempty') ->autoCheck() ->exec(); if(dao::isError()) return false; - } /** diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index d1491e98fb..b924bc50a9 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -45,7 +45,7 @@ id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'update', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index ce3fb48440..63a18d337a 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -51,11 +51,11 @@ mr->assignee;?> - assignee, "class='form-control chosen'")?> + assignee, "class='form-control chosen'")?> mr->reviewer;?> - reviewer, "class='form-control chosen'")?> + reviewer, "class='form-control chosen'")?> From f0ed277adbb3e757c1682d9f0e18c6648f4e3c0a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 14:15:55 +0800 Subject: [PATCH 056/154] * Fix browe mr page. --- module/mr/lang/zh-cn.php | 11 +++++++++++ module/mr/view/browse.html.php | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 8708c0be55..5258ef68b9 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -6,6 +6,8 @@ $lang->mr->list = $lang->mr->browse; $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; $lang->mr->view = "详情"; +$lang->mr->source = '源项目分支'; +$lang->mr->target = '目标项目分支'; $lang->mr->id = 'ID'; $lang->mr->iid = "MR原始ID"; @@ -17,6 +19,15 @@ $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; $lang->mr->canMerge = '是否可合并'; +$lang->mr->statusList = array(); +$lang->mr->statusList['opened'] = '开放中'; +$lang->mr->statusList['closed'] = '已关闭'; +$lang->mr->statusList['merged'] = '已合并'; + +$lang->mr->canMergeStatusList = array(); +$lang->mr->canMergeStatusList['can_be_merged'] = '可合并'; +$lang->mr->canMergeStatusList['cannot_be_merged'] = '不可合并'; + $lang->mr->description = '描述'; $lang->mr->confirmDelete = '确认删除该merge request吗?'; $lang->mr->sourceProject = '源项目'; diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index b924bc50a9..63a2c33f3c 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -37,11 +37,11 @@ id; ?> name; ?> loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->sourceProject)->name_with_namespace; ?> - sourceBranch; ?> + sourceBranch;?> loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->targetProject)->name_with_namespace; ?> - targetBranch; ?> - status; ?> - canMerge; ?> + targetBranch;?> + mr->statusList, $mr->status);?> + mr->canMergeStatusList, $mr->canMerge);?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); From 615ba5eac4c570930d1d5f57507fc2308b7bcaf1 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 15:00:33 +0800 Subject: [PATCH 057/154] * Correct menu display of MR. --- module/common/lang/menu.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index b6337eee94..f9f3ecb4cb 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -524,6 +524,7 @@ $lang->navGroup->devops = 'devops'; $lang->navGroup->repo = 'devops'; $lang->navGroup->job = 'devops'; $lang->navGroup->jenkins = 'devops'; +$lang->navGroup->mr = 'devops'; $lang->navGroup->gitlab = 'devops'; $lang->navGroup->compile = 'devops'; $lang->navGroup->ci = 'devops'; From e89f6043b00b9cd11a7b4f1e202198b0e19640d8 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 15:01:34 +0800 Subject: [PATCH 058/154] * Optimize some function of processMR. --- module/mr/model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/mr/model.php b/module/mr/model.php index be700b5779..255c9e378e 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -35,7 +35,7 @@ class mrModel extends model { $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); - if($process) return $this->processMR($MR); + if($MR and $process) return $this->processMR($MR); return $MR; } @@ -70,6 +70,8 @@ class mrModel extends model */ public function processMR($MR) { + if(!isset($MR->gitlabID)) return $MR; + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); $MR->name = $rawMR->title; From e26c2672315eb0139950b13236758c761336a31e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 15:03:36 +0800 Subject: [PATCH 059/154] * Add view functions for MR. --- module/mr/control.php | 18 ++++++++++++++++++ module/mr/lang/zh-cn.php | 8 +++++++- module/mr/view/browse.html.php | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 305d671217..f286673ceb 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -88,6 +88,24 @@ class mr extends control die(js::reload('parent')); } + /** + * View a MR. + * + * @access public + * @return void + */ + public function view($id) + { + $MR = $this->mr->getByID($id); + if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); + + $this->view->title = $this->lang->mr->view; + $this->view->MR = $MR; + $this->view->rawMR = isset($rawMR) ? $rawMR : false; + + $this->display(); + } + /** * AJAX: Get MR target projects. * diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 8708c0be55..e62b6828ef 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -5,7 +5,7 @@ $lang->mr->browse = "浏览{$lang->mr->common}"; $lang->mr->list = $lang->mr->browse; $lang->mr->edit = "编辑{$lang->mr->common}"; $lang->mr->delete = "删除{$lang->mr->common}"; -$lang->mr->view = "详情"; +$lang->mr->view = "{$lang->mr->common}详情"; $lang->mr->id = 'ID'; $lang->mr->iid = "MR原始ID"; @@ -25,3 +25,9 @@ $lang->mr->targetProject = '目标项目'; $lang->mr->targetBranch = '目标分支'; $lang->mr->usersTips = '提示:如果无法选择指派人和评审人,请先前往GitLab页面绑定用户。'; +$lang->mr->notFound = "此{$lang->mr->common}不存在。"; + +$lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; + +$lang->mr->description = "描述"; + diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index b924bc50a9..c9f851ef2b 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -44,7 +44,7 @@ canMerge; ?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'view', "mr={$mr->id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> From 581791948c94bdab4537b5ec3db2221a0559321f Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 23 Aug 2021 07:54:44 +0000 Subject: [PATCH 060/154] * Fix GitLab bug. --- module/gitlab/view/browse.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index c8469121b2..94c039eb70 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -44,7 +44,7 @@ name;?> url;?> - + isAdminToken) ? '' : 'disabled'; common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary'"); From 95c9e107c36836576930994ffba96b47bbf7f381 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 16:22:46 +0800 Subject: [PATCH 061/154] * Refactor creating function for MR. --- module/mr/config.php | 4 +- module/mr/control.php | 7 +-- module/mr/lang/zh-cn.php | 28 ++++++------ module/mr/model.php | 82 ++++++++++++++++++---------------- module/mr/view/browse.html.php | 6 +-- 5 files changed, 66 insertions(+), 61 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index b0535585c1..e93a28f438 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -1,8 +1,8 @@ MR = new stdclass(); $config->MR->create = new stdclass(); -$config->MR->create->requiredFields = 'gitlabID,projectID,mrID,title'; -$config->MR->create->skippedFields = 'sourceProject,sourceBranch,targetProject,targetBranch'; +$config->MR->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; +$config->MR->create->skippedFields = 'projectID'; $config->MR->edit = new stdclass(); $config->MR->edit->requiredFields = 'title'; diff --git a/module/mr/control.php b/module/mr/control.php index f286673ceb..4c5f78f2e2 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -35,11 +35,8 @@ class mr extends control { if($_POST) { - $rawMR = $this->mr->create(); - if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => $rawMR->message)); - - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + $result = $this->mr->create(); + return $this->send($result); } $this->view->title = $this->lang->mr->create; diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 7e0d48e8b1..229fd39fa4 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -9,24 +9,25 @@ $lang->mr->view = "{$lang->mr->common}详情"; $lang->mr->source = '源项目分支'; $lang->mr->target = '目标项目分支'; -$lang->mr->id = 'ID'; -$lang->mr->iid = "MR原始ID"; -$lang->mr->name = '名称'; -$lang->mr->status = '状态'; -$lang->mr->author = '创建人'; -$lang->mr->assignee = '指派给'; -$lang->mr->reviewer = '评审人'; -$lang->mr->link = 'GitLab链接'; -$lang->mr->canMerge = '是否可合并'; +$lang->mr->id = 'ID'; +$lang->mr->mriid = "MR原始ID"; +$lang->mr->name = '名称'; +$lang->mr->status = '状态'; +$lang->mr->author = '创建人'; +$lang->mr->assignee = '指派给'; +$lang->mr->reviewer = '评审人'; +$lang->mr->link = 'GitLab链接'; +$lang->mr->mergeStatus = '是否可合并'; $lang->mr->statusList = array(); $lang->mr->statusList['opened'] = '开放中'; $lang->mr->statusList['closed'] = '已关闭'; $lang->mr->statusList['merged'] = '已合并'; -$lang->mr->canMergeStatusList = array(); -$lang->mr->canMergeStatusList['can_be_merged'] = '可合并'; -$lang->mr->canMergeStatusList['cannot_be_merged'] = '不可合并'; +$lang->mr->mergeStatusList = array(); +$lang->mr->mergeStatusList['checking'] = '检查中'; +$lang->mr->mergeStatusList['can_be_merged'] = '可合并'; +$lang->mr->mergeStatusList['cannot_be_merged'] = '不可合并'; $lang->mr->description = '描述'; $lang->mr->confirmDelete = '确认删除该merge request吗?'; @@ -38,7 +39,8 @@ $lang->mr->targetBranch = '目标分支'; $lang->mr->usersTips = '提示:如果无法选择指派人和评审人,请先前往GitLab页面绑定用户。'; $lang->mr->notFound = "此{$lang->mr->common}不存在。"; -$lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; +$lang->mr->createFailedFromAPI = "创建合并请求失败。"; +$lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; $lang->mr->description = "描述"; diff --git a/module/mr/model.php b/module/mr/model.php index 255c9e378e..097fd0d06b 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -27,15 +27,12 @@ class mrModel extends model * Get a MR by id. * * @param int $id - * @param bool $process * @access public * @return object */ - public function getByID($id, $process = true) + public function getByID($id) { - $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); - - if($MR and $process) return $this->processMR($MR); + $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); return $MR; } @@ -56,8 +53,6 @@ class mrModel extends model ->page($pager) ->fetchAll('id'); - foreach($MRList as $MR) $MR = $this->processMR($MR); - return $MRList; } @@ -79,7 +74,7 @@ class mrModel extends model $MR->sourceBranch = $rawMR->source_branch; $MR->targetProject = $rawMR->target_project_id; $MR->targetBranch = $rawMR->target_branch; - $MR->canMerge = $rawMR->merge_status; + $MR->mergeStatus = $rawMR->merge_status; $MR->status = $rawMR->state; return $MR; } @@ -124,45 +119,56 @@ class mrModel extends model */ public function create() { - $gitlabID = $this->post->gitlabID; - $projectID = $this->post->sourceProject; - - $MR = new stdclass; - $MR->target_project_id = $this->post->targetProject; - $MR->source_branch = $this->post->sourceBranch; - $MR->target_branch = $this->post->targetBranch; - $MR->title = $this->post->title; - $MR->description = $this->post->description; - $MR->assignee_ids = $this->post->assignee; - $MR->reviewer_ids = $this->post->reviewer; - - $rawMR = $this->apiCreateMR($gitlabID, $projectID, $MR); - - /* Another open merge request already exists for this source branch. */ - if(isset($rawMR->message) and !isset($rawMR->iid)) return $rawMR; - - /* Create MR failed. */ - if(!isset($rawMR->iid)) return false; - $MR = fixer::input('post') - ->add('repoID', 0) - ->add('gitlabID', $gitlabID) - ->add('projectID', $rawMR->project_id) /* sourceProject can be not project of the created MR. */ - ->add('mrID', $rawMR->iid) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->get(); - /* Remove extra fields before inserting db table. */ - foreach(explode(',', $this->config->MR->create->skippedFields) as $field) unset($MR->$field); - - $this->dao->insert(TABLE_MR)->data($MR) + $this->dao->insert(TABLE_MR)->data($MR, $this->config->MR->create->skippedFields) ->batchCheck($this->config->MR->create->requiredFields, 'notempty') ->autoCheck() ->exec(); - if(dao::isError()) return false; + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); - return $this->dao->lastInsertId(); + $MRID = $this->dao->lastInsertId(); + + $MRObject = new stdclass; + $MRObject->target_project_id = $MR->targetProject; + $MRObject->source_branch = $MR->sourceBranch; + $MRObject->target_branch = $MR->targetBranch; + $MRObject->title = $MR->title; + $MRObject->description = $MR->description; + $MRObject->assignee_ids = $MR->assignee; + $MRObject->reviewer_ids = $MR->reviewer; + + $rawMR = $this->apiCreateMR($this->post->gitlabID, $this->post->sourceProject, $MRObject); + + /* Another open merge request already exists for this source branch. */ + if(isset($rawMR->message) and !isset($rawMR->iid)) + { + $this->dao->delete()->from(TABLE_MR)->where('id')->eq($MRID)->exec(); + return array('result' => 'fail', 'message' => $rawMR->message); + } + + /* Create MR failed. */ + if(!isset($rawMR->iid)) + { + $this->dao->delete()->from(TABLE_MR)->where('id')->eq($MRID)->exec(); + return array('result' => 'fail', 'message' => $this->lang->mr->createFailedFromAPI); + } + + $MR = new stdclass; + $MR->mriid = $rawMR->iid; + $MR->status = $rawMR->state; + $MR->mergeStatus = $rawMR->merge_status; + + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($MR) + ->where('id')->eq($MRID) + ->autoCheck() + ->exec(); + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); } /** diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 5ab068e7ce..7fb8423902 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -27,7 +27,7 @@ mr->targetProject); ?> mr->targetBranch); ?> mr->status); ?> - mr->canMerge); ?> + mr->mergeStatus); ?> actions; ?> @@ -35,13 +35,13 @@ id; ?> - name; ?> + title; ?> loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->sourceProject)->name_with_namespace; ?> sourceBranch;?> loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->targetProject)->name_with_namespace; ?> targetBranch;?> mr->statusList, $mr->status);?> - mr->canMergeStatusList, $mr->canMerge);?> + mr->mergeStatusList, $mr->mergeStatus);?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); From 84f5c25aa9e47e7d1638012762b6808bb52cd715 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 16:53:10 +0800 Subject: [PATCH 062/154] * Refactor the function for editing MR. --- module/mr/config.php | 2 -- module/mr/control.php | 5 ++--- module/mr/model.php | 22 ++++++++++++---------- module/mr/view/edit.html.php | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index e93a28f438..952787e0e9 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -4,5 +4,3 @@ $config->MR->create = new stdclass(); $config->MR->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; $config->MR->create->skippedFields = 'projectID'; -$config->MR->edit = new stdclass(); -$config->MR->edit->requiredFields = 'title'; diff --git a/module/mr/control.php b/module/mr/control.php index 4c5f78f2e2..3b42488dec 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -54,9 +54,8 @@ class mr extends control { if($_POST) { - $this->mr->edit($MRID); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + $result = $this->mr->edit($MRID); + return $result; } $MR = $this->mr->getByID($MRID); diff --git a/module/mr/model.php b/module/mr/model.php index 097fd0d06b..4e6462db67 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -179,12 +179,10 @@ class mrModel extends model */ public function edit($MRID) { - /* Get MR in zentao database and do not append extra attributes in GitLab. */ - $MR = $this->getByID($MRID, $process = false); - $MR->title = $this->post->title; - $MR->description = $this->post->description; - $MR->assignee = $this->post->assignee; - $MR->reviewer = $this->post->reviewer; + $MR = fixer::input('post') + ->setDefault('editedBy', $this->app->user->account) + ->setDefault('editedDate', helper::now()) + ->get(); /* Update MR in GitLab. */ $newMR = new stdclass; @@ -192,15 +190,19 @@ class mrModel extends model $newMR->description = $MR->description; $newMR->assignee = $MR->assignee; $newMR->reviewer = $MR->reviewer; - $newMR->targetBranch = $this->post->targetBranch; - $this->apiUpdateMR($MR->gitlabID, $MR->projectID, $MR->mrID, $newMR); + $newMR->targetBranch = $MR->targetBranch; + + $oldMR = $this->getByID($MRID); + $this->apiUpdateMR($oldMR->gitlabID, $oldMR->sourceProject, $oldMR->mriid, $newMR); /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) - ->batchCheck($this->config->MR->edit->requiredFields, 'notempty') + ->where('id')->eq($MRID) ->autoCheck() ->exec(); - if(dao::isError()) return false; + + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); } /** diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index 63a18d337a..0df56316f7 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -43,7 +43,7 @@ mr->name;?> - name, "class='form-control'"); ?> + title, "class='form-control'"); ?> mr->description; ?> From 38f7285ff41ad3214ef549fd1b92926a3c66eb6f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 17:01:40 +0800 Subject: [PATCH 063/154] * Update zt_mr table. --- db/zentao.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/db/zentao.sql b/db/zentao.sql index 4ccd0bf73f..953bff1a88 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -546,11 +546,13 @@ CREATE TABLE IF NOT EXISTS `zt_module` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_mr`; CREATE TABLE `zt_mr` ( - `id` mediumint(8) unsigned NOT NULL auto_increment, - `repoID` mediumint(8) unsigned NOT NULL, + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `gitlabID` mediumint(8) unsigned NOT NULL, - `projectID` mediumint(8) unsigned NOT NULL, - `mrID` mediumint(8) unsigned NOT NULL, + `sourceProject` int unsigned NOT NULL, + `sourceBranch` varchar(100) NOT NULL, + `targetProject` int unsigned NOT NULL, + `targetBranch` varchar(100) NOT NULL, + `mriid` int unsigned NOT NULL, `title` varchar(255) NOT NULL, `description` text NOT NULL, `assignee` varchar(255) NOT NULL, @@ -560,6 +562,8 @@ CREATE TABLE `zt_mr` ( `editedBy` varchar(30) NOT NULL, `editedDate` datetime NOT NULL, `deleted` tinyint(1) NOT NULL, + `status` char(30) NOT NULL, + `mergeStatus` char(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_notify`; From 7ccb99423b5762ce5d5ce1b7c579961330dcf79f Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 17:04:51 +0800 Subject: [PATCH 064/154] * Fix delete mr error. --- module/mr/control.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 305d671217..ae41cf7adb 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -71,9 +71,9 @@ class mr extends control } /** - * Delete a mr. + * Delete a MR. * - * @param int $MR + * @param int $id * @access public * @return void */ @@ -81,11 +81,12 @@ class mr extends control { if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); - $MRList = $this->mr->getByID($id); + $MR = $this->mr->getByID($id); - $this->mr->apiDeleteMR($MRList->gitlabID, $MRList->projectID, $MRList->mrID); - $this->mr->deleteMR($id); - die(js::reload('parent')); + $this->dao->delete()->from(TABLE_MR)->where('id')->eq($id)->exec(); + $this->mr->apiDeleteMR($MR->gitlabID, $MR->sourceProject, $MR->mriid); + + die(js::locate(inlink('browse'), 'parent')); } /** @@ -125,4 +126,10 @@ class mr extends control $this->send($options); } + + public function diff($MRID) + { + $MR = $this->mr->getByID($MRID); + $versions = $this->mr->apiGetDiffVersions($MR); + } } From 82ba7789b6bd2904f6b446ee0e19e857c2d301c6 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 17:06:21 +0800 Subject: [PATCH 065/154] * Fix params of get versions api. --- module/mr/model.php | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index be700b5779..f603124236 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -82,22 +82,6 @@ class mrModel extends model return $MR; } - /** - * Delete one MR. - * - * condition: when user deleting a repo. - * - * @param int $id - * @access public - * @return void - */ - public function deleteMR($id) - { - $this->dao->delete()->from(TABLE_MR) - ->andWhere('id')->eq($id) - ->exec(); - } - /** * Get gitlab pairs. * @@ -295,15 +279,13 @@ class mrModel extends model * Get MR diff versions by API. * * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-mr-diff-versions - * @param int $gitlabID - * @param int $projectID - * @param int $MRID + * @param object $MR * @access public * @return object */ - public function apiGetDiffVersions($gitlabID, $projectID, $MRID) + public function apiGetDiffVersions($MR) { - $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); + $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->targetProject}/merge_requests/$MR->mriid/versions"); return json_decode(commonModel::http($url)); } @@ -318,7 +300,7 @@ class mrModel extends model * @access public * @return object */ - public function apiGetSingleDiffVersion($gitlabID, $projectID, $MRID, $versionID) + public function apiGetSingleDiffVersion($MRID, $versionID) { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/versions/$versionID"); return json_decode(commonModel::http($url)); From d2e51fb7a37755bc8fb27fd80586830be880bb00 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 17:07:26 +0800 Subject: [PATCH 066/154] * Rename mrModel::edit function. --- module/mr/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/model.php b/module/mr/model.php index 9924df8966..c4ed60e886 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -161,7 +161,7 @@ class mrModel extends model * @access public * @return void */ - public function edit($MRID) + public function update($MRID) { $MR = fixer::input('post') ->setDefault('editedBy', $this->app->user->account) From 80c872be8062d9ebc75d59641cc47168b20eba1a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 17:08:03 +0800 Subject: [PATCH 067/154] * Rename mrModel::edit function. --- module/mr/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index bf978e5fd7..d322b40ad3 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -54,7 +54,7 @@ class mr extends control { if($_POST) { - $result = $this->mr->edit($MRID); + $result = $this->mr->update($MRID); return $result; } From eb5e3dbac7e975ca20e5c46cd5e32b24ff5734cd Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 23 Aug 2021 17:14:34 +0800 Subject: [PATCH 068/154] * Fix params of apiGetSingleDiffVersion and apiGetDiffVersions. --- module/mr/model.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index c4ed60e886..58f84d5669 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -32,8 +32,7 @@ class mrModel extends model */ public function getByID($id) { - $MR = $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); - return $MR; + return $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); } /** @@ -195,14 +194,14 @@ class mrModel extends model * @docs https://docs.gitlab.com/ee/api/merge_requests.html#create-mr * @param int $gitlabID * @param int $projectID - * @param object $params + * @param object $MR * @access public * @return object */ - public function apiCreateMR($gitlabID, $projectID, $params) + public function apiCreateMR($gitlabID, $projectID, $MR) { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); - return json_decode(commonModel::http($url, $data=$params, $options = array())); + return json_decode(commonModel::http($url, $MR)); } /** @@ -295,7 +294,7 @@ class mrModel extends model */ public function apiGetDiffVersions($MR) { - $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->targetProject}/merge_requests/$MR->mriid/versions"); + $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->sourceProject}/merge_requests/$MR->mriid/versions"); return json_decode(commonModel::http($url)); } @@ -303,17 +302,14 @@ class mrModel extends model * Get single diff version by API. * * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-mr-diff-version - * @param int $gitlabID - * @param int $projectID - * @param int $MRID - * @param int $versionID + * @param object $MR + * @param int $versionID * @access public * @return object */ - public function apiGetSingleDiffVersion($MRID, $versionID) + public function apiGetSingleDiffVersion($MR, $versionID) { - $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/versions/$versionID"); + $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->sourceProject}/merge_requests/{$MR->mriid}/versions/$versionID"); return json_decode(commonModel::http($url)); } } - From 6095bc4246df596f3ed1889a84f4986157dc608d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 17:57:50 +0800 Subject: [PATCH 069/154] * Get latest MR from GitLab API before display MR. --- module/mr/control.php | 17 +++++++++-------- module/mr/model.php | 29 +++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 3b42488dec..b4a9fcbb3b 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -54,7 +54,7 @@ class mr extends control { if($_POST) { - $result = $this->mr->edit($MRID); + $result = $this->mr->update($MRID); return $result; } @@ -67,9 +67,9 @@ class mr extends control } /** - * Delete a mr. + * Delete a MR. * - * @param int $MR + * @param int $id * @access public * @return void */ @@ -77,11 +77,12 @@ class mr extends control { if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); - $MRList = $this->mr->getByID($id); + $MR = $this->mr->getByID($id); - $this->mr->apiDeleteMR($MRList->gitlabID, $MRList->projectID, $MRList->mrID); - $this->mr->deleteMR($id); - die(js::reload('parent')); + $this->dao->delete()->from(TABLE_MR)->where('id')->eq($id)->exec(); + $this->mr->apiDeleteMR($MR->gitlabID, $MR->sourceProject, $MR->mriid); + + die(js::locate(inlink('browse'), 'parent')); } /** @@ -93,7 +94,7 @@ class mr extends control public function view($id) { $MR = $this->mr->getByID($id); - if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); + if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); $this->view->title = $this->lang->mr->view; $this->view->MR = $MR; diff --git a/module/mr/model.php b/module/mr/model.php index 4e6462db67..d7b1c3ba73 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -53,6 +53,8 @@ class mrModel extends model ->page($pager) ->fetchAll('id'); + foreach($MRList as $MR) $this->apiSyncMR($MR); + return $MRList; } @@ -67,7 +69,7 @@ class mrModel extends model { if(!isset($MR->gitlabID)) return $MR; - $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); $MR->name = $rawMR->title; $MR->sourceProject = $rawMR->source_project_id; @@ -205,6 +207,29 @@ class mrModel extends model return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); } + /** + * sync MR from GitLab API to Zentao database. + * + * @param object $MR + * @access public + * @return void + */ + public function apiSyncMR($MR) + { + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + if(isset($rawMR->iid)) + { + $newMR = new stdclass; + $newMR->status = $rawMR->state; + $newMR->mergeStatus = $rawMR->merge_status; + + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($newMR) + ->where('id')->eq($MR->id) + ->exec(); + } + } + /** * Create MR by API. * @@ -241,7 +266,7 @@ class mrModel extends model * * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr * @param int $gitlabID - * @param int $projectID + * @param int $projectID targetProject * @param int $MRID * @access public * @return object From dc981a4a05ed574b1e9abd314dc2b063d22e98de Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 08:26:13 +0800 Subject: [PATCH 070/154] * Update function for editing MR. --- module/mr/control.php | 14 ++++++++++---- module/mr/model.php | 3 ++- module/mr/view/edit.html.php | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 94bec9ea71..1a04cd649e 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -55,13 +55,19 @@ class mr extends control if($_POST) { $result = $this->mr->update($MRID); - return $result; + return $this->send($result); } $MR = $this->mr->getByID($MRID); - $this->view->MR = $MR; - $this->view->title = $this->lang->mr->edit; - $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); /* Get user list for assignee and reviewer. */ + + $branchList = $this->loadModel('gitlab')->getBranches($MR->gitlabID, $MR->targetProject); + $targetBranchList = array(); + foreach($branchList as $branch) $targetBranchList[$branch] = $branch; + + $this->view->MR = $MR; + $this->view->targetBranchList = $targetBranchList; + $this->view->title = $this->lang->mr->edit; + $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); /* Get user list for assignee and reviewer. */ $this->display(); } diff --git a/module/mr/model.php b/module/mr/model.php index cffb6f28ce..7729d55de6 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -178,7 +178,8 @@ class mrModel extends model $newMR->targetBranch = $MR->targetBranch; $oldMR = $this->getByID($MRID); - $this->apiUpdateMR($oldMR->gitlabID, $oldMR->sourceProject, $oldMR->mriid, $newMR); + + $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR); /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index 0df56316f7..d47637b8b4 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -37,7 +37,7 @@
loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject)->name_with_namespace;?> mr->targetBranch ?> - loadModel('gitlab')->getBranches($MR->gitlabID, $MR->targetProject), '', "class='form-control chosen'");?> + targetBranch, "class='form-control chosen'");?>
From 2c0f36696d4b7a5a91eedd32227d82118be2fb78 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 24 Aug 2021 02:12:17 +0000 Subject: [PATCH 071/154] * Adjust GitLab Token validation code. --- module/gitlab/lang/zh-cn.php | 2 +- module/gitlab/view/browse.html.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index f48412f833..f565ee11df 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -40,7 +40,7 @@ $lang->gitlab->placeholder->token = "请填写具有admin权限账户的access t $lang->gitlab->noImportableIssues = "目前没有可供导入的issue。"; $lang->gitlab->tokenError = "当前token非管理员权限。"; -$lang->gitlab->tokenLimit = "GitLab Token权限不足,无法使用当前功能。请更换为有管理员权限的GitLab Token。"; +$lang->gitlab->tokenLimit = "GitLab Token权限不足。请更换为有管理员权限的GitLab Token。"; $lang->gitlab->hostError = "无效的GitLab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; $lang->gitlab->importIssueError = "未选择该issue所属的执行。"; diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 94c039eb70..799a25a524 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -40,11 +40,11 @@ $gitlab): ?> - + name;?> url;?> - + isAdminToken) ? '' : 'disabled'; common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary'"); From 18569c95d2c5e2293cce4176582fb4f55cf94d05 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 10:19:57 +0800 Subject: [PATCH 072/154] * Update apiSyncMR function. --- module/mr/config.php | 10 ++++++++++ module/mr/model.php | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index 952787e0e9..35fdbbcb4a 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -4,3 +4,13 @@ $config->MR->create = new stdclass(); $config->MR->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; $config->MR->create->skippedFields = 'projectID'; +$config->MR->maps = new stdclass; +$config->MR->maps->sync = array(); +$config->MR->maps->sync['title'] = 'title|field|'; +$config->MR->maps->sync['description'] = 'description|field|'; +$config->MR->maps->sync['assignee'] = 'assignees|userPairs|id'; +$config->MR->maps->sync['reviewer'] = 'reviewers|userPairs|id'; +$config->MR->maps->sync['targetBranch'] = 'target_branch|field|'; +$config->MR->maps->sync['status'] = 'state|field|'; +$config->MR->maps->sync['mergeStatus'] = 'merge_status|field|'; + diff --git a/module/mr/model.php b/module/mr/model.php index 7729d55de6..fddfe980a5 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -201,11 +201,27 @@ class mrModel extends model public function apiSyncMR($MR) { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + if(isset($rawMR->iid)) { + $map = $this->config->MR->maps->sync; + $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); + $newMR = new stdclass; - $newMR->status = $rawMR->state; - $newMR->mergeStatus = $rawMR->merge_status; + foreach($map as $syncField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + + if($optionType == 'field') $value = $rawMR->$field; + if($optionType == 'userPairs') + { + $gitlabUserID = isset($rawMR->$field->$options) ? $rawMR->$field->$options : ''; + $value = zget($gitlabUsers, $gitlabUserID, ''); + } + + if($value) $newMR->$syncField = $value; + } /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($newMR) From be9a94087c9ebd38347298d5eb50abd5962b60f5 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 10:52:35 +0800 Subject: [PATCH 073/154] * Change assignee and reviewer from gitlab user ID to zentao account. --- module/mr/model.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index fddfe980a5..a81532f6c6 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -142,13 +142,18 @@ class mrModel extends model return array('result' => 'fail', 'message' => $this->lang->mr->createFailedFromAPI); } - $MR = new stdclass; - $MR->mriid = $rawMR->iid; - $MR->status = $rawMR->state; - $MR->mergeStatus = $rawMR->merge_status; + $newMR = new stdclass; + $newMR->mriid = $rawMR->iid; + $newMR->status = $rawMR->state; + $newMR->mergeStatus = $rawMR->merge_status; + + /* Change gitlab user ID to zentao account. */ + $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); + $newMR->assignee = zget($gitlabUsers, $MR->assignee, ''); + $newMR->reviewer = zget($gitlabUsers, $MR->reviewer, ''); /* Update MR in Zentao database. */ - $this->dao->update(TABLE_MR)->data($MR) + $this->dao->update(TABLE_MR)->data($newMR) ->where('id')->eq($MRID) ->autoCheck() ->exec(); @@ -216,7 +221,11 @@ class mrModel extends model if($optionType == 'field') $value = $rawMR->$field; if($optionType == 'userPairs') { - $gitlabUserID = isset($rawMR->$field->$options) ? $rawMR->$field->$options : ''; + $gitlabUserID = ''; + if(isset($rawMR->$field[0])) + { + $gitlabUserID = $rawMR->$field[0]->$options; + } $value = zget($gitlabUsers, $gitlabUserID, ''); } From 4f94bcafc59d1558aaeb469cec68372b3bbfa44e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 11:13:00 +0800 Subject: [PATCH 074/154] * Update function for editing a MR. --- module/mr/control.php | 4 ++++ module/mr/model.php | 5 +++++ module/mr/view/edit.html.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 1a04cd649e..3061c33d4c 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -64,10 +64,14 @@ class mr extends control $targetBranchList = array(); foreach($branchList as $branch) $targetBranchList[$branch] = $branch; + $gitlabUsers = $this->gitlab->getUserAccountIdPairs($MR->gitlabID); + $this->view->MR = $MR; $this->view->targetBranchList = $targetBranchList; $this->view->title = $this->lang->mr->edit; $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); /* Get user list for assignee and reviewer. */ + $this->view->assignee = zget($gitlabUsers, $MR->assignee, ''); + $this->view->reviewer = zget($gitlabUsers, $MR->reviewer, ''); $this->display(); } diff --git a/module/mr/model.php b/module/mr/model.php index a81532f6c6..f2202e0c22 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -186,6 +186,11 @@ class mrModel extends model $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR); + /* Change gitlab user ID to zentao account. */ + $gitlabUsers = $this->gitlab->getUserIdAccountPairs($oldMR->gitlabID); + $MR->assignee = zget($gitlabUsers, $MR->assignee, ''); + $MR->reviewer = zget($gitlabUsers, $MR->reviewer, ''); + /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) ->where('id')->eq($MRID) diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index d47637b8b4..582c1eb440 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -51,11 +51,11 @@ mr->assignee;?> - assignee, "class='form-control chosen'")?> + mr->reviewer;?> - reviewer, "class='form-control chosen'")?> + From 67569ee658cbb60e786492c66fcf00ec5057c528 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 24 Aug 2021 07:36:22 +0000 Subject: [PATCH 075/154] * Add GitLab log. --- module/gitlab/control.php | 62 +++++++++++++++++++++++++++++- module/gitlab/view/browse.html.php | 2 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index ae65e37916..e461559806 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -57,7 +57,20 @@ class gitlab extends control $this->checkToken(); $gitlabID = $this->gitlab->create(); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + if(dao::isError()) + { + /* Save log. */ + $now = new datetime('now'); + $log = ''; + $time = $now->format('G:i:s'); + $output = "\n" . dao::isError(); + + $log = "$time Create Error output : $output\n"; + $this->logGitLab($log); + unset($log); + + return $this->send(array('result' => 'fail', 'message' => dao::getError())); + } return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -80,7 +93,20 @@ class gitlab extends control { $this->checkToken(); $this->gitlab->update($id); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + if(dao::isError()) + { + /* Save log. */ + $now = new datetime('now'); + $log = ''; + $time = $now->format('G:i:s'); + $output = "\n" . dao::isError(); + + $log = "$time Edit output : $output\n"; + $this->gitlab->logGitLab($log); + unset($log); + + return $this->send(array('result' => 'fail', 'message' => dao::getError())); + } return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -179,6 +205,19 @@ class gitlab extends control if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); $this->gitlab->delete(TABLE_PIPELINE, $id); + + if(dao::isError()) + { + /* Save log. */ + $now = new datetime('now'); + $log = ''; + $time = $now->format('G:i:s'); + $output = "\n" . dao::isError(); + + $log = "$time Delete output : $output\n"; + $this->gitlab->logGitLab($log); + unset($log); + } die(js::reload('parent')); } @@ -381,6 +420,25 @@ class gitlab extends control $this->send($options); } + /** + * Log GitLab. + * + * @param string $log + * @access public + * @return void + */ + public function logGitLab($log) + { + if(!is_writable($this->app->getLogRoot())) return false; + + $file = $this->app->getLogRoot() . 'GitLab.' . date('Ymd') . '.log.php'; + if(!is_file($file)) $log = " $gitlab): ?> - + name;?> url;?> From 8a6ef83c499ae009459558747b842fd7991ea51a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 17:35:17 +0800 Subject: [PATCH 076/154] + Add apiGetSingleBranch function. --- module/gitlab/model.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0320cd7472..087fadabc5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -470,6 +470,21 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + /** + * Get single branch by API. + * + * @param int $gitlabID + * @param int $projectID + * @param string $branch + * @access public + * @return object + */ + public function apiGetSingleBranch($gitlabID, $projectID, $branch) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/branches/$branch"); + return json_decode(commonModel::http($url)); + } + /** * Get Forks of a project by API. * From df116c8cdbacf462233aa8428628674bc5973d45 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 23:22:35 +0800 Subject: [PATCH 077/154] * Add view a MR(staging). --- module/mr/control.php | 16 +++++++++++ module/mr/lang/zh-cn.php | 53 ++++++++++++++++++++++++++++++++++++ module/mr/view/view.html.php | 46 +++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 module/mr/view/view.html.php diff --git a/module/mr/control.php b/module/mr/control.php index 3061c33d4c..9147fc1796 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -110,6 +110,22 @@ class mr extends control $this->view->MR = $MR; $this->view->rawMR = isset($rawMR) ? $rawMR : false; + $this->loadModel('gitlab'); + $sourceProject = $this->gitlab->apiGetSingleProject($MR->gitlabID, $MR->sourceProject); + $targetProject = $this->gitlab->apiGetSingleProject($MR->gitlabID, $MR->targetProject); + $sourceBranch = $this->gitlab->apiGetSingleBranch($MR->gitlabID, $MR->sourceProject, $MR->sourceBranch); + $targetBranch = $this->gitlab->apiGetSingleBranch($MR->gitlabID, $MR->targetProject, $MR->targetBranch); + + $this->view->sourceProjectName = $sourceProject->name_with_namespace; + $this->view->targetProjectName = $targetProject->name_with_namespace; + $this->view->sourceProjectURL = $sourceBranch ->web_url; + $this->view->targetProjectURL = $targetBranch ->web_url; + + + /* Those variables are used to render $lang->mr->commandDocument. */ + $this->view->httpRepoURL = $sourceProject->http_url_to_repo; + $this->view->branchPath = $sourceProject->path_with_namespace . '-' . $rawMR->source_branch; + $this->display(); } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 229fd39fa4..5ae6e62d8a 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -18,6 +18,8 @@ $lang->mr->assignee = '指派给'; $lang->mr->reviewer = '评审人'; $lang->mr->link = 'GitLab链接'; $lang->mr->mergeStatus = '是否可合并'; +$lang->mr->commits = '提交数'; +$lang->mr->changes = '更改数'; $lang->mr->statusList = array(); $lang->mr->statusList['opened'] = '开放中'; @@ -44,3 +46,54 @@ $lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; $lang->mr->description = "描述"; +$lang->mr->from = "请求合并"; +$lang->mr->to = "入"; +$lang->mr->at = "于"; +$lang->mr->pipeline = "流水线"; +$lang->mr->pipelineSuccess = "已通过"; +$lang->mr->pipelineFailed = "未通过"; +$lang->mr->pipelineCancled = "已取消"; +$lang->mr->pipelineUnknown = "未知"; + +$lang->mr->pipelineStatus = array(); +$lang->mr->pipelineStatus['success'] = "已通过"; +$lang->mr->pipelineStatus['failed'] = "未通过"; +$lang->mr->pipelineStatus['canceled'] = "已取消"; + +$lang->mr->MRHasConflicts = "是否存在合并冲突"; +$lang->mr->hasConflicts = "存在合并冲突"; +$lang->mr->hasNoConflict = "可以合并请求"; +$lang->mr->mergeByManual = "此合并请求可以手动合并,请使用以下"; +$lang->mr->commandLine = "命令行"; + +/** + * Merge Command Document. + * + * %s source_roject::http_url_to_repo + * %s mr::source_branch + * %s source_project::path_with_namespace . '-' . mr::source_branch + * %s mr::target_branch + * %s source_project::path_with_namespace . '-' . mr::source_branch + * %s mr::target_branch + */ +$lang->mr->commandDocument = <<< EOD +

在本地检出、审核和合并

+ 第 1 步. 获取并查看此合并请求的分支 +
+    git fetch "%s" %s
+    git checkout -b "%s" FETCH_HEAD
+    
+ 第 2 步. 在本地查看更改 +
+ 第 3 步. 合并分支并解决出现的任何冲突 +
+    git fetch origin
+    git checkout "%s"
+    git merge --no-ff "%s"
+    
+ 第 4 步. 将合并结果推送到GitLab +
+    git push origin "%s"
+    
+EOD; + diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php new file mode 100644 index 0000000000..bd7af3990c --- /dev/null +++ b/module/mr/view/view.html.php @@ -0,0 +1,46 @@ + +id)):?> +
+
+

+ mr->notFound;?> + + createLink('mr', 'create'), " " . $lang->mr->create, '', "class='btn btn-info'");?> + +

+
+
+ +
+ createLink('mr', 'browse'), ' ' . $lang->goback, '', "class='btn btn-secondary'");?> +
+
+ id?> + web_url, $MR->title, "_blank", "class='btn btn-link btn-active-text' style='color: blue'");?> +
+
+ +
+
+
+
+
mr->description;?>
+
+ description) ? $MR->description : "
" . $lang->noData . '
';?> +
+
+
+ +
+
mr->from . html::a($sourceProjectURL, $sourceProjectName . ":" . $MR->sourceBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'") . $lang->mr->to . html::a($targetProjectURL, $targetProjectName . ":" . $MR->targetBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'");?>
+
head_pipeline->status)) echo $lang->mr->pipeline . $lang->mr->status . ": " . zget($lang->mr->pipelineStatus, $rawMR->head_pipeline->status, $lang->mr->pipelineUnknown);?>
+
mr->mergeStatus . ": " . zget($lang->mr->mergeStatusList, $rawMR->merge_status);?>
+
mr->MRHasConflicts . ": " . ($rawMR->has_conflicts ? $lang->mr->hasConflicts : $lang->mr->hasNoConflict);?>
+
+ +
mr->commandDocument, $httpRepoURL, $MR->sourceBranch, $branchPath, $MR->targetBranch, $branchPath, $MR->targetBranch);?>
+
+
+ + + From 7ed0e3c9702acb66d2be76216063d5c500e23a07 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 25 Aug 2021 10:32:44 +0800 Subject: [PATCH 078/154] * Add getDiffs function. --- module/mr/control.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index 3061c33d4c..12038bc8f4 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -154,6 +154,7 @@ class mr extends control public function diff($MRID) { $MR = $this->mr->getByID($MRID); - $versions = $this->mr->apiGetDiffVersions($MR); + $this->view->diffs = $this->mr->getDiffs($MR); + $this->display(); } } From e578838258803e791fa8ae046af1f186d4caa4b8 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 25 Aug 2021 10:33:53 +0800 Subject: [PATCH 079/154] * Add fromProject param for diff. --- lib/scm/gitlab.class.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index a5c472ed06..e36d4b86d0 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -276,13 +276,21 @@ class gitlab * @access public * @return array */ - public function diff($path, $fromRevision, $toRevision) + public function diff($path, $fromRevision, $toRevision, $fromProject = '') { if(!scm::checkRevision($fromRevision)) return array(); if(!scm::checkRevision($toRevision)) return array(); - $api = "compare"; - $params = array('from' => $fromRevision, 'to' => $toRevision, 'straight' => 1); + $api = "compare"; + $params = array('from' => $fromRevision, 'to' => $toRevision, 'straight' => 1); + if($fromProject) + { + $params['from'] = 'dev'; + $params['to'] = 'master'; + $params['from_project_id'] = $fromProject; + $params['straight'] = 1; + } + if($toRevision == 'HEAD' and $this->branch) $params['to'] = $this->branch; $results = $this->fetch($api, $params); foreach($results->diffs as $key => $diff) @@ -301,7 +309,6 @@ class gitlab foreach($diffLines as $diffLine) $lines[] = $diffLine; } return $lines; - //return $results->diffs; } /** From 22d79c2681b42e132b7b874275c22155b1b4a6d3 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 25 Aug 2021 10:35:12 +0800 Subject: [PATCH 080/154] * Add extra param to scm::diff function. --- lib/scm/scm.class.php | 127 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/lib/scm/scm.class.php b/lib/scm/scm.class.php index 24f9687e29..d148cc166c 100644 --- a/lib/scm/scm.class.php +++ b/lib/scm/scm.class.php @@ -5,8 +5,8 @@ class scm /** * Set engine. - * - * @param object $repo + * + * @param object $repo * @access public * @return void */ @@ -19,10 +19,10 @@ class scm } /** - * List files. - * - * @param string $path - * @param string $revision + * List files. + * + * @param string $path + * @param string $revision * @access public * @return array */ @@ -34,10 +34,10 @@ class scm /** * Get tags. - * - * @param string $path - * @param string $revision - * @param bool $onlyDir + * + * @param string $path + * @param string $revision + * @param bool $onlyDir * @access public * @return array */ @@ -49,7 +49,7 @@ class scm /** * Get branch. - * + * * @access public * @return array */ @@ -60,11 +60,11 @@ class scm /** * Get log. - * - * @param string $path - * @param string $fromRevision - * @param string $toRevision - * @param int $count + * + * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param int $count * @access public * @return array */ @@ -78,9 +78,9 @@ class scm /** * Blame file. - * - * @param string $path - * @param string $revision + * + * @param string $path + * @param string $revision * @access public * @return array */ @@ -92,9 +92,9 @@ class scm /** * Get last log. - * - * @param string $path - * @param int $count + * + * @param string $path + * @param int $count * @access public * @return array */ @@ -105,20 +105,21 @@ class scm /** * Diff file. - * - * @param string $path - * @param string $fromRevision - * @param string $toRevision - * @param string $parse + * + * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param string $parse * @access public * @return array */ - public function diff($path, $fromRevision = 0, $toRevision = 'HEAD', $parse = 'yes') + public function diff($path, $fromRevision = 0, $toRevision = 'HEAD', $parse = 'yes', $extra = '') { if(!scm::checkRevision($fromRevision)) return array(); if(!scm::checkRevision($toRevision)) return array(); - $diffs = $this->engine->diff($path, $fromRevision, $toRevision); + if(!$extra) $diffs = $this->engine->diff($path, $fromRevision, $toRevision); + if($extra) $diffs = $this->engine->diff($path, $fromRevision, $toRevision, $extra); if($parse != 'yes') return implode("\n", $diffs); return $this->engine->parseDiff($diffs); @@ -126,23 +127,23 @@ class scm /** * Cat file. - * - * @param string $entry - * @param string $revision + * + * @param string $entry + * @param string $revision * @access public * @return string */ public function cat($entry, $revision = 'HEAD') { if(!scm::checkRevision($revision)) return false; - return $this->engine->cat($entry, $revision); + return $this->engine->cat($entry, $revision); } /** * Get info. - * - * @param string $entry - * @param string $revision + * + * @param string $entry + * @param string $revision * @access public * @return object */ @@ -154,8 +155,8 @@ class scm /** * Exec scm cmd. - * - * @param string $cmd + * + * @param string $cmd * @access public * @return array */ @@ -165,47 +166,47 @@ class scm } /** - * Get commit count - * - * @param int $commits - * @param string $lastVersion + * Get commit count + * + * @param int $commits + * @param string $lastVersion * @access public * @return int */ public function getCommitCount($commits = 0, $lastVersion = 0) { if(!scm::checkRevision($lastVersion)) return false; - return $this->engine->getCommitCount($commits, $lastVersion); + return $this->engine->getCommitCount($commits, $lastVersion); } /** * Get latest revision. - * + * * @access public * @return string */ public function getLatestRevision() { - return $this->engine->getLatestRevision(); + return $this->engine->getLatestRevision(); } /** * Get first revision. - * + * * @access public * @return string */ public function getFirstRevision() { - return $this->engine->getFirstRevision(); + return $this->engine->getFirstRevision(); } /** * Get commits. - * - * @param string $version - * @param int $count - * @param string $branch + * + * @param string $version + * @param int $count + * @param string $branch * @access public * @return array */ @@ -216,9 +217,9 @@ class scm } /** - * Check revision - * - * @param int|string $revision + * Check revision + * + * @param int|string $revision * @static * @access public * @return bool @@ -231,9 +232,9 @@ class scm } /** - * Escape command. - * - * @param string $cmd + * Escape command. + * + * @param string $cmd * @access public * @return string */ @@ -246,12 +247,12 @@ function escapeCmd($cmd) } /** - * Execute command. - * - * @param string $cmd - * @param string $return - * @param int $result - * @param string $type + * Execute command. + * + * @param string $cmd + * @param string $return + * @param int $result + * @param string $type * @access public * @return array|string */ From eef945755ffe8dfcdefa9ffb2b1d52bdd16ab753 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 25 Aug 2021 10:36:18 +0800 Subject: [PATCH 081/154] * Add diff page. --- module/mr/model.php | 36 ++++---- module/mr/view/browse.html.php | 3 +- module/mr/view/diff.html.php | 147 +++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 18 deletions(-) create mode 100644 module/mr/view/diff.html.php diff --git a/module/mr/model.php b/module/mr/model.php index f2202e0c22..6b89bf1df1 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -348,24 +348,26 @@ class mrModel extends model * @access public * @return object */ - public function apiGetDiffVersions($MR) + public function getDiffs($MR) { - $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->sourceProject}/merge_requests/$MR->mriid/versions"); - return json_decode(commonModel::http($url)); - } + $gitlab = $this->gitlab->getByID($MR->gitlabID); + $fromProject = $MR->sourceProject; + $toProject = $MR->targetProject; - /** - * Get single diff version by API. - * - * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-mr-diff-version - * @param object $MR - * @param int $versionID - * @access public - * @return object - */ - public function apiGetSingleDiffVersion($MR, $versionID) - { - $url = sprintf($this->gitlab->getApiRoot($MR->gitlabID), "/projects/{$MR->sourceProject}/merge_requests/{$MR->mriid}/versions/$versionID"); - return json_decode(commonModel::http($url)); + $this->loadModel('repo'); + $repo = new stdclass; + $repo->SCM = 'GitLab'; + $repo->gitlab = $gitlab->id; + $repo->project = $toProject; + $repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $toProject); + $repo->client = $gitlab->url; + $repo->password = $gitlab->token; + + $scm = $this->app->loadClass('scm'); + $scm->setEngine($repo); + + $encoding = empty($encoding) ? $repo->encoding : $encoding; + $encoding = strtolower(str_replace('_', '-', $encoding)); + return $scm->diff('', $fromProject, $toProject, $parse = true, $fromProject); } } diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 7fb8423902..4d1fe12c67 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -44,8 +44,9 @@ mr->mergeStatusList, $mr->mergeStatus);?> id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); + common::printLink('mr', 'view', "mr={$mr->id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + common::printLink('mr', 'diff', "mr={$mr->id}", '', '', "title='{$lang->mr->diff}' class='btn btn-info'"); if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); ?> diff --git a/module/mr/view/diff.html.php b/module/mr/view/diff.html.php new file mode 100644 index 0000000000..0c2d5e88bd --- /dev/null +++ b/module/mr/view/diff.html.php @@ -0,0 +1,147 @@ + + + + + + +
+
+
+
+ repo->viewDiffList['inline'], "id='inline'", $arrange == 'inline' ? 'active btn btn-sm' : 'btn btn-sm')?> + repo->viewDiffList['appose'], "id='appose'", $arrange == 'appose' ? 'active btn btn-sm' : 'btn btn-sm')?> +
+
+
+
+ repo->encodingList, $encoding, $lang->repo->encoding) . "", "data-toggle='dropdown'", 'btn dropdown-toggle btn-sm')?> + +
+
+
+ +
+
+ +
+ + + contents)) continue;?> + contents as $content):?> + oldStartLine; + $newCurrentLine = $content->newStartLine; + ?> + + + + + + + + + + + + lines as $line):?> + + + + + + + + lines as $line):?> + + type == 'old') + { + $oldlc = $line->oldlc; + $newlc = ''; + if(isset($content->new[$oldlc])) + { + $newlc = $line->oldlc; + $line->type = 'custom'; + } + } + else + { + $oldlc = $line->oldlc; + $newlc = $line->newlc; + if(!isset($content->new[$newlc])) continue; + } + ?> + + + + + old[$oldlc])) unset($content->old[$oldlc]); + if(isset($content->new[$newlc])) unset($content->new[$newlc]); + ?> + + + + +
fileName;?>
......
type != 'new') echo $line->oldlc?>type != 'old') echo $line->newlc?>line = $repo->SCM == 'Subversion' ? htmlspecialchars($line->line) : $line->line; + echo $line->type == 'old' ? preg_replace('/^\-/', '–', $line->line) : ($line->type == 'new' ? $line->line : ' ' . $line->line); + ?>
type?> type == 'custom') echo "line-old"?> code'>old[$oldlc])) $content->old[$oldlc] = ''; + $content->old[$oldlc] = $repo->SCM == 'Subversion' ? htmlspecialchars($content->old[$oldlc]) : $content->old[$oldlc]; + if(!empty($oldlc)) echo $line->type != 'all' ? preg_replace('/^\-/', '–', $content->old[$oldlc]) : ' ' . $content->old[$oldlc]; + ?>type?> type == 'custom') echo "line-new"?> code'>new[$newlc])) $content->new[$newlc] = ''; + $content->new[$newlc] = $repo->SCM == 'Subversion' ? htmlspecialchars($content->new[$newlc]) : $content->new[$newlc]; + if(!empty($newlc)) echo $line->type != 'all' ? $content->new[$newlc] : ' ' . $content->new[$newlc]; + ?>
+
+ +
+ + + From 38c327927fe595b1ab5f272bbded1e620510949b Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 26 Aug 2021 05:49:38 +0000 Subject: [PATCH 082/154] * Adjust GitLab history log. --- module/gitlab/control.php | 78 +++++++++------------------------------ 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index e461559806..2d81bcf71f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -57,20 +57,9 @@ class gitlab extends control $this->checkToken(); $gitlabID = $this->gitlab->create(); - if(dao::isError()) - { - /* Save log. */ - $now = new datetime('now'); - $log = ''; - $time = $now->format('G:i:s'); - $output = "\n" . dao::isError(); - - $log = "$time Create Error output : $output\n"; - $this->logGitLab($log); - unset($log); - - return $this->send(array('result' => 'fail', 'message' => dao::getError())); - } + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->loadModel('action'); + $actionID = $this->action->create('gitlab', $gitlabID, 'create'); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -88,30 +77,24 @@ class gitlab extends control */ public function edit($id) { - $gitlab = $this->gitlab->getByID($id); + $oldGitLab = $this->gitlab->getByID($id); + if($_POST) { $this->checkToken(); $this->gitlab->update($id); - if(dao::isError()) - { - /* Save log. */ - $now = new datetime('now'); - $log = ''; - $time = $now->format('G:i:s'); - $output = "\n" . dao::isError(); + $gitLab = $this->gitlab->getByID($id); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - $log = "$time Edit output : $output\n"; - $this->gitlab->logGitLab($log); - unset($log); - - return $this->send(array('result' => 'fail', 'message' => dao::getError())); - } + $this->loadModel('action'); + $actionID = $this->action->create('gitlab', $id, 'edit'); + $changes = common::createChanges($oldGitLab, $gitLab); + $this->action->logHistory($actionID, $changes); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->edit; - $this->view->gitlab = $gitlab; + $this->view->gitlab = $oldGitLab; $this->display(); } @@ -204,20 +187,14 @@ class gitlab extends control { if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); + $oldGitLab = $this->gitlab->getByID($id); + $this->loadModel('action'); $this->gitlab->delete(TABLE_PIPELINE, $id); - if(dao::isError()) - { - /* Save log. */ - $now = new datetime('now'); - $log = ''; - $time = $now->format('G:i:s'); - $output = "\n" . dao::isError(); - - $log = "$time Delete output : $output\n"; - $this->gitlab->logGitLab($log); - unset($log); - } + $gitLab = $this->gitlab->getByID($id); + $actionID = $this->action->create('gitlab', $id, 'delete'); + $changes = common::createChanges($oldGitLab, $gitLab); + $this->action->logHistory($actionID, $changes); die(js::reload('parent')); } @@ -420,25 +397,6 @@ class gitlab extends control $this->send($options); } - /** - * Log GitLab. - * - * @param string $log - * @access public - * @return void - */ - public function logGitLab($log) - { - if(!is_writable($this->app->getLogRoot())) return false; - - $file = $this->app->getLogRoot() . 'GitLab.' . date('Ymd') . '.log.php'; - if(!is_file($file)) $log = " Date: Thu, 26 Aug 2021 14:20:52 +0800 Subject: [PATCH 083/154] * Finish view mr codes diff page. --- config/filter.php | 4 +++ module/mr/control.php | 50 ++++++++++++++++++++++++++++++++++-- module/mr/css/diff.css | 22 ++++++++++++++++ module/mr/lang/zh-cn.php | 19 +++++++------- module/mr/view/diff.html.php | 2 +- 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 module/mr/css/diff.css diff --git a/config/filter.php b/config/filter.php index 2b07fbc15f..0f42c2b707 100644 --- a/config/filter.php +++ b/config/filter.php @@ -58,6 +58,7 @@ $filter->git = new stdclass(); $filter->svn = new stdclass(); $filter->search = new stdclass(); $filter->gitlab = new stdclass(); +$filter->mr = new stdclass(); $filter->ci = new stdclass(); $filter->block->default = new stdclass(); @@ -136,6 +137,7 @@ $filter->repo->ajaxsynccommit = new stdclass(); $filter->search->index = new stdclass(); $filter->gitlab->webhook = new stdclass(); $filter->gitlab->importissue = new stdclass(); +$filter->mr->diff = new stdclass(); $filter->ci->checkCompileStatus = new stdclass(); $filter->bug->batchcreate->cookie['preBranch'] = 'int'; @@ -334,4 +336,6 @@ $filter->gitlab->importissue->get['product'] = 'string'; $filter->gitlab->importissue->get['project'] = 'int'; $filter->gitlab->importissue->get['repo'] = 'int'; +$filter->mr->diff->cookie['arrange'] = 'reg::word'; + $filter->ci->checkCompileStatus->get['gitlabOnly'] = 'string'; diff --git a/module/mr/control.php b/module/mr/control.php index 495b6d8b1a..bc04a5d209 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -17,6 +17,9 @@ class mr extends control $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); + /* Save current URI to session. */ + $this->session->set('mrList', $this->app->getURI(true), 'repo'); + $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; $this->view->MRList = $this->mr->getList($orderBy, $pager); $this->view->orderBy = $orderBy; @@ -167,10 +170,53 @@ class mr extends control $this->send($options); } + /** + * View diff between MR source and target branches. + * + * @param int $MRID + * @access public + * @return void + */ public function diff($MRID) { - $MR = $this->mr->getByID($MRID); - $this->view->diffs = $this->mr->getDiffs($MR); + $MR = $this->mr->getByID($MRID); + $diffs = $this->mr->getDiffs($MR); + $arrange = $this->cookie->arrange ? $this->cookie->arrange : 'inline'; + + if($this->server->request_method == 'POST') + { + if($this->post->arrange) + { + $arrange = $this->post->arrange; + setcookie('arrange', $arrange); + } + if($this->post->encoding) $encoding = $this->post->encoding; + } + + if($arrange == 'appose') + { + + foreach($diffs as $diffFile) + { + if(empty($diffFile->contents)) continue; + foreach($diffFile->contents as $content) + { + $old = array(); + $new = array(); + foreach($content->lines as $line) + { + if($line->type != 'new') $old[$line->oldlc] = $line->line; + if($line->type != 'old') $new[$line->newlc] = $line->line; + } + $content->old = $old; + $content->new = $new; + } + } + } + + $this->view->title = $this->lang->mr->showDiif; + $this->view->diffs = $diffs; + $this->view->arrange = $arrange; $this->display(); } } diff --git a/module/mr/css/diff.css b/module/mr/css/diff.css new file mode 100644 index 0000000000..5db97ecce4 --- /dev/null +++ b/module/mr/css/diff.css @@ -0,0 +1,22 @@ +body {padding-bottom: 0px;} +.w-code {width: 48%; word-break: break-all;} +td.code {color: #484848; padding: 0px 3px; white-space: pre-wrap;} +.none {background: #EAF2F5;} +table.diff {margin-bottom: 0px;} +.diff caption {border: 1px solid #e4e4e4; background: #edf3fe; margin: 0; padding: 6px 2px 6px 10px; text-align: left; font-weight: bold; font-size: 13px;} +.diff th, .diff td {border: none;} +.diff th {padding-top: 2px; padding-bottom: 2px;} +.diff .line-new, .diff .line-new {background: #CFC;} +.diff .line-old, .diff .line-old {background: #FCC;} +.diff .line-all, .diff .line-all {background: #FFF;} +.diff .w-num {width: 25px; border-right: 1px solid #E4E4E4; color: #999; border-left: 1px solid #E4E4E4; color: #999; font-weight: normal;} + +.repoCode .diff tr .comment-btn .icon-wrapper {left: -23px;} +.repoCode .diff tr.over td.line-all, .repoCode .diff tr.over td.line-all {background: #f8eec7;} +.repoCode .diff tr.over td.line-new, .repoCode .diff tr.over td.line-new {background: #8eff8e;} +.repoCode .diff tr.over td.line-old, .repoCode .diff tr.over td.line-old {background: #f6b2b2;} + +.repoCode form > .btn {margin-right: 10px;} +.label-exchange {background-color: #566F7C; cursor: pointer;} +.label-exchange i {padding: 0;} +.btn-download {border-right: none;} diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 5ae6e62d8a..f51db88611 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -1,13 +1,14 @@ mr->common = "合并请求"; -$lang->mr->create = "创建{$lang->mr->common}"; -$lang->mr->browse = "浏览{$lang->mr->common}"; -$lang->mr->list = $lang->mr->browse; -$lang->mr->edit = "编辑{$lang->mr->common}"; -$lang->mr->delete = "删除{$lang->mr->common}"; -$lang->mr->view = "{$lang->mr->common}详情"; -$lang->mr->source = '源项目分支'; -$lang->mr->target = '目标项目分支'; +$lang->mr->common = "合并请求"; +$lang->mr->create = "创建{$lang->mr->common}"; +$lang->mr->browse = "浏览{$lang->mr->common}"; +$lang->mr->list = $lang->mr->browse; +$lang->mr->edit = "编辑{$lang->mr->common}"; +$lang->mr->delete = "删除{$lang->mr->common}"; +$lang->mr->view = "{$lang->mr->common}详情"; +$lang->mr->source = '源项目分支'; +$lang->mr->target = '目标项目分支'; +$lang->mr->viewDiff = '查看Merge Request 改动'; $lang->mr->id = 'ID'; $lang->mr->mriid = "MR原始ID"; diff --git a/module/mr/view/diff.html.php b/module/mr/view/diff.html.php index 0c2d5e88bd..8844dcd5df 100644 --- a/module/mr/view/diff.html.php +++ b/module/mr/view/diff.html.php @@ -14,7 +14,7 @@ - +
From 0a88f13f16f168b67d5537324cbfcfeb79c76da6 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 16:46:47 +0800 Subject: [PATCH 086/154] - Delete list.html.php . --- module/mr/view/list.html.php | 46 ------------------------------------ 1 file changed, 46 deletions(-) delete mode 100644 module/mr/view/list.html.php diff --git a/module/mr/view/list.html.php b/module/mr/view/list.html.php deleted file mode 100644 index 36fdadf0e5..0000000000 --- a/module/mr/view/list.html.php +++ /dev/null @@ -1,46 +0,0 @@ - - -
-
- - - - recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> - - - - - - - - - - - - - - - - - - - - -
mr->id); ?>mr->name); ?>mr->sourceProject); ?>mr->targetProject); ?>mr->status); ?>actions; ?>
id; ?>createLink('mr', 'browse', "mrID={$mr->id}"), $mr->title);?>source_project_id . ":" . $mr->source_branch;?>target_project_id . ":" . $mr->target_branch;?>state;?> - id}", '', '', "title='{$lang->mr->list}' class='btn btn-info'"); - common::printLink('mr', 'create', "mr={$mr->id}", '', '', "title='{$lang->mr->create}' class='btn btn-info'"); - common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "mrID=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); - ?> -
- - - -
-
- From 2d6419c497fb594b24909cedbd1c25e7a8c0e15d Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 16:58:29 +0800 Subject: [PATCH 087/154] * Adjust style of pipeline status. --- module/mr/view/view.html.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index 7a2a42698c..b5f7c68ca4 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -27,13 +27,18 @@
mr->from . html::a($sourceProjectURL, $sourceProjectName . ":" . $MR->sourceBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'") . $lang->mr->to . html::a($targetProjectURL, $targetProjectName . ":" . $MR->targetBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'");?>
-
head_pipeline->status)) echo $lang->mr->pipeline . $lang->mr->status . ": " . zget($lang->mr->pipelineStatus, $rawMR->head_pipeline->status, $lang->mr->pipelineUnknown);?>
+ head_pipeline->status)):?> +
+ mr->pipeline}{$lang->mr->status}";?> + mr->pipelineStatus, $rawMR->head_pipeline->status, $lang->mr->pipelineUnknown);?> +
+ mr->mergeStatus;?> mr->mergeStatusList, $rawMR->merge_status);?>
- mr->MRHasConflicts. $lang->colon;?> + mr->MRHasConflicts;?> has_conflicts ? $lang->mr->hasConflicts : $lang->mr->hasNoConflict);?>
From ed95aa5dbd30b5267a93974b3aed69eff5f0353b Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:08:09 +0800 Subject: [PATCH 088/154] * Fix rignt spell error. --- module/mr/view/browse.html.php | 16 ++++++++++++++++ module/repo/view/maintain.html.php | 2 +- module/webhook/view/browse.html.php | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 4d1fe12c67..8efb8b258c 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -1,3 +1,13 @@ + diff --git a/module/webhook/view/browse.html.php b/module/webhook/view/browse.html.php index e6056a9bfe..94ff1a9b76 100644 --- a/module/webhook/view/browse.html.php +++ b/module/webhook/view/browse.html.php @@ -50,7 +50,7 @@ - +
From 567f80f171b9c9a8d9600f8d5863b8e7727cc7e2 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:40:03 +0800 Subject: [PATCH 089/154] * Fix ajaxGetMRTragetProjects and remove and Fix comments. --- module/mr/control.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index bc04a5d209..cf3cfe938d 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -69,10 +69,10 @@ class mr extends control $gitlabUsers = $this->gitlab->getUserAccountIdPairs($MR->gitlabID); + $this->view->title = $this->lang->mr->edit; $this->view->MR = $MR; $this->view->targetBranchList = $targetBranchList; - $this->view->title = $this->lang->mr->edit; - $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); /* Get user list for assignee and reviewer. */ + $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); $this->view->assignee = zget($gitlabUsers, $MR->assignee, ''); $this->view->reviewer = zget($gitlabUsers, $MR->reviewer, ''); @@ -124,7 +124,6 @@ class mr extends control $this->view->sourceProjectURL = $sourceBranch ->web_url; $this->view->targetProjectURL = $targetBranch ->web_url; - /* Those variables are used to render $lang->mr->commandDocument. */ $this->view->httpRepoURL = $sourceProject->http_url_to_repo; $this->view->branchPath = $sourceProject->path_with_namespace . '-' . $rawMR->source_branch; @@ -140,11 +139,13 @@ class mr extends control * @access public * @return void */ - public function ajaxGetMRTragetProjects($gitlabID, $projectID) + public function ajaxGetMRTargetProjects($gitlabID, $projectID) { $this->loadModel('gitlab'); + /* First step: get forks. */ $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); + /* Second step: get project itself. */ $projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); @@ -195,7 +196,6 @@ class mr extends control if($arrange == 'appose') { - foreach($diffs as $diffFile) { if(empty($diffFile->contents)) continue; @@ -214,7 +214,7 @@ class mr extends control } } - $this->view->title = $this->lang->mr->showDiif; + $this->view->title = $this->lang->mr->viewDiif; $this->view->diffs = $diffs; $this->view->arrange = $arrange; $this->display(); From 3110a903c35c34f90415946b2e6cab0057c73cdd Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:41:13 +0800 Subject: [PATCH 090/154] * Fix ajaxGetMRTragetProjects. --- module/mr/js/create.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/js/create.js b/module/mr/js/create.js index ae7c6decb1..98583c829e 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -41,7 +41,7 @@ $(function() $('#sourceProject').change(function() { sourceProject = $(this).val(); - projectUrl = createLink('mr', 'ajaxGetMRTragetProjects', "gitlabID=" + gitlabID + "&projectID=" + sourceProject); + projectUrl = createLink('mr', 'ajaxGetMRTargetProjects', "gitlabID=" + gitlabID + "&projectID=" + sourceProject); $.get(projectUrl, function(response) { $('#targetProject').html('').append(response); From cfd56b03f0e39832fc3eca5991326e7c87545d36 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:41:35 +0800 Subject: [PATCH 091/154] * Remove processMR function, Adjust api error message. --- module/mr/model.php | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 6b89bf1df1..1cba029e8f 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -57,29 +57,6 @@ class mrModel extends model return $MRList; } - /** - * Process MR info by api. Append extra attributes in GitLab. - * - * @param object $MR - * @access public - * @return object - */ - public function processMR($MR) - { - if(!isset($MR->gitlabID)) return $MR; - - $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - - $MR->name = $rawMR->title; - $MR->sourceProject = $rawMR->source_project_id; - $MR->sourceBranch = $rawMR->source_branch; - $MR->targetProject = $rawMR->target_project_id; - $MR->targetBranch = $rawMR->target_branch; - $MR->mergeStatus = $rawMR->merge_status; - $MR->status = $rawMR->state; - return $MR; - } - /** * Get gitlab pairs. * @@ -132,7 +109,7 @@ class mrModel extends model if(isset($rawMR->message) and !isset($rawMR->iid)) { $this->dao->delete()->from(TABLE_MR)->where('id')->eq($MRID)->exec(); - return array('result' => 'fail', 'message' => $rawMR->message); + return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->createMR, $rawMR->message)); } /* Create MR failed. */ @@ -242,6 +219,7 @@ class mrModel extends model ->where('id')->eq($MR->id) ->exec(); } + return $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch(); } /** From 03b9fd39825262675c88367661df17d55bd5e168 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:43:10 +0800 Subject: [PATCH 092/154] * Add apiError->createMR lang item. --- module/mr/lang/zh-cn.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index d6001b2136..0498e9afd2 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -42,6 +42,9 @@ $lang->mr->targetBranch = '目标分支'; $lang->mr->usersTips = '提示:如果无法选择指派人和评审人,请先前往GitLab页面绑定用户。'; $lang->mr->notFound = "此{$lang->mr->common}不存在。"; +$lang->mr->apiError = new stdclass; +$lang->mr->apiError->createMR = "通过API创建合并请求失败,失败原因:%s"; + $lang->mr->createFailedFromAPI = "创建合并请求失败。"; $lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; From 1160e1eba721370c26298a965be7c3eba25bed17 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:44:06 +0800 Subject: [PATCH 093/154] * Use common::printLink and remove extra comments. --- module/mr/view/browse.html.php | 40 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 8efb8b258c..37c6f1dab6 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -3,7 +3,7 @@ * The view file for browse page of mr module of ZenTaoPMS. * * @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com) - * @author Wang Yidong, Zhu Jinyong + * @author Guodong Ding * @package mr * @version $Id: create.html.php $ */ @@ -11,7 +11,7 @@
@@ -42,38 +42,30 @@ - + - id; ?> - title; ?> - loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->sourceProject)->name_with_namespace; ?> - sourceBranch;?> - loadModel('gitlab')->apiGetSingleProject($mr->gitlabID, $mr->targetProject)->name_with_namespace; ?> - targetBranch;?> - mr->statusList, $mr->status);?> - mr->mergeStatusList, $mr->mergeStatus);?> + id; ?> + title; ?> + loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject)->name_with_namespace; ?> + sourceBranch;?> + loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject)->name_with_namespace; ?> + targetBranch;?> + mr->statusList, $MR->status);?> + mr->mergeStatusList, $MR->mergeStatus);?> id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); - common::printLink('mr', 'edit', "mrID=$mr->id", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - common::printLink('mr', 'diff', "mr={$mr->id}", '', '', "title='{$lang->mr->diff}' class='btn btn-info'"); - if(common::hasPriv('mr', 'delete')) echo html::a($this->createLink('mr', 'delete', "id=$mr->id"), '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn'"); + common::printLink('mr', 'view', "mr={$MR->id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); + common::printLink('mr', 'edit', "mr={$MR->id}", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); + common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->diff}' class='btn btn-info'"); + common::printLink('mr', 'delete', "mr={$MR->id}", '', '', "title='{$lang->mr->delete}' class='btn btn-info'"); ?> - - - +
-/** - * - */ -/** - * - */ From 8c32895ad801b05cb7190236d4d4e3cea27589c0 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:44:44 +0800 Subject: [PATCH 094/154] * Fix comments. --- module/mr/view/create.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 2ffc1dd4a4..3a745ff6e9 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -3,7 +3,7 @@ * The create view file of mr module of ZenTaoPMS. * * @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com) - * @author Wang Yidong, Zhu Jinyong + * @author Guodong * @package mr * @version $Id: create.html.php $ */ From 0a56e0100e03e12ee9671eb0e7b6f72bb80b48b3 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 26 Aug 2021 17:45:16 +0800 Subject: [PATCH 095/154] * Fix comments. --- module/mr/view/diff.html.php | 2 +- module/mr/view/edit.html.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/mr/view/diff.html.php b/module/mr/view/diff.html.php index 8844dcd5df..a4ff5ab6f9 100644 --- a/module/mr/view/diff.html.php +++ b/module/mr/view/diff.html.php @@ -3,7 +3,7 @@ * The diff view file of repo module of ZenTaoPMS. * * @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com) - * @author Wang Yidong, Zhu Jinyong + * @author Xiying Guan * @package repo * @version $Id: browse.html.php $ */ diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index 582c1eb440..c167084c52 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -1,6 +1,6 @@ Date: Fri, 27 Aug 2021 07:36:48 +0000 Subject: [PATCH 096/154] * Add GitLab view template and control view function. --- module/gitlab/control.php | 18 ++++++++++++++++++ module/gitlab/lang/zh-cn.php | 1 + 2 files changed, 19 insertions(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 2d81bcf71f..7646ce74b2 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -68,6 +68,24 @@ class gitlab extends control $this->display(); } + /** + * view a gitlab. + * @param int $id + * @access public + * @return void + */ + public function view($id) + { + $gitlab = $this->gitlab->getByID($id); + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->view; + $this->view->gitlab = $gitlab; + $this->view->users = $this->loadModel('user')->getPairs('noclosed'); + $this->view->actions = $this->loadModel('action')->getList('gitlab', $id); + $this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('pipeline', $id); + $this->display(); + } + /** * Edit a gitlab. * diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index f565ee11df..9467979803 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -4,6 +4,7 @@ $lang->gitlab->common = 'GitLab'; $lang->gitlab->browse = '浏览GitLab'; $lang->gitlab->create = '添加GitLab'; $lang->gitlab->edit = '编辑GitLab'; +$lang->gitlab->view = '查看GitLab'; $lang->gitlab->bindUser = '绑定用户'; $lang->gitlab->webhook = 'webhook'; $lang->gitlab->bindProduct = '关联产品'; From 2b03f84fe4c87e0d77fc3229408dcd70a7f9c555 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 27 Aug 2021 08:10:04 +0000 Subject: [PATCH 097/154] * Adjust GitLab browse template. --- module/gitlab/view/browse.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index d4e475952a..a7498c50cf 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -42,7 +42,7 @@ $gitlab): ?> - name;?> + ">name;?> url;?> Date: Fri, 27 Aug 2021 17:37:28 +0800 Subject: [PATCH 098/154] * Fix bug when creating a repo without gitlabProject. --- module/repo/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/repo/model.php b/module/repo/model.php index b9609b7fe5..b6887955db 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -224,7 +224,7 @@ class repoModel extends model if($data->encrypt == 'base64') $data->password = base64_encode($data->password); $this->dao->insert(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject') ->batchCheck($this->config->repo->create->requiredFields, 'notempty') - ->checkIF($data->SCM == 'GitLab', 'gitlabProject', 'notempty') + ->checkIF($data->SCM == 'Gitlab', 'gitlabProject', 'notempty') ->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty') ->autoCheck() ->exec(); @@ -282,7 +282,7 @@ class repoModel extends model $this->dao->update(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject') ->batchCheck($this->config->repo->edit->requiredFields, 'notempty') ->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty') - ->checkIF($data->SCM == 'GitLab', 'extra', 'notempty') + ->checkIF($data->SCM == 'Gitlab', 'extra', 'notempty') ->autoCheck() ->where('id')->eq($id)->exec(); From 8f4cfb67da9f735d6a96c0a6e44884a2f0d26aa3 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 30 Aug 2021 06:52:02 +0000 Subject: [PATCH 099/154] * Add Sync MR from GitLab API to Zentao database, default time 5 minutes to execute once. --- db/update15.3.sql | 3 +++ module/install/lang/zh-cn.php | 1 + module/mr/control.php | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/db/update15.3.sql b/db/update15.3.sql index 743ccea4e4..6b8dd5c83c 100644 --- a/db/update15.3.sql +++ b/db/update15.3.sql @@ -1 +1,4 @@ ALTER TABLE `zt_testtask` ADD `realFinishedDate` datetime NOT NULL AFTER `end`; + +INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES +('*/5', '*', '*', '*', '*', 'moduleName=mr&methodName=syncMR', '定时同步GitLab合并数据到禅道数据库', 'zentao', 1, 'normal', '0000-00-00 00:00:00'); diff --git a/module/install/lang/zh-cn.php b/module/install/lang/zh-cn.php index 988abbab0d..3e056fff4a 100644 --- a/module/install/lang/zh-cn.php +++ b/module/install/lang/zh-cn.php @@ -169,6 +169,7 @@ $lang->install->cronList['moduleName=todo&methodName=createCycle'] = '生 $lang->install->cronList['moduleName=ci&methodName=initQueue'] = '创建周期性任务'; $lang->install->cronList['moduleName=ci&methodName=checkCompileStatus'] = '同步Jenkins任务状态'; $lang->install->cronList['moduleName=ci&methodName=exec'] = '执行Jenkins任务'; +$lang->install->cronList['moduleName=mr&methodName=syncMR'] = '定时同步GitLabMR信息'; $lang->install->success = "安装成功"; $lang->install->login = '登录禅道管理系统'; diff --git a/module/mr/control.php b/module/mr/control.php index cf3cfe938d..5acb340fa0 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -131,6 +131,25 @@ class mr extends control $this->display(); } + /** + * Crontab sync MR from GitLab API to Zentao database, default time 5 minutes to execute once. + * + * @access public + * @return void + */ + public function syncMR() + { + $this->mr->getList(); + + if(dao::isError()) + { + echo json_encode(dao::getError()); + return true; + } + + echo 'success'; + } + /** * AJAX: Get MR target projects. * From 95ea397519b4297d8c1731c3c2b70245bddaabf5 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 30 Aug 2021 06:55:05 +0000 Subject: [PATCH 100/154] * Add GitLab view html. --- module/gitlab/view/view.html.php | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 module/gitlab/view/view.html.php diff --git a/module/gitlab/view/view.html.php b/module/gitlab/view/view.html.php new file mode 100644 index 0000000000..091389733c --- /dev/null +++ b/module/gitlab/view/view.html.php @@ -0,0 +1,54 @@ + + * @package GitLab + * @version $Id: view.html.php 4728 2013-05-03 06:14:34Z david18810279601@gmail.com $ + * @link http://www.zentao.net + * */ +?> + + +session->gitlabList ? $app->session->gitlabList : inlink('browse');?> + +
+
+ printExtendFields($gitlab, 'div', "position=left&inForm=0&inCell=1");?> +
+ id"; + ?> +
+
+ + deleted):?> +
+ + +
+
+
+
+ +
+ +
+ + + From 99fdb293270306b3f0b1d188d4d0bf94b1ab44fa Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 30 Aug 2021 07:04:48 +0000 Subject: [PATCH 101/154] * Adjust GitLab view html. --- module/gitlab/view/view.html.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/module/gitlab/view/view.html.php b/module/gitlab/view/view.html.php index 091389733c..30fc445968 100644 --- a/module/gitlab/view/view.html.php +++ b/module/gitlab/view/view.html.php @@ -12,13 +12,8 @@ ?> -session->gitlabList ? $app->session->gitlabList : inlink('browse');?>
+
+ state == 'opened' and !$rawMR->has_conflicts) echo html::linkButton(' ' . $lang->mr->acceptMR, inlink( 'accept', "mr=$MR->id"), 'self', '', 'btn btn-wide btn-primary');?> From b2f1fd3f3cdba385403bf8ddd3f7005387d4838a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 31 Aug 2021 11:05:03 +0800 Subject: [PATCH 105/154] + Accept a MR. --- module/mr/control.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/module/mr/control.php b/module/mr/control.php index 5acb340fa0..a3f9ee28fb 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -132,6 +132,7 @@ class mr extends control } /** +<<<<<<< HEAD * Crontab sync MR from GitLab API to Zentao database, default time 5 minutes to execute once. * * @access public @@ -150,6 +151,20 @@ class mr extends control echo 'success'; } + /** Accept a MR. + * + * @param int $MRID + * @access public + * @return void + */ + public function accept($MRID) + { + $MR = $this->mr->getByID($MRID); + if(isset($MR->gitlabID)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + if(isset($rawMR->state) and $rawMR->state == 'merged') return array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess); + return array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed); + } + /** * AJAX: Get MR target projects. * From 95c2adad703f2ca0f08f00104b8b2943b824e210 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 31 Aug 2021 10:57:17 +0800 Subject: [PATCH 106/154] * Correct apiAcceptMR and update functions. --- module/mr/model.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 1cba029e8f..bdb58b44dc 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -153,15 +153,16 @@ class mrModel extends model /* Update MR in GitLab. */ $newMR = new stdclass; - $newMR->title = $MR->title; - $newMR->description = $MR->description; - $newMR->assignee = $MR->assignee; - $newMR->reviewer = $MR->reviewer; - $newMR->targetBranch = $MR->targetBranch; + $newMR->title = $MR->title; + $newMR->description = $MR->description; + $newMR->assignee_ids = $MR->assignee; + $newMR->reviewer_ids = $MR->reviewer; + $newMR->target_branch = $MR->targetBranch; $oldMR = $this->getByID($MRID); - $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR); + /* Known issue: `reviewer_ids` takes no effect. */ + $rawMR = $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR); /* Change gitlab user ID to zentao account. */ $gitlabUsers = $this->gitlab->getUserIdAccountPairs($oldMR->gitlabID); @@ -173,6 +174,7 @@ class mrModel extends model ->where('id')->eq($MRID) ->autoCheck() ->exec(); + $MR = $this->getByID($MRID); if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); @@ -314,8 +316,8 @@ class mrModel extends model */ public function apiAcceptMR($gitlabID, $projectID, $MRID) { - $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID"); - return json_decode(commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/merge"); + return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** From 1632859fafb9aef5299a7c91d6471929a320ff09 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 31 Aug 2021 11:01:29 +0800 Subject: [PATCH 107/154] * Update MR view and lang. --- module/mr/lang/zh-cn.php | 8 ++++++-- module/mr/view/view.html.php | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 0498e9afd2..9a83adbd96 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -30,7 +30,7 @@ $lang->mr->statusList['merged'] = '已合并'; $lang->mr->mergeStatusList = array(); $lang->mr->mergeStatusList['checking'] = '检查中'; $lang->mr->mergeStatusList['can_be_merged'] = '可合并'; -$lang->mr->mergeStatusList['cannot_be_merged'] = '不可合并'; +$lang->mr->mergeStatusList['cannot_be_merged'] = '不可自动合并'; $lang->mr->description = '描述'; $lang->mr->confirmDelete = '确认删除该合并请求吗?'; @@ -68,6 +68,10 @@ $lang->mr->hasConflicts = "存在合并冲突"; $lang->mr->hasNoConflict = "可以合并请求"; $lang->mr->mergeByManual = "此合并请求可以手动合并,请使用以下"; $lang->mr->commandLine = "合并命令"; +$lang->mr->acceptMR = "合并"; +$lang->mr->mergeFailed = "无法合并,请核对合并请求状态"; +$lang->mr->mergeSuccess = "已成功合并"; + /** * Merge Command Document. @@ -80,7 +84,7 @@ $lang->mr->commandLine = "合并命令"; * %s mr::target_branch */ $lang->mr->commandDocument = <<< EOD -
在本地检出、审核和合并
+
在本地检出、审核和手动合并

第 1 步. 获取并查看此合并请求的分支 diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index b5f7c68ca4..89cada7c09 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -29,6 +29,9 @@

mr->from . html::a($sourceProjectURL, $sourceProjectName . ":" . $MR->sourceBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'") . $lang->mr->to . html::a($targetProjectURL, $targetProjectName . ":" . $MR->targetBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'");?>
+ mr->status;?> + mr->statusList, $MR->status);?> +
head_pipeline->status)):?>
mr->pipeline}{$lang->mr->status}";?> @@ -51,8 +54,12 @@
+ state == 'opened'):?>
mr->commandDocument, $httpRepoURL, $MR->sourceBranch, $branchPath, $MR->targetBranch, $branchPath, $MR->targetBranch);?>
+
+
+ state == 'opened' and !$rawMR->has_conflicts) echo html::linkButton(' ' . $lang->mr->acceptMR, inlink( 'accept', "mr=$MR->id"), 'self', '', 'btn btn-wide btn-primary');?> From 33b287b4279b5fba6a02110b6c0be9f2d8082862 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 31 Aug 2021 11:10:50 +0800 Subject: [PATCH 108/154] - Remove extra lines which should be deleted. --- module/mr/control.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 40198033cf..dd90d86d04 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -132,8 +132,6 @@ class mr extends control } /** -<<<<<<< HEAD -<<<<<<< HEAD * Crontab sync MR from GitLab API to Zentao database, default time 5 minutes to execute once. * * @access public From 761c5d282e01964bbbb279dd0989811e72c827fb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 09:40:46 +0800 Subject: [PATCH 109/154] * Fix bug when getting gitlab projects list. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 087fadabc5..aa8cc892df 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -448,9 +448,9 @@ class gitlabModel extends model $allResults = array(); for($page = 1; true; $page ++) { - $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100")); + $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100")); if(empty($results) or $page > 10) break; - $allResults = $allResults + $results; + $allResults = array_merge($allResults, $results); } return $allResults; From 3209790874beb0d2746b21a539031416670a8259 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 10:28:06 +0800 Subject: [PATCH 110/154] + Add apiGetProjectUsers function. --- module/gitlab/model.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 087fadabc5..1ebc19862a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -470,6 +470,20 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + /** + * Get project users. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function apiGetProjectUsers($gitlabID, $projectID) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/users"); + return json_decode(commonModel::http($url)); + } + /** * Get single branch by API. * From e6799383792bf059ae373c27f8321dee5d0303d2 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 10:29:03 +0800 Subject: [PATCH 111/154] * Update ajaxGetMRUserPairs function. --- module/gitlab/control.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 7646ce74b2..dd06f754eb 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -417,16 +417,25 @@ class gitlab extends control /** * AJAX: Get MR user pairs to select assignee_ids and reviewer_ids. + * Attention: The user must be a member of the GitLab project. * * @param int $gitlabID + * @param int $projectID * @access public * @return void */ - public function ajaxGetMRUserPairs($gitlabID) + public function ajaxGetMRUserPairs($gitlabID, $projectID) { if(!$gitlabID) return $this->send(array('message' => array())); - $users = $this->gitlab->getUserIdRealnamePairs($gitlabID); + $bindedUsers = $this->gitlab->getUserIdRealnamePairs($gitlabID); + $rawProjectUsers = $this->gitlab->apiGetProjectUsers($gitlabID, $projectID); + $users = array(); + foreach($rawProjectUsers as $rawProjectUser) + { + if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id]; + } + $options = ""; foreach($users as $index => $user) { From 5ebad79a991cced602a1b80240e46fec42abc01d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 10:33:55 +0800 Subject: [PATCH 112/154] * Fix bug when getting gitlab projects list. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1ebc19862a..1a87c51110 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -448,9 +448,9 @@ class gitlabModel extends model $allResults = array(); for($page = 1; true; $page ++) { - $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100")); + $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100")); if(empty($results) or $page > 10) break; - $allResults = $allResults + $results; + $allResults = array_merge($allResults, $results); } return $allResults; From 8b17a74a1ccce29dc68b04da49043a6d276fc6a2 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 10:36:02 +0800 Subject: [PATCH 113/154] * Update fetching users list when creating a MR. --- module/mr/js/create.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/module/mr/js/create.js b/module/mr/js/create.js index 98583c829e..2194a15d88 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -11,19 +11,7 @@ $(function() $('#sourceProject').html('').append(response); $('#sourceProject').chosen().trigger("chosen:updated");; }); - - var assignee = $("#assignee").parents('td').find('select[name*=assignee]'); - var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]'); - usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID); - $.get(usersUrl, function(response) - { - assignee.html('').append(response); - assignee.chosen().trigger("chosen:updated");; - reviewer.html('').append(response); - reviewer.chosen().trigger("chosen:updated");; - }); - - }); + }); $('#sourceProject,#targetProject').change(function() { @@ -48,4 +36,21 @@ $(function() $('#targetProject').chosen().trigger("chosen:updated");; }); }); + + $('#targetProject').change(function() + { + targetProject = $(this).val(); + var assignee = $("#assignee").parents('td').find('select[name*=assignee]'); + var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]'); + usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID + "&projectID=" + targetProject); + $.get(usersUrl, function(response) + { + assignee.html('').append(response); + assignee.chosen().trigger("chosen:updated");; + reviewer.html('').append(response); + reviewer.chosen().trigger("chosen:updated");; + }); + }); + + }); From ff83efb0666cbc320709f029e8d2d841df56005e Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 1 Sep 2021 10:57:07 +0800 Subject: [PATCH 114/154] * Add manage reference of gitlab job function. --- module/job/control.php | 17 +++++++++++++++++ module/job/js/create.js | 22 ++++++++++++++++++++-- module/job/js/edit.js | 21 +++++++++++++++++++++ module/job/model.php | 29 +++++++++++++++++++++-------- module/job/view/create.html.php | 5 +++-- module/job/view/edit.html.php | 3 ++- 6 files changed, 84 insertions(+), 13 deletions(-) diff --git a/module/job/control.php b/module/job/control.php index 17d166f5d6..a44519e0cb 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -161,6 +161,8 @@ class job extends control $repo = $this->loadModel('repo')->getRepoByID($job->repo); $this->view->repo = $this->loadModel('repo')->getRepoByID($job->repo); + if($repo->SCM == 'Gitlab') $this->view->refList = $this->loadModel('gitlab')->getRefOptions($repo->gitlab, $repo->project); + $repoList = $this->repo->getList($this->projectID); $repoPairs = array(0 => '', $repo->id => $repo->name); $gitlabRepos = array(0 => ''); @@ -375,4 +377,19 @@ class job extends control $productName = $this->loadModel('product')->getByID($repo->product)->name; die(json_encode(array($productName => $repo->product))); } + + /** + * Ajax get reference list function. + * + * @param int $repoID + * @access public + * @return void + */ + public function ajaxGetRefList($repoID) + { + $repo = $this->loadModel('repo')->getRepoByID($repoID); + if($repo->SCM != 'Gitlab') $this->send(array('result' => 'fail')); + $refList = $this->loadModel('gitlab')->getRefOptions($repo->gitlab, $repo->project); + $this->send(array('result' => 'success', 'refList' => $refList)); + } } diff --git a/module/job/js/create.js b/module/job/js/create.js index cbe8c58a18..18b121ba44 100644 --- a/module/job/js/create.js +++ b/module/job/js/create.js @@ -129,19 +129,37 @@ $(document).ready(function() if($(this).val() == 'gitlab') { - $('#triggerType').find('[value=schedule]').remove(); $('tr.gitlabRepo').show(); $('tr.commonRepo').hide(); } else if($('#triggerType').find('[value=schedule]').size() == 0 ) { - $('#triggerType').append(scheduleOption); $('tr.gitlabRepo').hide(); $('tr.commonRepo').show(); } }); $('#engine').change(); + $('#gitlabRepo').change(function() + { + $('#reference option').remove(); + + var repoID = $(this).val(); + if(repoID > 0) + { + $.getJSON(createLink('job', 'ajaxGetRefList', "repoID=" + repoID), function(response) + { + if(response.result == 'success') + { + $.each(response.refList, function(reference, name) + { + $('#reference').append(""); + }); + } + $('#reference').trigger('chosen:updated'); + }); + } + }); $('#triggerType').change(); }); diff --git a/module/job/js/edit.js b/module/job/js/edit.js index 2b76c48b1c..f91c2aef1b 100644 --- a/module/job/js/edit.js +++ b/module/job/js/edit.js @@ -146,6 +146,27 @@ $(document).ready(function() } }); + $('#gitlabRepo').change(function() + { + $('#reference option').remove(); + + var repoID = $(this).val(); + if(repoID > 0) + { + $.getJSON(createLink('job', 'ajaxGetRefList', "repoID=" + repoID), function(response) + { + if(response.result == 'success') + { + $.each(response.refList, function(reference, name) + { + $('#reference').append(""); + }); + } + $('#reference').trigger('chosen:updated'); + }); + } + }); + $('#engine').change(); $('#jkServer').change(); diff --git a/module/job/model.php b/module/job/model.php index 1bbcf23110..73afdf517b 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -20,7 +20,14 @@ class jobModel extends model */ public function getByID($id) { - return $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($id)->fetch(); + $job = $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($id)->fetch(); + if(strtolower($job->engine) == 'gitlab') + { + $pipeline = json_decode($job->pipeline); + $job->project = $pipeline->project; + $job->reference = $pipeline->reference; + } + return $job; } /** @@ -117,7 +124,7 @@ class jobModel extends model ->setDefault('atDay', '') ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) - ->remove('repoType') + ->remove('repoType,reference') ->get(); if($job->engine == 'jenkins') @@ -128,10 +135,12 @@ class jobModel extends model if(strtolower($job->engine) == 'gitlab') { + $repo = $this->loadModel('repo')->getRepoByID($job->gitlabRepo); + $project = zget($repo, 'project'); + $job->repo = $job->gitlabRepo; - $repo = $this->loadModel('repo')->getRepoByID($job->repo); $job->server = (int)zget($repo, 'gitlab', 0); - $job->pipeline = zget($repo, 'project', ''); + $job->pipeline = json_encode(array('project' => $project, 'reference' => $this->post->reference)); } unset($job->jkServer); @@ -203,7 +212,7 @@ class jobModel extends model ->setIF($this->post->triggerType != 'tag', 'lastTag', '') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) - ->remove('repoType') + ->remove('repoType,reference') ->get(); if($job->engine == 'jenkins') @@ -214,10 +223,12 @@ class jobModel extends model if(strtolower($job->engine) == 'gitlab') { + $repo = $this->loadModel('repo')->getRepoByID($job->gitlabRepo); + $project = zget($repo, 'project'); + $job->repo = $job->gitlabRepo; - $repo = $this->loadModel('repo')->getRepoByID($job->repo); $job->server = (int)zget($repo, 'gitlab', 0); - $job->pipeline = zget($repo, 'project', ''); + $job->pipeline = json_encode(array('project' => $project, 'reference' => $this->post->reference)); } unset($job->jkServer); @@ -252,6 +263,7 @@ class jobModel extends model if(!empty($paramName)) $customParam[$paramName] = $paramValue; } + unset($job->paramName); unset($job->paramValue); unset($job->custom); @@ -407,7 +419,8 @@ class jobModel extends model } elseif($job->engine == 'gitlab' and $reference) { - $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $job->pipeline, $reference); + list($gitlabProject, $gitlabReference) = json_decode($job->pipeline); + $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $gitlabProject, $gitlabReference); if(empty($pipeline->id)) { $compile->status = 'create_fail'; diff --git a/module/job/view/create.html.php b/module/job/view/create.html.php index e7e0090ab5..69714f9eaf 100644 --- a/module/job/view/create.html.php +++ b/module/job/view/create.html.php @@ -48,7 +48,8 @@ job->repo; ?> - + + job->product; ?> @@ -95,7 +96,7 @@
- job->pipeline; ?> + job->pipeline;?> ''), '', "class='form-control chosen'"); ?>
diff --git a/module/job/view/edit.html.php b/module/job/view/edit.html.php index 3d0894484b..9c06425b7a 100644 --- a/module/job/view/edit.html.php +++ b/module/job/view/edit.html.php @@ -43,7 +43,8 @@ job->repo; ?> - repo, "class='form-control'"); ?> + repo, "class='chosen form-control'");?> + reference, "class='chosen form-control'");?> job->product;?> From 5e5cbe2d2fafe6e1ab4861df4eebf54141129208 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 1 Sep 2021 11:08:34 +0800 Subject: [PATCH 115/154] * Update and correct editing a MR. --- module/mr/control.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index dd90d86d04..ba743b6ba6 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -67,12 +67,21 @@ class mr extends control $targetBranchList = array(); foreach($branchList as $branch) $targetBranchList[$branch] = $branch; + /* Fetch user list both in Zentao and current GitLab project. */ + $bindedUsers = $this->gitlab->getUserIdRealnamePairs($MR->gitlabID); + $rawProjectUsers = $this->gitlab->apiGetProjectUsers($MR->gitlabID, $MR->targetProject); + $users = array(); + foreach($rawProjectUsers as $rawProjectUser) + { + if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id]; + } + $gitlabUsers = $this->gitlab->getUserAccountIdPairs($MR->gitlabID); $this->view->title = $this->lang->mr->edit; $this->view->MR = $MR; $this->view->targetBranchList = $targetBranchList; - $this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID); + $this->view->users = array("" => "") + $users; $this->view->assignee = zget($gitlabUsers, $MR->assignee, ''); $this->view->reviewer = zget($gitlabUsers, $MR->reviewer, ''); From 7f71a63468447dfbcfbbcd87001ebd706193abaa Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 1 Sep 2021 07:02:17 +0000 Subject: [PATCH 116/154] * Sync GitLab Todo ZenTao Todo. --- module/mr/model.php | 71 ++++++++++++++++++++++++++++++++++++++ module/todo/lang/zh-cn.php | 13 +++---- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 1cba029e8f..20f3b4bb7d 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -218,10 +218,81 @@ class mrModel extends model $this->dao->update(TABLE_MR)->data($newMR) ->where('id')->eq($MR->id) ->exec(); + + /*Sync GitLab Todo ZenTao Todo. */ + + $gitlabTodoList = $this->apiTodoList($MR->gitlabID, $MR->targetProject); + if($gitlabTodoList) + { + foreach($gitlabTodoList as $do) + { + $todoDesc = $this->dao->select('*') + ->from(TABLE_TODO) + ->where('idvalue') + ->eq($do->id) + ->fetch(); + if(empty($todoDesc)) + { + $todo = new stdClass; + $todo->account = $this->app->user->account; + $todo->assignedTo = $this->app->user->account; + $todo->assignedBy = $this->app->user->account; + $todo->date = $do->target->created_at; + $todo->assignedDate = $do->target->created_at; + $todo->begin = $do->target->created_at; + $todo->end = ''; + $todo->type = 'mrapprove'; + $todo->idvalue = $do->id; + $todo->pri = 1; + $todo->name = $do->target->title; + $todo->desc = $do->target->description . "
" . $this->todoDescriptionLink($MR->gitlabID, $MR->targetProject); + $todo->private = 0; + $todo->config = 0; + $todo->finishedBy = ''; + $todo->finishedDate = ''; + $todo->closedBy = ''; + $todo->closedDate = '0000-00-00 00:00:00'; + $this->dao->insert(TABLE_TODO)->data($todo)->exec(); + } + } + } } return $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch(); } + /** + * Get a list of to-do items. + * + * @docs https://docs.gitlab.com/ee/api/todos.html + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiTodoList($gitlabID, $projectID) + { + $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); + if(!$gitlab) return ''; + $url = rtrim($gitlab->url, '/')."/api/v4/todos?project_id=$projectID&type=MergeRequest&private_token={$gitlab->token}"; + return json_decode(commonModel::http($url)); + } + + /** + * Get a list of to-do items. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function todoDescriptionLink($gitlabID, $projectID) + { + $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); + if(!$gitlab) return ''; + return rtrim($gitlab->url, '/')."/dashboard/todos?project_id=$projectID&type=MergeRequest"; + } + + /** * Create MR by API. * diff --git a/module/todo/lang/zh-cn.php b/module/todo/lang/zh-cn.php index 18cfc39a1b..697ffa97c1 100644 --- a/module/todo/lang/zh-cn.php +++ b/module/todo/lang/zh-cn.php @@ -93,12 +93,13 @@ $lang->todo->priList[2] = 2; $lang->todo->priList[3] = 3; $lang->todo->priList[4] = 4; -$lang->todo->typeList['custom'] = '自定义'; -$lang->todo->typeList['cycle'] = '周期'; -$lang->todo->typeList['bug'] = 'Bug'; -$lang->todo->typeList['task'] = '任务'; -$lang->todo->typeList['story'] = $lang->SRCommon; -$lang->todo->typeList['testtask'] = '测试单'; +$lang->todo->typeList['custom'] = '自定义'; +$lang->todo->typeList['cycle'] = '周期'; +$lang->todo->typeList['bug'] = 'Bug'; +$lang->todo->typeList['task'] = '任务'; +$lang->todo->typeList['story'] = $lang->SRCommon; +$lang->todo->typeList['testtask'] = '测试单'; +$lang->todo->typeList['mrapprove'] = '合并请求审批'; $lang->todo->confirmDelete = "您确定要删除这条待办吗?"; $lang->todo->thisIsPrivate = '这是一条私人事务。:)'; From db552dc4287b72f664c1eff66ad752e9a14db63a Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 2 Sep 2021 06:13:18 +0000 Subject: [PATCH 117/154] * Adjust sync gitlab mr code. --- module/gitlab/model.php | 17 ++++++ module/mr/config.php | 17 +++--- module/mr/control.php | 11 +++- module/mr/model.php | 131 +++++++++++++++++++++++++--------------- 4 files changed, 117 insertions(+), 59 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1a87c51110..2d25db6f52 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -387,6 +387,23 @@ class gitlabModel extends model return json_decode(commonModel::http($url, $data, $options)); } + /** + * Get a list of to-do items. + * + * @see https://docs.gitlab.com/ee/api/todos.html + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiTodoList($gitlabID, $projectID) + { + $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); + if(!$gitlab) return ''; + $url = rtrim($gitlab->url, '/')."/api/v4/todos?project_id=$projectID&type=MergeRequest&private_token={$gitlab->token}"; + return json_decode(commonModel::http($url)); + } + /** * Get current user. * diff --git a/module/mr/config.php b/module/mr/config.php index 35fdbbcb4a..c64305044e 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -6,11 +6,14 @@ $config->MR->create->skippedFields = 'projectID'; $config->MR->maps = new stdclass; $config->MR->maps->sync = array(); -$config->MR->maps->sync['title'] = 'title|field|'; -$config->MR->maps->sync['description'] = 'description|field|'; -$config->MR->maps->sync['assignee'] = 'assignees|userPairs|id'; -$config->MR->maps->sync['reviewer'] = 'reviewers|userPairs|id'; -$config->MR->maps->sync['targetBranch'] = 'target_branch|field|'; -$config->MR->maps->sync['status'] = 'state|field|'; -$config->MR->maps->sync['mergeStatus'] = 'merge_status|field|'; +$config->MR->maps->sync['title'] = 'title|field|'; +$config->MR->maps->sync['description'] = 'description|field|'; +$config->MR->maps->sync['assignee'] = 'assignees|userPairs|id'; +$config->MR->maps->sync['reviewer'] = 'reviewers|userPairs|id'; +$config->MR->maps->sync['targetBranch'] = 'target_branch|field|'; +$config->MR->maps->sync['sourceBranch'] = 'source_branch|field|'; +$config->MR->maps->sync['sourceProject'] = 'source_project_id|field|'; +$config->MR->maps->sync['targetProject'] = 'target_project_id|field|'; +$config->MR->maps->sync['status'] = 'state|field|'; +$config->MR->maps->sync['mergeStatus'] = 'merge_status|field|'; diff --git a/module/mr/control.php b/module/mr/control.php index ba743b6ba6..4c9450be56 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -15,13 +15,17 @@ class mr extends control public function browse($objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $this->app->loadClass('pager', $static = true); - $pager = new pager($recTotal, $recPerPage, $pageID); + $pager = new pager($recTotal, $recPerPage, $pageID); + $MRList = $this->mr->getList($orderBy, $pager); /* Save current URI to session. */ $this->session->set('mrList', $this->app->getURI(true), 'repo'); + /* Sync GitLab MR to ZenTao Database. */ + $this->mr->batchSyncMR($MRList); + $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; - $this->view->MRList = $this->mr->getList($orderBy, $pager); + $this->view->MRList = $MRList; $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->pager = $pager; @@ -148,7 +152,8 @@ class mr extends control */ public function syncMR() { - $this->mr->getList(); + $MRList = $this->mr->getList(); + $this->mr->batchSyncMR($MRList); if(dao::isError()) { diff --git a/module/mr/model.php b/module/mr/model.php index 0579eff71d..1f900b3b57 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -52,8 +52,6 @@ class mrModel extends model ->page($pager) ->fetchAll('id'); - foreach($MRList as $MR) $this->apiSyncMR($MR); - return $MRList; } @@ -191,7 +189,7 @@ class mrModel extends model { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(isset($rawMR->iid)) + if(isset($rawMR->iid) and $rawMR->state != 'merged') { $map = $this->config->MR->maps->sync; $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); @@ -220,63 +218,98 @@ class mrModel extends model $this->dao->update(TABLE_MR)->data($newMR) ->where('id')->eq($MR->id) ->exec(); - - /*Sync GitLab Todo ZenTao Todo. */ - - $gitlabTodoList = $this->apiTodoList($MR->gitlabID, $MR->targetProject); - if($gitlabTodoList) - { - foreach($gitlabTodoList as $do) - { - $todoDesc = $this->dao->select('*') - ->from(TABLE_TODO) - ->where('idvalue') - ->eq($do->id) - ->fetch(); - if(empty($todoDesc)) - { - $todo = new stdClass; - $todo->account = $this->app->user->account; - $todo->assignedTo = $this->app->user->account; - $todo->assignedBy = $this->app->user->account; - $todo->date = $do->target->created_at; - $todo->assignedDate = $do->target->created_at; - $todo->begin = $do->target->created_at; - $todo->end = ''; - $todo->type = 'mrapprove'; - $todo->idvalue = $do->id; - $todo->pri = 1; - $todo->name = $do->target->title; - $todo->desc = $do->target->description . "
" . $this->todoDescriptionLink($MR->gitlabID, $MR->targetProject); - $todo->private = 0; - $todo->config = 0; - $todo->finishedBy = ''; - $todo->finishedDate = ''; - $todo->closedBy = ''; - $todo->closedDate = '0000-00-00 00:00:00'; - $this->dao->insert(TABLE_TODO)->data($todo)->exec(); - } - } - } } return $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch(); } /** - * Get a list of to-do items. + * Batch Sync GitLab MR Database. + * + * @param object $MRList + * @access public + * @return void + */ + public function batchSyncMR($MRList) + { + if(!empty($MRList)) foreach($MRList as $MR) + { + + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + + if(isset($rawMR->iid) and $rawMR->state != 'merged') + { + /* create gitlab mr todo to zentao todo */ + $this->batchSyncTodo($MR->gitlabID, $MR->targetProject); + + $map = $this->config->MR->maps->sync; + $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); + + $newMR = new stdclass; + foreach($map as $syncField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + + if($optionType == 'field') $value = $rawMR->$field; + if($optionType == 'userPairs') + { + $gitlabUserID = ''; + if(isset($rawMR->$field[0])) + { + $gitlabUserID = $rawMR->$field[0]->$options; + } + $value = zget($gitlabUsers, $gitlabUserID, ''); + } + + if($value) $newMR->$syncField = $value; + } + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($newMR) + ->where('id')->eq($MR->id) + ->exec(); + } + } + } + + /** + * Sync GitLab Todo to ZenTao Todo. * - * @docs https://docs.gitlab.com/ee/api/todos.html * @param int $gitlabID * @param int $projectID * @access public - * @return object + * @return void */ - public function apiTodoList($gitlabID, $projectID) + public function batchSyncTodo($gitlabID, $projectID) { - $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); - if(!$gitlab) return ''; - $url = rtrim($gitlab->url, '/')."/api/v4/todos?project_id=$projectID&type=MergeRequest&private_token={$gitlab->token}"; - return json_decode(commonModel::http($url)); + $todoList = $this->loadModel('gitlab')->apiTodoList($gitlabID, $projectID); + + if(!empty($todoList)) + { + foreach($todoList as $do) + { + $todoDesc = $this->dao->select('*') + ->from(TABLE_TODO) + ->where('idvalue')->eq($do->id) + ->fetch(); + if(empty($todoDesc)) + { + $todo = new stdClass; + $todo->account = $this->app->user->account; + $todo->assignedTo = $this->app->user->account; + $todo->assignedBy = $this->app->user->account; + $todo->date = $do->target->created_at; + $todo->assignedDate = $do->target->created_at; + $todo->begin = $do->target->created_at; + $todo->type = 'mrapprove'; + $todo->idvalue = $do->id; + $todo->pri = 1; + $todo->name = $do->target->title; + $todo->desc = $do->target->description . "
" . $this->todoDescriptionLink($gitlabID, $projectID); + $todo->finishedBy = $this->app->user->account; + $this->dao->insert(TABLE_TODO)->data($todo)->exec(); + } + } + } } /** From cbf7227e8915b828eec7c3cd9eb90e0ee2129dd6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 2 Sep 2021 14:19:43 +0800 Subject: [PATCH 118/154] * Correct the bug when a API error is raised. --- module/mr/model.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 0579eff71d..53703fb5dd 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -105,11 +105,14 @@ class mrModel extends model $rawMR = $this->apiCreateMR($this->post->gitlabID, $this->post->sourceProject, $MRObject); - /* Another open merge request already exists for this source branch. */ + /** + * Another open merge request already exists for this source branch. + * The type of variable `$rawMR->message` is array. + */ if(isset($rawMR->message) and !isset($rawMR->iid)) { $this->dao->delete()->from(TABLE_MR)->where('id')->eq($MRID)->exec(); - return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->createMR, $rawMR->message)); + return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->createMR, $rawMR->message[0])); } /* Create MR failed. */ From 8201fafc464360724423785174957d2db4c66c52 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 2 Sep 2021 15:20:21 +0800 Subject: [PATCH 119/154] + Get sudo user ID in GitLab. --- module/mr/model.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 2073d4ff6d..281d48699f 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -418,13 +418,15 @@ class mrModel extends model * @param int $gitlabID * @param int $projectID * @param int $MRID + * @param string $sudo * @access public * @return object */ - public function apiAcceptMR($gitlabID, $projectID, $MRID) + public function apiAcceptMR($gitlabID, $projectID, $MRID, $sudo = "") { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/merge"); - return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + if($sudo != "") return json_decode(commonModel::http($url, $data = null, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'), $headers = array("sudo: 0"))); + return json_decode(commonModel::http($url, $data = null, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** @@ -457,4 +459,28 @@ class mrModel extends model $encoding = strtolower(str_replace('_', '-', $encoding)); return $scm->diff('', $fromProject, $toProject, $parse = true, $fromProject); } + + /** + * Get sudo user ID in GitLab. + * Note: sudo parameter in GitLab API can be user ID or username. + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function getSudoUsername($gitlabID, $projectID) + { + $zentaoUser = $this->app->user->account; + + /* Fetch user list both in Zentao and current GitLab project. */ + $bindedUsers = $this->gitlab->getUserAccountIdPairs($gitlabID); + $rawProjectUsers = $this->gitlab->apiGetProjectUsers($gitlabID, $projectID); + $users = array(); + foreach($rawProjectUsers as $rawProjectUser) + { + if(!empty($bindedUsers[$rawProjectUser->username])) $users[$rawProjectUser->username] = $bindedUsers[$rawProjectUser->username]; + } + if(!empty($users[$zentaoUser])) return $users[$zentaoUser]; + return ""; + } } From 1b41b61cee8eef4965ef44175747e05b28e152e3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 2 Sep 2021 15:21:19 +0800 Subject: [PATCH 120/154] * Using sudo to accept merge request. --- module/mr/control.php | 13 ++++++++++++- module/mr/lang/zh-cn.php | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 4c9450be56..12ad6a9ef5 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -174,8 +174,19 @@ class mr extends control public function accept($MRID) { $MR = $this->mr->getByID($MRID); - if(isset($MR->gitlabID)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + + /* Accept MR by using the mapped user in GitLab. */ + $sudoUser = $this->mr->getSudoUsername($MR->gitlabID, $MR->targetProject); + + if(isset($MR->gitlabID)) + { + if(!empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid, $sudo = $sudoUser); + if(empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + } if(isset($rawMR->state) and $rawMR->state == 'merged') return array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess); + + /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ + if(isset($rawMR->message)) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message)); return array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed); } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 9a83adbd96..92bfc96367 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -44,6 +44,7 @@ $lang->mr->notFound = "此{$lang->mr->common}不存在。"; $lang->mr->apiError = new stdclass; $lang->mr->apiError->createMR = "通过API创建合并请求失败,失败原因:%s"; +$lang->mr->apiError->sudo = "无法以当前用户绑定的GitLab账户进行操作,失败原因:%s"; $lang->mr->createFailedFromAPI = "创建合并请求失败。"; $lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; @@ -72,7 +73,6 @@ $lang->mr->acceptMR = "合并"; $lang->mr->mergeFailed = "无法合并,请核对合并请求状态"; $lang->mr->mergeSuccess = "已成功合并"; - /** * Merge Command Document. * From d272eeeefce98a643fad1f7d603d1e0ea3b0f87f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 2 Sep 2021 15:39:34 +0800 Subject: [PATCH 121/154] * Optimize fetching data from API. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 2d25db6f52..ae8289bc5b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -284,7 +284,7 @@ class gitlabModel extends model public function getProjectName($gitlabID, $projectID) { $project = $this->apiGetSingleProject($gitlabID, $projectID); - if(isset($project->name)) return $project->name; + if(is_object($project) and isset($project->name)) return $project->name; return false; } From 3d360a1e4e07b7673d34f651ec33829ded496822 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 2 Sep 2021 16:49:52 +0800 Subject: [PATCH 122/154] * Bug fix and reduce PHP notices. --- module/mr/view/browse.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 37c6f1dab6..469ebf1e91 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -11,7 +11,7 @@
@@ -56,7 +56,7 @@ id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); common::printLink('mr', 'edit', "mr={$MR->id}", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->diff}' class='btn btn-info'"); + common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'"); common::printLink('mr', 'delete', "mr={$MR->id}", '', '', "title='{$lang->mr->delete}' class='btn btn-info'"); ?> From 6441a8de44bc98caf8c42dc375b527bfcaa3defe Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 3 Sep 2021 01:39:33 +0000 Subject: [PATCH 123/154] * Add GitLab MR English Language. --- module/mr/lang/en.php | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 module/mr/lang/en.php diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php new file mode 100644 index 0000000000..6cd2a48e08 --- /dev/null +++ b/module/mr/lang/en.php @@ -0,0 +1,110 @@ +mr->common = "Merge Request"; +$lang->mr->create = "create"; +$lang->mr->browse = "browse"; +$lang->mr->list = "list"; +$lang->mr->edit = "edit"; +$lang->mr->delete = "delete"; +$lang->mr->view = "view"; +$lang->mr->source = 'source'; +$lang->mr->target = 'target'; +$lang->mr->viewDiff = 'view diff'; +$lang->mr->viewInGitlab = 'view GitLab'; + +$lang->mr->id = 'ID'; +$lang->mr->mriid = "MR原始ID"; +$lang->mr->name = 'name'; +$lang->mr->status = 'status'; +$lang->mr->author = 'author'; +$lang->mr->assignee = 'assignee'; +$lang->mr->reviewer = 'reviewer'; +$lang->mr->mergeStatus = 'merge status'; +$lang->mr->commits = 'commits'; +$lang->mr->changes = 'changes'; + +$lang->mr->statusList = array(); +$lang->mr->statusList['opened'] = 'opened'; +$lang->mr->statusList['closed'] = 'closed'; +$lang->mr->statusList['merged'] = 'merged'; + +$lang->mr->mergeStatusList = array(); +$lang->mr->mergeStatusList['checking'] = 'checking'; +$lang->mr->mergeStatusList['can_be_merged'] = 'can be merged'; +$lang->mr->mergeStatusList['cannot_be_merged'] = 'cannot be merged'; + +$lang->mr->description = 'description'; +$lang->mr->confirmDelete = 'Are you sure to delete this merge request?'; +$lang->mr->sourceProject = 'source project'; +$lang->mr->sourceBranch = 'source branch'; +$lang->mr->targetProject = 'target project'; +$lang->mr->targetBranch = 'target branch'; + +$lang->mr->usersTips = 'Tip: If you cannot choose the designator and reviewer, please go to the GitLab page to bind the user first.'; +$lang->mr->notFound = "Merge Reqest does not exist!"; + +$lang->mr->apiError = new stdclass; +$lang->mr->apiError->createMR = "Failed to create a merge request through API. Reason for failure:%s"; +$lang->mr->apiError->sudo = "Unable to operate with the GitLab account bound to the current user, the reason for the failure:%s"; + +$lang->mr->createFailedFromAPI = "Failed to create Merge Request."; +$lang->mr->accessGitlabFailed = "Unable to connect to the GitLab server."; + +$lang->mr->from = "from"; +$lang->mr->to = "to"; +$lang->mr->at = "at"; + +$lang->mr->pipeline = "Pipline"; +$lang->mr->pipelineSuccess = "Success"; +$lang->mr->pipelineFailed = "Failed"; +$lang->mr->pipelineCancled = "Cancled"; +$lang->mr->pipelineUnknown = "Unknown"; + +$lang->mr->pipelineStatus = array(); +$lang->mr->pipelineStatus['success'] = "success"; +$lang->mr->pipelineStatus['failed'] = "failed"; +$lang->mr->pipelineStatus['canceled'] = "canceled"; + +$lang->mr->MRHasConflicts = "Merge Request has a conflict"; +$lang->mr->hasConflicts = "Merge Request conflict"; +$lang->mr->hasNoConflict = "Can merge requests"; +$lang->mr->mergeByManual = "This merge request can be merged manually, please refer to"; +$lang->mr->commandLine = "Merge Request command"; +$lang->mr->acceptMR = "Accept Merge request "; +$lang->mr->mergeFailed = "Unable to merge request, please check the merge request status"; +$lang->mr->mergeSuccess = "Merge Request Successfully"; + +/** + * Merge Command Document. + * + * %s source_roject::http_url_to_repo + * %s mr::source_branch + * %s source_project::path_with_namespace . '-' . mr::source_branch + * %s mr::target_branch + * %s source_project::path_with_namespace . '-' . mr::source_branch + * %s mr::target_branch + */ +$lang->mr->commandDocument = <<< EOD +
Check, Review and Merge manually locally
+
+

+ step 1. Get and view the branches of this merge request. +

+    git fetch "%s" %s
+    git checkout -b "%s" FETCH_HEAD
+

+

+ step 2. View changes locally +

+

+ step 3. Merge branches and resolve any conflicts that arise +

+    git fetch origin
+    git checkout "%s"
+    git merge --no-ff "%s"
+

+

+ step 4. Push the merge to GitLab +

 git push origin "%s" 
+

+
+EOD; From 7d83d3110fa1570accc6a56694a293bf54b2b67a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 13:20:53 +0800 Subject: [PATCH 124/154] * Fix bug when sudo as user. --- module/mr/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/model.php b/module/mr/model.php index 281d48699f..43aa536fb1 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -425,7 +425,7 @@ class mrModel extends model public function apiAcceptMR($gitlabID, $projectID, $MRID, $sudo = "") { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/merge"); - if($sudo != "") return json_decode(commonModel::http($url, $data = null, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'), $headers = array("sudo: 0"))); + if($sudo != "") return json_decode(commonModel::http($url, $data = null, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'), $headers = array("sudo: {$sudo}"))); return json_decode(commonModel::http($url, $data = null, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } From 7a7c63499f1ef892094ed3ac440acb74182f587a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 13:21:14 +0800 Subject: [PATCH 125/154] * Fix bug for no response after accept view. --- module/mr/control.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 12ad6a9ef5..ab4d8d278a 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -183,11 +183,11 @@ class mr extends control if(!empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid, $sudo = $sudoUser); if(empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); } - if(isset($rawMR->state) and $rawMR->state == 'merged') return array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess); + if(isset($rawMR->state) and $rawMR->state == 'merged') return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess), 'locate' => helper::createLink('mr', 'browse')); /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ - if(isset($rawMR->message)) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message)); - return array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed); + if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message))); + return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed)); } /** From 13506c3cbd2c59c511289aa7f371655cbaaf17ba Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 13:37:41 +0800 Subject: [PATCH 126/154] * Add locate redirection but test not passed. --- module/mr/control.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index ab4d8d278a..007f413316 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -183,11 +183,14 @@ class mr extends control if(!empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid, $sudo = $sudoUser); if(empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); } - if(isset($rawMR->state) and $rawMR->state == 'merged') return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess), 'locate' => helper::createLink('mr', 'browse')); - + if(isset($rawMR->state) and $rawMR->state == 'merged') + { + return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse'))); + } /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ - if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message))); - return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed)); + + if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message), 'locate' => helper::createLink('mr', 'view', "mr={$MRID}"))); + return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}"))); } /** From c80ce42a12327385fb187824daf6cbb3211ad61e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 13:39:54 +0800 Subject: [PATCH 127/154] * Reformat code for accept MR. --- module/mr/control.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index 007f413316..ad75a908e9 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -187,9 +187,10 @@ class mr extends control { return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse'))); } - /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ + /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ if(isset($rawMR->message)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message), 'locate' => helper::createLink('mr', 'view', "mr={$MRID}"))); + return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}"))); } From 82d9ac3b02250eb3493dc1741492846f7b5f6c00 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 14:52:51 +0800 Subject: [PATCH 128/154] + Add apiGetProjectMembers apiGetProjectMember functions. --- module/gitlab/model.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ae8289bc5b..a9d27168b5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -493,7 +493,7 @@ class gitlabModel extends model * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return object */ public function apiGetProjectUsers($gitlabID, $projectID) { @@ -501,6 +501,35 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + /** + * Get project all members(users and users in groups). + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiGetProjectMembers($gitlabID, $projectID) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/members/all"); + return json_decode(commonModel::http($url)); + } + + /** + * Get the member detail in project. + * + * @param int $gitlabID + * @param int $projectID + * @param int $userID + * @access public + * @return object + */ + public function apiGetProjectMember($gitlabID, $projectID, $userID) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/members/all/$userID"); + return json_decode(commonModel::http($url)); + } + /** * Get single branch by API. * From fde5d66e3cf58d12bf998e50926aa150f9aa3b7c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 3 Sep 2021 14:54:35 +0800 Subject: [PATCH 129/154] * Adjust function comment. --- module/mr/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 43aa536fb1..a0edbaa0c6 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -461,12 +461,12 @@ class mrModel extends model } /** - * Get sudo user ID in GitLab. + * Get sudo user ID in both GitLab and Project. * Note: sudo parameter in GitLab API can be user ID or username. * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return int|string */ public function getSudoUsername($gitlabID, $projectID) { From 94f4d9110700bb0cabd0dbdca09ad98e462de0d9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 6 Sep 2021 11:29:52 +0800 Subject: [PATCH 130/154] * Modify en lang for MR. --- module/mr/lang/en.php | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php index 6cd2a48e08..c40575da89 100644 --- a/module/mr/lang/en.php +++ b/module/mr/lang/en.php @@ -9,16 +9,16 @@ $lang->mr->view = "view"; $lang->mr->source = 'source'; $lang->mr->target = 'target'; $lang->mr->viewDiff = 'view diff'; -$lang->mr->viewInGitlab = 'view GitLab'; +$lang->mr->viewInGitlab = 'view in GitLab'; $lang->mr->id = 'ID'; -$lang->mr->mriid = "MR原始ID"; -$lang->mr->name = 'name'; -$lang->mr->status = 'status'; -$lang->mr->author = 'author'; -$lang->mr->assignee = 'assignee'; -$lang->mr->reviewer = 'reviewer'; -$lang->mr->mergeStatus = 'merge status'; +$lang->mr->mriid = "raw MR ID"; +$lang->mr->name = 'Name'; +$lang->mr->status = 'Status'; +$lang->mr->author = 'Author'; +$lang->mr->assignee = 'Assignee'; +$lang->mr->reviewer = 'Reviewer'; +$lang->mr->mergeStatus = 'Merge status'; $lang->mr->commits = 'commits'; $lang->mr->changes = 'changes'; @@ -32,19 +32,19 @@ $lang->mr->mergeStatusList['checking'] = 'checking'; $lang->mr->mergeStatusList['can_be_merged'] = 'can be merged'; $lang->mr->mergeStatusList['cannot_be_merged'] = 'cannot be merged'; -$lang->mr->description = 'description'; +$lang->mr->description = 'Description'; $lang->mr->confirmDelete = 'Are you sure to delete this merge request?'; -$lang->mr->sourceProject = 'source project'; -$lang->mr->sourceBranch = 'source branch'; -$lang->mr->targetProject = 'target project'; -$lang->mr->targetBranch = 'target branch'; +$lang->mr->sourceProject = 'Source project'; +$lang->mr->sourceBranch = 'Source branch'; +$lang->mr->targetProject = 'Target project'; +$lang->mr->targetBranch = 'Target branch'; -$lang->mr->usersTips = 'Tip: If you cannot choose the designator and reviewer, please go to the GitLab page to bind the user first.'; -$lang->mr->notFound = "Merge Reqest does not exist!"; +$lang->mr->usersTips = 'Tip: If you cannot choose the assignee and reviewer, please go to the GitLab page to bind the user first.'; +$lang->mr->notFound = "Merge Request does not exist!"; $lang->mr->apiError = new stdclass; -$lang->mr->apiError->createMR = "Failed to create a merge request through API. Reason for failure:%s"; -$lang->mr->apiError->sudo = "Unable to operate with the GitLab account bound to the current user, the reason for the failure:%s"; +$lang->mr->apiError->createMR = "Failed to create a merge request through API. Reason: %s"; +$lang->mr->apiError->sudo = "Unable to operate with the GitLab account bound to the current user. Reason: %s"; $lang->mr->createFailedFromAPI = "Failed to create Merge Request."; $lang->mr->accessGitlabFailed = "Unable to connect to the GitLab server."; @@ -53,10 +53,10 @@ $lang->mr->from = "from"; $lang->mr->to = "to"; $lang->mr->at = "at"; -$lang->mr->pipeline = "Pipline"; +$lang->mr->pipeline = "Pipeline"; $lang->mr->pipelineSuccess = "Success"; $lang->mr->pipelineFailed = "Failed"; -$lang->mr->pipelineCancled = "Cancled"; +$lang->mr->pipelineCancled = "Canceled"; $lang->mr->pipelineUnknown = "Unknown"; $lang->mr->pipelineStatus = array(); @@ -65,8 +65,8 @@ $lang->mr->pipelineStatus['failed'] = "failed"; $lang->mr->pipelineStatus['canceled'] = "canceled"; $lang->mr->MRHasConflicts = "Merge Request has a conflict"; -$lang->mr->hasConflicts = "Merge Request conflict"; -$lang->mr->hasNoConflict = "Can merge requests"; +$lang->mr->hasConflicts = "There are merge conflicts"; +$lang->mr->hasNoConflict = "Can merge request"; $lang->mr->mergeByManual = "This merge request can be merged manually, please refer to"; $lang->mr->commandLine = "Merge Request command"; $lang->mr->acceptMR = "Accept Merge request "; @@ -76,7 +76,7 @@ $lang->mr->mergeSuccess = "Merge Request Successfully"; /** * Merge Command Document. * - * %s source_roject::http_url_to_repo + * %s source_project::http_url_to_repo * %s mr::source_branch * %s source_project::path_with_namespace . '-' . mr::source_branch * %s mr::target_branch @@ -84,26 +84,26 @@ $lang->mr->mergeSuccess = "Merge Request Successfully"; * %s mr::target_branch */ $lang->mr->commandDocument = <<< EOD -
Check, Review and Merge manually locally
+
Check out, review and merge locally

- step 1. Get and view the branches of this merge request. + step 1. Fetch and check out the branch for this merge request

     git fetch "%s" %s
     git checkout -b "%s" FETCH_HEAD

- step 2. View changes locally + step 2. Review the changes locally

- step 3. Merge branches and resolve any conflicts that arise + step 3. Merge the branch and fix any conflicts that come up

     git fetch origin
     git checkout "%s"
     git merge --no-ff "%s"

- step 4. Push the merge to GitLab + step 4. Push the result of the merge to GitLab

 git push origin "%s" 

From e664627f128466c87654daa6887b90fe35d27151 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 6 Sep 2021 11:31:56 +0800 Subject: [PATCH 131/154] * Add en lang for MR in DevOps menu. --- module/common/lang/en.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/common/lang/en.php b/module/common/lang/en.php index ac1f213127..0651332cf7 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -237,6 +237,7 @@ $lang->testcase->testsuite = 'Test Suite'; $lang->testcase->caselib = 'Case Library'; $lang->devops->compile = 'Compile'; +$lang->devops->mr = 'Merge Request'; $lang->devops->repo = 'Repo'; $lang->devops->rules = 'Rule'; From f16eba5b09f5b28c0958b1a9c95c9a2a48b6d80a Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 6 Sep 2021 05:22:27 +0000 Subject: [PATCH 132/154] * Add GitLab Merge Request Permission configuration. --- module/common/lang/menu.php | 3 +++ module/common/lang/zh-cn.php | 9 +++++---- module/group/lang/resource.php | 12 ++++++++++-- module/mr/control.php | 11 +++++++++++ module/mr/lang/zh-cn.php | 6 ++++++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index f9f3ecb4cb..38eaf5a9dc 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -223,6 +223,7 @@ $lang->scrum->menu->settings['subMenu']->whitelist = array('link' => "{$lang-> $lang->scrum->menu->settings['subMenu']->stakeholder = array('link' => "{$lang->stakeholder->common}|stakeholder|browse|project=%s", 'subModule' => 'stakeholder'); $lang->scrum->menu->settings['subMenu']->group = array('link' => "{$lang->priv}|project|group|project=%s", 'alias' => 'group,manageview,managepriv'); + /* Execution menu. */ $lang->execution->homeMenu = new stdclass(); if($config->systemMode == 'new') $lang->execution->homeMenu->executionkanban = array('link' => "{$lang->execution->executionKanban}|execution|executionkanban|"); @@ -331,6 +332,8 @@ $lang->devops->menuOrder[25] = 'jenkins'; $lang->devops->menuOrder[30] = 'maintain'; $lang->devops->menuOrder[35] = 'rules'; +$lang->devops->menu->mr['subMenu'] = new stdclass(); +$lang->devops->menu->mr['subMenu']->browse = array('link' => "{$lang->devops->settings}|mr|settings"); /* Doc menu. */ $lang->doc->menu = new stdclass(); $lang->doc->menu->dashboard = array('link' => "{$lang->dashboard}|doc|index"); diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 8935a7ceed..82324277a7 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -236,10 +236,11 @@ $lang->testcase->case = '用例'; $lang->testcase->testsuite = '套件'; $lang->testcase->caselib = '用例库'; -$lang->devops->compile = '构建'; -$lang->devops->mr = '合并请求'; -$lang->devops->repo = '版本库'; -$lang->devops->rules = '指令'; +$lang->devops->compile = '构建'; +$lang->devops->mr = '合并请求'; +$lang->devops->repo = '版本库'; +$lang->devops->rules = '指令'; +$lang->devops->settings = '合并请求设置'; $lang->admin->system = '系统'; $lang->admin->entry = '应用'; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index bb693f5039..3f042726ef 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1152,9 +1152,17 @@ $lang->gitlab->methodOrder[35] = 'bindUser'; /* merge request. */ $lang->resource->mr = new stdclass(); -$lang->resource->mr->common = "common"; +$lang->resource->mr->create = 'create'; +$lang->resource->mr->browse = 'browse'; +$lang->resource->mr->edit = 'edit'; +$lang->resource->mr->delete = 'delete'; +$lang->resource->mr->settings = 'settings'; -$lang->mr->methodOrder[5] = 'common'; +$lang->mr->methodOrder[10] = 'create'; +$lang->mr->methodOrder[15] = 'browse'; +$lang->mr->methodOrder[20] = 'edit'; +$lang->mr->methodOrder[25] = 'delete'; +$lang->mr->methodOrder[35] = 'settings'; /* Git. */ $lang->resource->git = new stdclass(); diff --git a/module/mr/control.php b/module/mr/control.php index 12ad6a9ef5..bb9051827e 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -32,6 +32,17 @@ class mr extends control $this->display(); } + /** + * settings MR function. + * + * @access public + * @return void + */ + public function settings() + { + $this->display(); + } + /** * Create MR function. * diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 92bfc96367..3ad1506d4f 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -21,12 +21,16 @@ $lang->mr->reviewer = '评审人'; $lang->mr->mergeStatus = '是否可合并'; $lang->mr->commits = '提交数'; $lang->mr->changes = '更改数'; +$lang->mr->settings = '合并代码设置'; $lang->mr->statusList = array(); $lang->mr->statusList['opened'] = '开放中'; $lang->mr->statusList['closed'] = '已关闭'; $lang->mr->statusList['merged'] = '已合并'; +$lang->mr->gitlabsever = 'GitLabSever'; +$lang->mr->projectname = '项目名称'; + $lang->mr->mergeStatusList = array(); $lang->mr->mergeStatusList['checking'] = '检查中'; $lang->mr->mergeStatusList['can_be_merged'] = '可合并'; @@ -73,6 +77,8 @@ $lang->mr->acceptMR = "合并"; $lang->mr->mergeFailed = "无法合并,请核对合并请求状态"; $lang->mr->mergeSuccess = "已成功合并"; +$lang->mr->settings = '合并代码设置'; +$lang->mr->sync = '设置同步'; /** * Merge Command Document. * From 81795244b321008b2623096484cec244a6cf796d Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 16:44:27 +0800 Subject: [PATCH 133/154] * Adjust getReferenceOptions function, rename param of function apiCreatePipeline. --- module/gitlab/model.php | 47 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index a9d27168b5..beeb1be943 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -289,20 +289,23 @@ class gitlabModel extends model } /** - * Get ref option menus. + * Get reference option menus. * * @param int $gitlabID * @param int $projectID * @access public * @return array */ - public function getRefOptions($gitlabID, $projectID) + public function getReferenceOptions($gitlabID, $projectID) { - $refList = array(); + $refList = array(); + $branches = $this->apiGetBranches($gitlabID, $projectID); - $tags = $this->apiGetTags($gitlabID, $projectID); - foreach($branches as $branch) $refList[] = "Branch::" . $branch->name; - foreach($tags as $tag) $refList[] = "Tag::" . $tag->name; + foreach($branches as $branch) $refList[$branch->name] = "Branch::" . $branch->name; + + $tags = $this->apiGetTags($gitlabID, $projectID); + foreach($tags as $tag) $refList[$tag->name] = "Tag::" . $tag->name; + return $refList; } @@ -865,14 +868,14 @@ class gitlabModel extends model /** * Create a new pipeline by api. * - * @param integer $gitlabID - * @param integer $projectID - * @param string $reference + * @param int $gitlabID + * @param int $projectID + * @param object $params * @access public * @return object * @docment https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline */ - public function apiCreatePipeline($gitlabID, $projectID, $reference) + public function apiCreatePipeline($gitlabID, $projectID, $params) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/pipeline"); return json_decode(commonModel::http($url, $reference, null, array("Content-Type: application/json"))); @@ -881,9 +884,9 @@ class gitlabModel extends model /** * Get single pipline by api. * - * @param integer $gitlabID - * @param integer $projectID - * @param integer $pipelineID + * @param int $gitlabID + * @param int $projectID + * @param int $pipelineID * @access public * @return object * @docment https://docs.gitlab.com/ee/api/pipelines.html#get-a-single-pipeline @@ -897,9 +900,9 @@ class gitlabModel extends model /** * List pipeline jobs by api. * - * @param integer $gitlabID - * @param integer $projectID - * @param integer $pipelineID + * @param int $gitlabID + * @param int $projectID + * @param int $pipelineID * @return object * @docment https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs */ @@ -912,9 +915,9 @@ class gitlabModel extends model /** * Get a single job by api. * - * @param integer $gitlabID - * @param integer $projectID - * @param integer $jobID + * @param int $gitlabID + * @param int $projectID + * @param int $jobID * @return object * @docment https://docs.gitlab.com/ee/api/jobs.html#get-a-single-job */ @@ -927,9 +930,9 @@ class gitlabModel extends model /** * Get a log file by api. * - * @param integer $gitlabID - * @param integer $projectID - * @param integer $jobID + * @param int $gitlabID + * @param int $projectID + * @param int $jobID * @return string * @docment https://docs.gitlab.com/ee/api/jobs.html#get-a-log-file */ From ddfe2479ac327e3cd9eceafbbc3dcbf32b9edd66 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 16:46:07 +0800 Subject: [PATCH 134/154] * Finish task #41976, adjust exec gitlab function. --- module/job/control.php | 40 +++---------------- module/job/model.php | 68 ++++++++++++++++++++++++--------- module/job/view/browse.html.php | 3 +- 3 files changed, 57 insertions(+), 54 deletions(-) diff --git a/module/job/control.php b/module/job/control.php index a44519e0cb..6b634e4686 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -161,7 +161,7 @@ class job extends control $repo = $this->loadModel('repo')->getRepoByID($job->repo); $this->view->repo = $this->loadModel('repo')->getRepoByID($job->repo); - if($repo->SCM == 'Gitlab') $this->view->refList = $this->loadModel('gitlab')->getRefOptions($repo->gitlab, $repo->project); + if($repo->SCM == 'Gitlab') $this->view->refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitlab, $repo->project); $repoList = $this->repo->getList($this->projectID); $repoPairs = array(0 => '', $repo->id => $repo->name); @@ -301,40 +301,12 @@ class job extends control * @access public * @return void */ - public function exec($id, $showForm = 'no') + public function exec($id) { - if($showForm == 'yes' or $_POST) + $job = $this->job->getByID($id); + if(strtolower($job->engine) == 'gitlab') { - $job = $this->job->getByID($id); - $refList = $this->loadModel('gitlab')->getRefOptions($job->server, $job->pipeline); - - if($_POST) - { - $reference = new stdclass; - $reference->ref = explode("::", $refList[$this->post->ref])[1]; - - $variables = array(); - foreach($this->post->keys as $key => $field) - { - $variable = array(); - if(!trim($this->post->values[$key])) continue; - $variable['key'] = $field; - $variable['value'] = $this->post->values[$key]; - $variable['variable_type'] = "env_var"; - - $variables[] = $variable; - } - - $reference->variables = $variables; - $compile = $this->job->exec($id, json_encode($reference)); - return $this->send(array('result' => 'success', 'message' => $this->lang->job->execSuccess, 'locate' => $this->createLink('compile', 'logs', "buildID={$compile->id}"))); - } - - $this->view->title = $this->lang->job->runPipeline; - $this->view->refList = $refList; - $this->view->job = $job; - $this->view->pipelineTips = $this->lang->job->pipelineTips; - return $this->display(); + if(!isset($job->reference) or !$job->reference) $this->locate(inlink('edit', "id=$id")); } $compile = $this->job->exec($id); @@ -389,7 +361,7 @@ class job extends control { $repo = $this->loadModel('repo')->getRepoByID($repoID); if($repo->SCM != 'Gitlab') $this->send(array('result' => 'fail')); - $refList = $this->loadModel('gitlab')->getRefOptions($repo->gitlab, $repo->project); + $refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitlab, $repo->project); $this->send(array('result' => 'success', 'refList' => $refList)); } } diff --git a/module/job/model.php b/module/job/model.php index 73afdf517b..0a41b7b99f 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -338,7 +338,7 @@ class jobModel extends model * @access public * @return string|bool */ - public function exec($id, $reference = null) + public function exec($id) { $job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.server,t1.pipeline,t1.triggerType,t1.atTime,t1.customParam,t1.engine,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') ->from(TABLE_JOB)->alias('t1') @@ -408,33 +408,65 @@ class jobModel extends model $data->$paramName = $paramValue; } - $compile = new stdclass(); - $compile->id = $compileID; - if($job->engine == 'jenkins') { $url = $this->loadModel('compile')->getBuildUrl($job); + + $compile = new stdclass(); + $compile->id = $compileID; $compile->queue = $this->loadModel('ci')->sendRequest($url->url, $data, $url->userPWD); $compile->status = $compile->queue ? 'created' : 'create_fail'; } - elseif($job->engine == 'gitlab' and $reference) - { - list($gitlabProject, $gitlabReference) = json_decode($job->pipeline); - $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $gitlabProject, $gitlabReference); - if(empty($pipeline->id)) - { - $compile->status = 'create_fail'; - } - else - { - $compile->queue = $pipeline->id; - $compile->status = zget($pipeline, 'status', 'create_fail'); - } - } + + if($job->engine == 'gitlab') $compile = $this->execGitlabPipeline($job, $compileID); $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); $this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($compile->status)->where('id')->eq($job->id)->exec(); return $compile; } + + /** + * Exec gitlab pipeline. + * + * @param int $job + * @param int $compileID + * @access public + * @return void + */ + public function execGitlabPipeline($job, $compileID) + { + list($gitlabProject, $gitlabReference) = json_decode($job->pipeline); + + $pipelineParams = new stdclass; + $pipelineParams->ref = $gitlabReference; + + $customParams = json_decode($job->customParam); + $variables = array(); + foreach($customParams as $paramName => $paramValue) + { + $variable = array(); + $variable['key'] = $paramName; + $variable['value'] = $paramValue; + $variable['variable_type'] = "env_var"; + + $variables[] = $variable; + } + + $pipelineParams->variables = $variables; + + $compile = new stdclass; + $compile->id = $compileID; + + $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $gitlabProject, $pipelineParams); + if(empty($pipeline->id)) $compile->status = 'create_fail'; + + if(!empty($pipeline->id)) + { + $compile->queue = $pipeline->id; + $compile->status = zget($pipeline, 'status', 'create_fail'); + } + + return $compile; + } } diff --git a/module/job/view/browse.html.php b/module/job/view/browse.html.php index 7e0b15f941..8b4b068dc6 100644 --- a/module/job/view/browse.html.php +++ b/module/job/view/browse.html.php @@ -67,8 +67,7 @@ engine) == 'jenkins') common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play', 'hiddenwin'); - if(strtolower($job->engine) == 'gitlab') common::printIcon('job', 'exec', "jobID=$id&showForm=yes", '', 'list', 'play', '', '', false, "data-toggle='modal' data-type='ajax'"); + common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play', 'hiddenwin'); if(common::hasPriv('job', 'delete')) echo html::a($this->createLink('job', 'delete', "jobID=$id"), '', 'hiddenwin', "title='{$lang->job->delete}' class='btn'"); ?> From a5ceffb6cf67278170ef3fb990c291712fed11d2 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 17:29:37 +0800 Subject: [PATCH 135/154] * Fix exec gitlab job bug and adjust exec job function. --- module/gitlab/model.php | 3 ++- module/job/control.php | 10 ++++++---- module/job/js/browse.js | 16 ++++++++++++++++ module/job/lang/zh-cn.php | 1 + module/job/model.php | 8 ++++---- module/job/view/browse.html.php | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 module/job/js/browse.js diff --git a/module/gitlab/model.php b/module/gitlab/model.php index beeb1be943..003ca55bfe 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -877,8 +877,9 @@ class gitlabModel extends model */ public function apiCreatePipeline($gitlabID, $projectID, $params) { + if(!is_string($params)) $params = json_encode($params); $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/pipeline"); - return json_decode(commonModel::http($url, $reference, null, array("Content-Type: application/json"))); + return json_decode(commonModel::http($url, $params, null, array("Content-Type: application/json"))); } /** diff --git a/module/job/control.php b/module/job/control.php index 6b634e4686..e3f12a3be4 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -306,15 +306,17 @@ class job extends control $job = $this->job->getByID($id); if(strtolower($job->engine) == 'gitlab') { - if(!isset($job->reference) or !$job->reference) $this->locate(inlink('edit', "id=$id")); + if(!isset($job->reference) or !$job->reference) + { + return $this->send(array('result' => 'fail', 'message' => $this->lang->job->setReferenceTips, 'locate' => inlink('edit', "id=$id"))); + } } $compile = $this->job->exec($id); - if(dao::isError()) die(js::error(dao::getError())); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->app->loadLang('compile'); - echo js::alert(sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $compile->status))); - die(js::reload('parent')); + return $this->send(array('result' => 'success', 'message' => sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $compile->status)))); } /** diff --git a/module/job/js/browse.js b/module/job/js/browse.js new file mode 100644 index 0000000000..b801c52f3b --- /dev/null +++ b/module/job/js/browse.js @@ -0,0 +1,16 @@ +$(document).ready(function() +{ + $('.icon-job-exec').parent().click(function() + { + link = $(this).attr('href'); + $.getJSON(link, function(response) + { + if(response.result == 'success') bootbox.alert(response.message); + if(response.result != 'success') bootbox.alert(response.message, function() + { + if(typeof(response.locate) == 'string') location.href = response.locate; + }); + }); + return false; + }); +}); diff --git a/module/job/lang/zh-cn.php b/module/job/lang/zh-cn.php index 6209ba46a4..12681b5324 100644 --- a/module/job/lang/zh-cn.php +++ b/module/job/lang/zh-cn.php @@ -86,3 +86,4 @@ $lang->job->pipelineVariables = "变量"; $lang->job->pipelineVariablesKeyPlaceHolder = "输入变量的名称"; $lang->job->pipelineVariablesValuePlaceHolder = "输入变量的值"; $lang->job->pipelineVariablesTips = "指定要在此次运行中使用的变量值。CI/CD设置中指定的值将用作默认值。"; +$lang->job->setReferenceTips = "在执行构建前,请先设置构建的 Reference."; diff --git a/module/job/model.php b/module/job/model.php index 0a41b7b99f..aa272209d8 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -436,10 +436,10 @@ class jobModel extends model */ public function execGitlabPipeline($job, $compileID) { - list($gitlabProject, $gitlabReference) = json_decode($job->pipeline); + $pipeline = json_decode($job->pipeline); $pipelineParams = new stdclass; - $pipelineParams->ref = $gitlabReference; + $pipelineParams->ref = $pipeline->reference; $customParams = json_decode($job->customParam); $variables = array(); @@ -453,12 +453,12 @@ class jobModel extends model $variables[] = $variable; } - $pipelineParams->variables = $variables; + if(!empty($variables)) $pipelineParams->variables = $variables; $compile = new stdclass; $compile->id = $compileID; - $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $gitlabProject, $pipelineParams); + $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $pipeline->project, $pipelineParams); if(empty($pipeline->id)) $compile->status = 'create_fail'; if(!empty($pipeline->id)) diff --git a/module/job/view/browse.html.php b/module/job/view/browse.html.php index 8b4b068dc6..177cb7a320 100644 --- a/module/job/view/browse.html.php +++ b/module/job/view/browse.html.php @@ -67,7 +67,7 @@ createLink('job', 'delete', "jobID=$id"), '', 'hiddenwin', "title='{$lang->job->delete}' class='btn'"); ?> From cd1a40b066a7d2f7aa84a0dd3346b37c190213e5 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 17:45:08 +0800 Subject: [PATCH 136/154] * Fix job object name in browse page. --- module/job/lang/zh-cn.php | 2 +- module/job/view/browse.html.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/module/job/lang/zh-cn.php b/module/job/lang/zh-cn.php index 12681b5324..d95c034f77 100644 --- a/module/job/lang/zh-cn.php +++ b/module/job/lang/zh-cn.php @@ -86,4 +86,4 @@ $lang->job->pipelineVariables = "变量"; $lang->job->pipelineVariablesKeyPlaceHolder = "输入变量的名称"; $lang->job->pipelineVariablesValuePlaceHolder = "输入变量的值"; $lang->job->pipelineVariablesTips = "指定要在此次运行中使用的变量值。CI/CD设置中指定的值将用作默认值。"; -$lang->job->setReferenceTips = "在执行构建前,请先设置构建的 Reference."; +$lang->job->setReferenceTips = "在执行构建前,请先设置代码库的分支信息。"; diff --git a/module/job/view/browse.html.php b/module/job/view/browse.html.php index 177cb7a320..4fc37ec44e 100644 --- a/module/job/view/browse.html.php +++ b/module/job/view/browse.html.php @@ -50,13 +50,20 @@ $job):?> +I engine) == 'gitlab') + { + $pipeline = json_decode($job->pipeline); + if(is_numeric($job->pipeline)) $job->pipeline = $this->loadModel('gitlab')->getProjectName($job->server, $job->pipeline); + if(isset($pipeline->reference)) $job->pipeline = $this->loadModel('gitlab')->getProjectName($job->server, $pipeline->project); + } + ?> createLink('job', 'view', "jobID={$job->id}", 'html', true), $job->name, '', "class='iframe' data-width='90%'") : $job->name;?> repoName;?> job->engineList, $job->engine);?> job->frameList, $job->frame);?> - engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getProjectName($job->server, $job->pipeline);?> pipeline) . '@' . $job->jenkinsName;?> job->getTriggerConfig($job);?> From 9d5c1de0ab2e9027063d8fc89eb518cde8fe0569 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 6 Sep 2021 17:57:27 +0800 Subject: [PATCH 137/154] * Sync MR in ZenTao database whatever status of MR in GitLab. --- module/mr/model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index a0edbaa0c6..6f90f790a3 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -192,7 +192,8 @@ class mrModel extends model { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(isset($rawMR->iid) and $rawMR->state != 'merged') + /* Sync MR in ZenTao database whatever status of MR in GitLab. */ + if(isset($rawMR->iid)) { $map = $this->config->MR->maps->sync; $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); @@ -239,7 +240,7 @@ class mrModel extends model $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(isset($rawMR->iid) and $rawMR->state != 'merged') + if(isset($rawMR->iid)) { /* create gitlab mr todo to zentao todo */ $this->batchSyncTodo($MR->gitlabID, $MR->targetProject); From 2d1bc4fcc77df8662f24fda6afd586a5d49cb996 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 20:07:04 +0800 Subject: [PATCH 138/154] * Finish task #41977. --- module/compile/model.php | 33 ++++++--- module/job/model.php | 154 +++++++++++++++++++++++---------------- 2 files changed, 115 insertions(+), 72 deletions(-) diff --git a/module/compile/model.php b/module/compile/model.php index 5fe8999488..accbed3c93 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -129,17 +129,30 @@ class compileModel extends model if(!$job) return false; - $data = new stdclass(); - $data->PARAM_TAG = $compile->tag; - $data->ZENTAO_DATA = "compile={$compile->id}"; + $compileID = $compile->id; + $repo = $this->loadModel('repo')->getRepoById($job->repo); - $url = $this->getBuildUrl($job); - $build = new stdclass(); - $build->queue = $this->loadModel('ci')->sendRequest($url->url, $data, $url->userPWD); - $build->status = $build->queue ? 'created' : 'create_fail'; - $build->updateDate = helper::now(); - $this->dao->update(TABLE_COMPILE)->data($build)->where('id')->eq($compile->id)->exec(); - $this->dao->update(TABLE_JOB)->set('lastStatus')->eq($build->status)->set('lastExec')->eq($build->updateDate)->where('id')->eq($compile->job)->exec(); + if($job->triggerType == 'tag') + { + $lastTag = $this->getLastTagByRepo($repo); + if($lastTag) + { + $job->lastTag = $lastTag; + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($job->id)->exec(); + } + + $this->dao->update(TABLE_COMPILE)->set('tag')->eq($lastTag)->where('id')->eq($compile->id)->exec(); + } + + if($job->engine == 'gitlab') $compile = $this->loadModel('job')->execGitlabPipeline($job, $compileID); + if($job->engine == 'jenkins') $compile = $this->job->execJenkinsPipeline($job, $repo, $compile->id); + + $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); + $this->dao->update(TABLE_JOB) + ->set('lastStatus')->eq($build->status) + ->set('lastExec')->eq($build->updateDate) + ->where('id')->eq($job->id) + ->exec(); return !dao::isError(); } diff --git a/module/job/model.php b/module/job/model.php index aa272209d8..3195bd5179 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -345,83 +345,83 @@ class jobModel extends model ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.server=t2.id') ->where('t1.id')->eq($id) ->fetch(); + if(!$job) return false; - $build = new stdclass(); - $build->job = $job->id; - $build->name = $job->name; - - $now = helper::now(); - $data = new stdclass(); $repo = $this->loadModel('repo')->getRepoById($job->repo); - $data->PARAM_TAG = ''; - if($job->triggerType == 'tag') - { - $lastTag = ''; - if($repo->SCM == 'Subversion') - { - $dirs = $this->loadModel('svn')->getRepoTags($repo, $job->svnDir); - if($dirs) - { - end($dirs); - $lastTag = current($dirs); - $lastTag = rtrim($repo->path , '/') . '/' . trim($job->svnDir, '/') . '/' . $lastTag; - } - } - else - { - $tags = $this->loadModel('git')->getRepoTags($repo); - if($tags) - { - end($tags); - $lastTag = current($tags); - } - } - - if($lastTag) - { - $build->tag = $lastTag; - $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($job->id)->exec(); - $data->PARAM_TAG = $lastTag; - } - } - elseif($job->triggerType == 'schedule') - { - $build->atTime = $job->atTime; - } + $now = helper::now(); + /* Save compile data. */ + $build = new stdclass(); + $build->job = $job->id; + $build->name = $job->name; $build->createdBy = $this->app->user->account; $build->createdDate = $now; $build->updateDate = $now; + + if($job->triggerType == 'schedule') $build->atTime = $job->atTime; + + if($job->triggerType == 'tag') + { + $lastTag = $this->getLastTagByRepo($repo); + if($lastTag) + { + $build->tag = $lastTag; + $job->lastTag = $lastTag; + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($job->id)->exec(); + } + } + $this->dao->insert(TABLE_COMPILE)->data($build)->exec(); $compileID = $this->dao->lastInsertId(); - $data->ZENTAO_DATA = "compile={$compileID}"; + if($job->engine == 'jenkins') $compile = $this->execJenkinsPipeline($job, $repo, $compileID); + if($job->engine == 'gitlab') $compile = $this->execGitlabPipeline($job); + + $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); + + $this->dao->update(TABLE_JOB) + ->set('lastExec')->eq($now) + ->set('lastStatus')->eq($compile->status) + ->where('id')->eq($job->id) + ->exec(); + + return $compile; + } + + /** + * Exec jenkins pipeline. + * + * @param object $job + * @param object $repo + * @param int $compileID + * @access public + * @return object + */ + public function execJenkinsPipeline($job, $repo, $compileID) + { + $pipeline = new stdclass(); + $pipeline->PARAM_TAG = ''; + $pipeline->ZENTAO_DATA = "compile={$compileID}"; + if($job->triggerType == 'tag') $pipeline->PARAM_TAG = $job->lastTag; /* Add custom parameters to the data. */ foreach(json_decode($job->customParam) as $paramName => $paramValue) { - $paramValue = str_replace('$zentao_version', $this->config->version, $paramValue); - $paramValue = str_replace('$zentao_account', $this->app->user->account, $paramValue); - $paramValue = str_replace('$zentao_product', $job->product, $paramValue); + $paramValue = str_replace('$zentao_version', $this->config->version, $paramValue); + $paramValue = str_replace('$zentao_account', $this->app->user->account, $paramValue); + $paramValue = str_replace('$zentao_product', $job->product, $paramValue); $paramValue = str_replace('$zentao_repopath', $repo->path, $paramValue); - $data->$paramName = $paramValue; + + $pipeline->$paramName = $paramValue; } - if($job->engine == 'jenkins') - { - $url = $this->loadModel('compile')->getBuildUrl($job); + $url = $this->loadModel('compile')->getBuildUrl($job); - $compile = new stdclass(); - $compile->id = $compileID; - $compile->queue = $this->loadModel('ci')->sendRequest($url->url, $data, $url->userPWD); - $compile->status = $compile->queue ? 'created' : 'create_fail'; - } - - if($job->engine == 'gitlab') $compile = $this->execGitlabPipeline($job, $compileID); - - $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); - $this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($compile->status)->where('id')->eq($job->id)->exec(); + $compile = new stdclass(); + $compile->id = $compileID; + $compile->queue = $this->loadModel('ci')->sendRequest($url->url, $pipeline, $url->userPWD); + $compile->status = $compile->queue ? 'created' : 'create_fail'; return $compile; } @@ -430,11 +430,10 @@ class jobModel extends model * Exec gitlab pipeline. * * @param int $job - * @param int $compileID * @access public * @return void */ - public function execGitlabPipeline($job, $compileID) + public function execGitlabPipeline($job) { $pipeline = json_decode($job->pipeline); @@ -456,7 +455,6 @@ class jobModel extends model if(!empty($variables)) $pipelineParams->variables = $variables; $compile = new stdclass; - $compile->id = $compileID; $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $pipeline->project, $pipelineParams); if(empty($pipeline->id)) $compile->status = 'create_fail'; @@ -469,4 +467,36 @@ class jobModel extends model return $compile; } + + /** + * Get last tag of one repo. + * + * @param object $repo + * @access public + * @return void + */ + public function getLastTagByRepo($repo) + { + if($repo->SCM == 'Subversion') + { + $dirs = $this->loadModel('svn')->getRepoTags($repo, $job->svnDir); + if($dirs) + { + end($dirs); + $lastTag = current($dirs); + return rtrim($repo->path , '/') . '/' . trim($job->svnDir, '/') . '/' . $lastTag; + } + } + else + { + $tags = $this->loadModel('git')->getRepoTags($repo); + if($tags) + { + end($tags); + return current($tags); + } + } + + return ''; + } } From 7ca5893ce2afea68297eb07555f0a46b0e06bafe Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 7 Sep 2021 00:44:34 +0000 Subject: [PATCH 139/154] * Cancel GitLab SYNC Settings. --- module/common/lang/menu.php | 3 --- module/group/js/managepriv.js | 4 ++-- module/group/view/managepriv.html.php | 2 +- module/mr/control.php | 11 ----------- module/mr/lang/zh-cn.php | 5 ----- module/mr/model.php | 1 - 6 files changed, 3 insertions(+), 23 deletions(-) diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index 38eaf5a9dc..d93dece94e 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -331,9 +331,6 @@ $lang->devops->menuOrder[20] = 'gitlab'; $lang->devops->menuOrder[25] = 'jenkins'; $lang->devops->menuOrder[30] = 'maintain'; $lang->devops->menuOrder[35] = 'rules'; - -$lang->devops->menu->mr['subMenu'] = new stdclass(); -$lang->devops->menu->mr['subMenu']->browse = array('link' => "{$lang->devops->settings}|mr|settings"); /* Doc menu. */ $lang->doc->menu = new stdclass(); $lang->doc->menu->dashboard = array('link' => "{$lang->dashboard}|doc|index"); diff --git a/module/group/js/managepriv.js b/module/group/js/managepriv.js index 94b96a75ab..6b7ac166ac 100644 --- a/module/group/js/managepriv.js +++ b/module/group/js/managepriv.js @@ -5,8 +5,8 @@ function showPriv(value) /** * Control the actions select control for a module. - * - * @param string $module + * + * @param string $module * @access public * @return void */ diff --git a/module/group/view/managepriv.html.php b/module/group/view/managepriv.html.php index 4bd7c24837..d89dbd8064 100644 --- a/module/group/view/managepriv.html.php +++ b/module/group/view/managepriv.html.php @@ -10,7 +10,7 @@ * @link http://www.zentao.net */ ?> -display(); } - /** - * settings MR function. - * - * @access public - * @return void - */ - public function settings() - { - $this->display(); - } - /** * Create MR function. * diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 3ad1506d4f..025ec7e8c2 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -28,9 +28,6 @@ $lang->mr->statusList['opened'] = '开放中'; $lang->mr->statusList['closed'] = '已关闭'; $lang->mr->statusList['merged'] = '已合并'; -$lang->mr->gitlabsever = 'GitLabSever'; -$lang->mr->projectname = '项目名称'; - $lang->mr->mergeStatusList = array(); $lang->mr->mergeStatusList['checking'] = '检查中'; $lang->mr->mergeStatusList['can_be_merged'] = '可合并'; @@ -77,8 +74,6 @@ $lang->mr->acceptMR = "合并"; $lang->mr->mergeFailed = "无法合并,请核对合并请求状态"; $lang->mr->mergeSuccess = "已成功合并"; -$lang->mr->settings = '合并代码设置'; -$lang->mr->sync = '设置同步'; /** * Merge Command Document. * diff --git a/module/mr/model.php b/module/mr/model.php index a0edbaa0c6..7dbf3e8f9a 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -238,7 +238,6 @@ class mrModel extends model { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(isset($rawMR->iid) and $rawMR->state != 'merged') { /* create gitlab mr todo to zentao todo */ From a786e5f00d13ad482a0078cbaf2a0dde3fc467e7 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 7 Sep 2021 00:50:33 +0000 Subject: [PATCH 140/154] * GitLab MR Code Merge. --- module/mr/model.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 31e9076d04..17cd6a674e 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -239,12 +239,7 @@ class mrModel extends model { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); -<<<<<<< HEAD if(isset($rawMR->iid) and $rawMR->state != 'merged') -======= - - if(isset($rawMR->iid)) ->>>>>>> 2d1bc4fcc77df8662f24fda6afd586a5d49cb996 { /* create gitlab mr todo to zentao todo */ $this->batchSyncTodo($MR->gitlabID, $MR->targetProject); From 90c3e3479f8f5e74c5087aaa55f54f079e324976 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 7 Sep 2021 01:58:24 +0000 Subject: [PATCH 141/154] * Fix GitLab MR sync status. --- module/mr/model.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 17cd6a674e..4d0db5997d 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -191,7 +191,6 @@ class mrModel extends model public function apiSyncMR($MR) { $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - /* Sync MR in ZenTao database whatever status of MR in GitLab. */ if(isset($rawMR->iid)) { @@ -237,9 +236,8 @@ class mrModel extends model { if(!empty($MRList)) foreach($MRList as $MR) { - $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(isset($rawMR->iid) and $rawMR->state != 'merged') + if(isset($rawMR->iid)) { /* create gitlab mr todo to zentao todo */ $this->batchSyncTodo($MR->gitlabID, $MR->targetProject); @@ -248,6 +246,7 @@ class mrModel extends model $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); $newMR = new stdclass; + foreach($map as $syncField => $config) { $value = ''; From ee13e00554757c2484141fa0a8c30cb4a8c8231a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 10:02:52 +0800 Subject: [PATCH 142/154] * Add tips for merge code locally. --- module/mr/lang/en.php | 1 + module/mr/lang/zh-cn.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php index c40575da89..40c82646e7 100644 --- a/module/mr/lang/en.php +++ b/module/mr/lang/en.php @@ -86,6 +86,7 @@ $lang->mr->mergeSuccess = "Merge Request Successfully"; $lang->mr->commandDocument = <<< EOD
Check out, review and merge locally
+

Note: This merge request status will be changed after you merge locally and you will need to delete this merge request or submit new code.

step 1. Fetch and check out the branch for this merge request

diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php
index 025ec7e8c2..12b7f2c6bd 100644
--- a/module/mr/lang/zh-cn.php
+++ b/module/mr/lang/zh-cn.php
@@ -77,7 +77,7 @@ $lang->mr->mergeSuccess   = "已成功合并";
 /**
  * Merge Command Document.
  *
- * %s source_roject::http_url_to_repo
+ * %s source_project::http_url_to_repo
  * %s mr::source_branch
  * %s source_project::path_with_namespace . '-' . mr::source_branch
  * %s mr::target_branch
@@ -87,6 +87,7 @@ $lang->mr->mergeSuccess   = "已成功合并";
 $lang->mr->commandDocument = <<< EOD
 
在本地检出、审核和手动合并
+

注意:您在本地合并后此合并请求将变为不可合并状态,需要删除此合并请求或者提交新的代码。

第 1 步. 获取并查看此合并请求的分支


From 701b000c09e5182f2546e0b74527831d62544f07 Mon Sep 17 00:00:00 2001
From: dingguodong 
Date: Tue, 7 Sep 2021 10:13:57 +0800
Subject: [PATCH 143/154] * Optimize language file.

---
 module/mr/lang/en.php    | 4 ++--
 module/mr/lang/zh-cn.php | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php
index 40c82646e7..61e7e883d2 100644
--- a/module/mr/lang/en.php
+++ b/module/mr/lang/en.php
@@ -65,8 +65,8 @@ $lang->mr->pipelineStatus['failed']   = "failed";
 $lang->mr->pipelineStatus['canceled'] = "canceled";
 
 $lang->mr->MRHasConflicts = "Merge Request has a conflict";
-$lang->mr->hasConflicts   = "There are merge conflicts";
-$lang->mr->hasNoConflict  = "Can merge request";
+$lang->mr->hasConflicts   = "There are merge conflicts or wait for push";
+$lang->mr->hasNoConflict  = "Can merge";
 $lang->mr->mergeByManual  = "This merge request can be merged manually, please refer to";
 $lang->mr->commandLine    = "Merge Request command";
 $lang->mr->acceptMR       = "Accept Merge request ";
diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php
index 12b7f2c6bd..1f88c3e478 100644
--- a/module/mr/lang/zh-cn.php
+++ b/module/mr/lang/zh-cn.php
@@ -65,9 +65,9 @@ $lang->mr->pipelineStatus['success']  = "已通过";
 $lang->mr->pipelineStatus['failed']   = "未通过";
 $lang->mr->pipelineStatus['canceled'] = "已取消";
 
-$lang->mr->MRHasConflicts = "是否存在合并冲突";
-$lang->mr->hasConflicts   = "存在合并冲突";
-$lang->mr->hasNoConflict  = "可以合并请求";
+$lang->mr->MRHasConflicts = "是否存在冲突";
+$lang->mr->hasConflicts   = "存在冲突或等待提交";
+$lang->mr->hasNoConflict  = "可以合并";
 $lang->mr->mergeByManual  = "此合并请求可以手动合并,请使用以下";
 $lang->mr->commandLine    = "合并命令";
 $lang->mr->acceptMR       = "合并";

From 7b9cb9ed8e2fdba6ef83afd3284f7c74b4750897 Mon Sep 17 00:00:00 2001
From: Guan Xiying 
Date: Tue, 7 Sep 2021 10:26:39 +0800
Subject: [PATCH 144/154] * Remove debug codes.

---
 lib/scm/gitlab.class.php | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php
index e36d4b86d0..cae6a19004 100644
--- a/lib/scm/gitlab.class.php
+++ b/lib/scm/gitlab.class.php
@@ -282,14 +282,8 @@ class gitlab
         if(!scm::checkRevision($toRevision))   return array();
 
         $api    = "compare";
-        $params = array('from' => $fromRevision, 'to' => $toRevision, 'straight' => 1);
-        if($fromProject)
-        {
-            $params['from'] = 'dev';
-            $params['to']   = 'master';
-            $params['from_project_id'] = $fromProject;
-            $params['straight']        = 1;
-        }
+        $params = array('from' => $fromRevision, 'to' => $toRevision);
+        if($fromProject) $params['from_project_id'] = $fromProject;
 
         if($toRevision == 'HEAD' and $this->branch) $params['to'] = $this->branch;
         $results = $this->fetch($api, $params);

From 12935f3ead2c2d7a9cb23cc13e195be0e1b16ec6 Mon Sep 17 00:00:00 2001
From: lichengjun 
Date: Tue, 7 Sep 2021 02:33:36 +0000
Subject: [PATCH 145/154] * Adjust GitLab MR TODO Detail.

---
 module/mr/model.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/module/mr/model.php b/module/mr/model.php
index 4d0db5997d..1119bc636d 100644
--- a/module/mr/model.php
+++ b/module/mr/model.php
@@ -306,7 +306,7 @@ class mrModel extends model
                     $todo->idvalue      = $do->id;
                     $todo->pri          = 1;
                     $todo->name         = $do->target->title;
-                    $todo->desc         = $do->target->description . "
" . $this->todoDescriptionLink($gitlabID, $projectID); + $todo->desc = $do->target->description . "
" . '' . $this->todoDescriptionLink($gitlabID, $projectID) .''; $todo->finishedBy = $this->app->user->account; $this->dao->insert(TABLE_TODO)->data($todo)->exec(); } From d5b52bc7ad77c49cd72c7ea3063206f7486fa792 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 7 Sep 2021 10:50:34 +0800 Subject: [PATCH 146/154] * Fix viewDiif. --- module/mr/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index ad75a908e9..b08684f9b7 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -277,7 +277,7 @@ class mr extends control } } - $this->view->title = $this->lang->mr->viewDiif; + $this->view->title = $this->lang->mr->viewDiff; $this->view->diffs = $diffs; $this->view->arrange = $arrange; $this->display(); From 8e8875319fbc5e60618f717ca44ce030fa511fa4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 10:50:44 +0800 Subject: [PATCH 147/154] * Optimize function getDiffs. --- module/mr/model.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 4d0db5997d..40a7998c7f 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -439,15 +439,13 @@ class mrModel extends model public function getDiffs($MR) { $gitlab = $this->gitlab->getByID($MR->gitlabID); - $fromProject = $MR->sourceProject; - $toProject = $MR->targetProject; $this->loadModel('repo'); $repo = new stdclass; $repo->SCM = 'GitLab'; $repo->gitlab = $gitlab->id; - $repo->project = $toProject; - $repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $toProject); + $repo->project = $MR->targetProject; + $repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $MR->targetProject); $repo->client = $gitlab->url; $repo->password = $gitlab->token; @@ -456,7 +454,7 @@ class mrModel extends model $encoding = empty($encoding) ? $repo->encoding : $encoding; $encoding = strtolower(str_replace('_', '-', $encoding)); - return $scm->diff('', $fromProject, $toProject, $parse = true, $fromProject); + return $scm->diff('', $MR->sourceBranch, $MR->targetBranch, $parse = true, $MR->sourceProject); } /** From 154662d760f141a1d11f807cbafaa5b7dee1339f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 15:05:09 +0800 Subject: [PATCH 148/154] * Disable diff in MR feature. --- module/mr/view/browse.html.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 469ebf1e91..7d79d57109 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -56,7 +56,8 @@ id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); common::printLink('mr', 'edit', "mr={$MR->id}", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); - common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'"); + /* Function diff is not ready yet. so comment it. */ + //common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'"); common::printLink('mr', 'delete', "mr={$MR->id}", '', '', "title='{$lang->mr->delete}' class='btn btn-info'"); ?> From 4e08891ea9b4a80e3b8f04b1eebc49020c0ea6c6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 15:46:40 +0800 Subject: [PATCH 149/154] * Optimize comment. --- module/mr/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/mr/control.php b/module/mr/control.php index b08684f9b7..a8af1e0793 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -206,7 +206,7 @@ class mr extends control { $this->loadModel('gitlab'); - /* First step: get forks. */ + /* First step: get forks. Only get first level forks(not recursively). */ $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); /* Second step: get project itself. */ From 8d6ad937272cdc0c2ce7c1bf3cebda1d7685d81f Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 7 Sep 2021 16:13:52 +0800 Subject: [PATCH 150/154] * Add gitlab browse to resoure list. --- module/group/lang/resource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 3f042726ef..b006caa837 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1133,6 +1133,7 @@ $lang->svn->methodOrder[15] = 'apiSync'; /* GitLab. */ $lang->resource->gitlab = new stdclass(); +$lang->resource->gitlab->browse = 'browse'; $lang->resource->gitlab->create = 'create'; $lang->resource->gitlab->edit = 'edit'; $lang->resource->gitlab->importIssue = 'importIssue'; From 74d6b1895ae5ed087a0a991af4d4a1b158c8a672 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 18:12:01 +0800 Subject: [PATCH 151/154] * Update accept MR display style. --- module/mr/control.php | 4 +++- module/mr/js/view.js | 17 +++++++++++++++++ module/mr/view/view.html.php | 4 +++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 module/mr/js/view.js diff --git a/module/mr/control.php b/module/mr/control.php index a8af1e0793..e413e822f1 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -185,7 +185,9 @@ class mr extends control } if(isset($rawMR->state) and $rawMR->state == 'merged') { - return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse'))); + /* Force reload when locate to the url. */ + $random = uniqid(); + return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse', "random={$random}"))); } /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ diff --git a/module/mr/js/view.js b/module/mr/js/view.js new file mode 100644 index 0000000000..f75fc67687 --- /dev/null +++ b/module/mr/js/view.js @@ -0,0 +1,17 @@ +$(document).ready(function() + { + $('#mergeButton').click(function() + { + link = $(this).attr('href'); + $.getJSON(link, function(response) + { + if(response.result == 'success') + { + $.zui.messager.success(response.message); + setTimeout(function(){ location.href=response.locate }, 2500); + } + if(response.result == 'fail') $.zui.messager.danger(response.message); + }); + return false; + }); + }); diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index 89cada7c09..cbc02d1221 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -60,6 +60,8 @@

- state == 'opened' and !$rawMR->has_conflicts) echo html::linkButton(' ' . $lang->mr->acceptMR, inlink( 'accept', "mr=$MR->id"), 'self', '', 'btn btn-wide btn-primary');?> + state == 'opened' and !$rawMR->has_conflicts):?> + id"), ' ' . $lang->mr->acceptMR, '', "id='mergeButton' class='btn btn-wide btn-primary'");?> + From 6de75d2fcb066d8eb528c2fb497a00ddb4ec71f9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 20:17:31 +0800 Subject: [PATCH 152/154] * Fix bug for sync mr. --- module/mr/control.php | 2 +- module/mr/model.php | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index e413e822f1..8798eabf5d 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -22,7 +22,7 @@ class mr extends control $this->session->set('mrList', $this->app->getURI(true), 'repo'); /* Sync GitLab MR to ZenTao Database. */ - $this->mr->batchSyncMR($MRList); + $MRList = $this->mr->batchSyncMR($MRList); $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; $this->view->MRList = $MRList; diff --git a/module/mr/model.php b/module/mr/model.php index 044a68583e..fd4f449500 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -32,7 +32,7 @@ class mrModel extends model */ public function getByID($id) { - return $this->dao->select('*')->from(TABLE_MR)->where('id')->eq($id)->fetch(); + return $this->dao->findByID($id)->from(TABLE_MR)->fetch(); } /** @@ -234,8 +234,9 @@ class mrModel extends model */ public function batchSyncMR($MRList) { - if(!empty($MRList)) foreach($MRList as $MR) + if(!empty($MRList)) foreach($MRList as $key => $MR) { + if($MR->status != 'opened') continue; $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); if(isset($rawMR->iid)) { @@ -267,10 +268,16 @@ class mrModel extends model } /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($newMR) - ->where('id')->eq($MR->id) - ->exec(); + ->where('id')->eq($MR->id) + ->exec(); + + /* Refetch MR in Zentao database. */ + $MR = $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch(); + $MRList[$key] = $MR; } } + + return $MRList; } /** @@ -290,9 +297,9 @@ class mrModel extends model foreach($todoList as $do) { $todoDesc = $this->dao->select('*') - ->from(TABLE_TODO) - ->where('idvalue')->eq($do->id) - ->fetch(); + ->from(TABLE_TODO) + ->where('idvalue')->eq($do->id) + ->fetch(); if(empty($todoDesc)) { $todo = new stdClass; From b1e05cd0f34535ac1707ab5b1820183b524c533e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 20:18:50 +0800 Subject: [PATCH 153/154] * Adjust display style. --- module/mr/view/browse.html.php | 12 +++++------- module/mr/view/create.html.php | 2 +- module/mr/view/edit.html.php | 12 +++++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 7d79d57109..45cc7ecb4c 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -31,14 +31,13 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> mr->id); ?> - mr->name); ?> - mr->sourceProject); ?> + mr->name); ?> + mr->sourceProject); ?> mr->sourceBranch); ?> - mr->targetProject); ?> + mr->targetProject); ?> mr->targetBranch); ?> - mr->status); ?> mr->mergeStatus); ?> - actions; ?> + actions; ?> @@ -50,8 +49,7 @@ sourceBranch;?> loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject)->name_with_namespace; ?> targetBranch;?> - mr->statusList, $MR->status);?> - mr->mergeStatusList, $MR->mergeStatus);?> + status == 'merged') ? zget($lang->mr->statusList, $MR->status) : zget($lang->mr->mergeStatusList, $MR->mergeStatus); ?> id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 3a745ff6e9..53489e179a 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -63,7 +63,7 @@ - + goback, '', 'class="btn btn-wide"');?> diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index c167084c52..48541919ed 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -24,10 +24,11 @@ mr->sourceProject;?> -
- loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject)->name_with_namespace; ?> - mr->sourceBranch ?> +
+ + loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject)->name_with_namespace; ?>: sourceBranch;?> +
@@ -35,8 +36,9 @@ mr->targetProject;?>
+ loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject)->name_with_namespace;?> - mr->targetBranch ?> + targetBranch, "class='form-control chosen'");?>
@@ -63,7 +65,7 @@ - + goback, '', 'class="btn btn-wide"');?> From 448d1423a6cae5e1cb1440d6352159c579e93bb8 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 7 Sep 2021 20:33:04 +0800 Subject: [PATCH 154/154] + Add SQL file for update version 15.4 . --- db/update15.4.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/update15.4.sql diff --git a/db/update15.4.sql b/db/update15.4.sql new file mode 100644 index 0000000000..738239d177 --- /dev/null +++ b/db/update15.4.sql @@ -0,0 +1,22 @@ +CREATE TABLE `zt_mr` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `gitlabID` mediumint(8) unsigned NOT NULL, + `sourceProject` int unsigned NOT NULL, + `sourceBranch` varchar(100) NOT NULL, + `targetProject` int unsigned NOT NULL, + `targetBranch` varchar(100) NOT NULL, + `mriid` int unsigned NOT NULL, + `title` varchar(255) NOT NULL, + `description` text NOT NULL, + `assignee` varchar(255) NOT NULL, + `reviewer` varchar(255) NOT NULL, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) NOT NULL, + `editedDate` datetime NOT NULL, + `deleted` tinyint(1) NOT NULL, + `status` char(30) NOT NULL, + `mergeStatus` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +