From 8a6ef83c499ae009459558747b842fd7991ea51a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 24 Aug 2021 17:35:17 +0800 Subject: [PATCH 1/2] + 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 2/2] * 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);?>
+
+
+ + +