From cdbff35897d077e98a0898ea11876076a19adb1d Mon Sep 17 00:00:00 2001 From: liyuchun Date: Wed, 22 Dec 2021 16:12:03 +0800 Subject: [PATCH] * Code for task #46003. --- module/mr/config.php | 2 +- module/mr/control.php | 19 +++++++++++--- module/mr/model.php | 51 ++++++++++++++++++++---------------- module/mr/view/view.html.php | 12 +++++---- 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index e3c53e3e05..2a9bce4d56 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -13,7 +13,7 @@ $config->mr->editor = new stdclass(); $config->mr->editor->diff = array('id' => 'commentText', 'tools' => 'simpleTools'); $config->mr->apicreate = new stdclass(); -$config->mr->apicreate->requiredFields = 'repoID,sourceBranch,targetBranch,diffs,mergeStatus,hasNoConflict'; +$config->mr->apicreate->requiredFields = 'repoID,sourceBranch,targetBranch,mergeStatus'; $config->mr->maps = new stdclass; $config->mr->maps->sync = array(); diff --git a/module/mr/control.php b/module/mr/control.php index b62d4e450a..910242bcb9 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -94,8 +94,19 @@ class mr extends control { if($_POST) { - $result = $this->mr->apiCreate(); - return $this->send($result); + $this->mr->apiCreate(); + + if(dao::isError()) + { + $response['result'] = 'fail'; + $response['message'] = dao::getError(); + } + else + { + $response['result'] = 'success'; + $response['message'] = ''; + } + return $this->send($response); } } @@ -198,7 +209,7 @@ class mr extends control $MR = $this->mr->getByID($id); if(!$MR) die(js::error($this->lang->notFound) . js::locate($this->createLink('mr', 'browse'))); if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); - if(!isset($rawMR->id) or (isset($rawMR->message) and $rawMR->message == '404 Not found') or empty($rawMR)) return $this->display(); + if($MR->synced and (!isset($rawMR->id) or (isset($rawMR->message) and $rawMR->message == '404 Not found') or empty($rawMR))) return $this->display(); $MR = $this->mr->apiSyncMR($MR); /* Sync MR from GitLab to ZentaoPMS. */ $this->loadModel('gitlab'); @@ -214,7 +225,7 @@ class mr extends control /* 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->view->branchPath = $sourceProject->path_with_namespace . '-' . $MR->sourceBranch; /* Get mr linked list. */ $this->app->loadLang('productplan'); diff --git a/module/mr/model.php b/module/mr/model.php index 301abb55ee..be15b7dbc8 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -186,30 +186,33 @@ class mrModel extends model */ public function apiCreate() { - $postData = fixer::input('post') - ->setDefault('repoUrl,repoSrcBranch,repoDistBranch,diffMsg,mergeStatus,hasNoConflict', '') - ->get(); + $postData = fixer::input('post')->get(); + $postData = (object)$postData->data; - $repo = $this->loadModel('repo')->getRepoByUrl($postData->repoUrl); - if(!$repo || $repo->result != 'fail') return false; - $repo = (object)$repo->data; + $repo = $this->loadModel('repo')->getRepoByUrl($postData->RepoUrl); + if(empty($repo['data'])) + { + dao::$errors[] = $repo['message']; + return false; + } + $repo = $repo['data']; /* Process and insert mr data. */ $MR = new stdClass(); $MR->gitlabID = $repo->client; $MR->sourceProject = $repo->path; - $MR->sourceBranch = $postData->repoSrcBranch; + $MR->sourceBranch = $postData->RepoSrcBranch; $MR->targetProject = $repo->path; - $MR->targetBranch = $postData->repoDistBranch; - $MR->diffs = $postData->diffMsg; + $MR->targetBranch = $postData->RepoDistBranch; + $MR->diffs = $postData->DiffMsg; $MR->title = 'Merge request'; $MR->repoID = $repo->id; - $MR->jobID = $repo->job; + $MR->jobID = isset($repo->job->id) ? $repo->job->id : 0; $MR->synced = '0'; $MR->needCI = '1'; $MR->approvalStatus = 'approved'; - $MR->hasNoConflict = $postData->hasNoConflict ? '1' : '0'; - $MR->mergeStatus = $postData->mergeStatus ? 'can_be_merged' : 'cannot_be_merged'; + $MR->hasNoConflict = $postData->MergeStatus ? '0' : '1'; + $MR->mergeStatus = $postData->MergeStatus ? 'can_be_merged' : 'cannot_be_merged'; $MR->createdBy = $this->app->user->account; $MR->createdDate = date('Y-m-d H:i:s'); @@ -221,24 +224,28 @@ class mrModel extends model if(dao::isError()) return false; /* Exec Job */ - if($MR->hasNoConflict == '1' && $MR->mergeStatus == 'can_be_merged' && $MR->jobID) + if($MR->hasNoConflict == '0' && $MR->mergeStatus == 'can_be_merged' && $MR->jobID) { $MRID = $this->dao->lastInsertId(); $pipeline = $this->loadModel('job')->exec($MR->jobID); + $newMR = new stdClass(); if(!empty($pipeline->queue)) { - $newMR = new stdClass(); $compile = $this->loadModel('compile')->getByQueue($pipeline->queue); - $newMR->compileID = $compile->id; + $newMR->compileID = $compile->id; $newMR->compileStatus = $compile->status; - - /* Update MR in Zentao database. */ - $this->dao->update(TABLE_MR)->data($newMR) - ->where('id')->eq($MRID) - ->autoCheck() - ->exec(); - if(dao::isError()) return false; } + else + { + $newMR->compileStatus = $pipeline->status; + } + + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($newMR) + ->where('id')->eq($MRID) + ->autoCheck() + ->exec(); + if(dao::isError()) return false; } return true; } diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index 55bf2c2f1c..e877880fa2 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -11,7 +11,7 @@ -id)): ?> +synced and (empty($rawMR) or !isset($rawMR->id))): ?>

@@ -28,7 +28,9 @@

id ?> title; ?> + synced):?> web_url, $lang->mr->viewInGitlab, "_blank", "class='btn btn-link btn-active-text' style='color: blue'"); ?> +
@@ -90,7 +92,7 @@ - state == 'opened'): ?> + synced and $rawMR->state == 'opened'): ?>
mr->commandDocument, $httpRepoURL, $MR->sourceBranch, $branchPath, $MR->targetBranch, $branchPath, $MR->targetBranch); ?>
@@ -98,8 +100,8 @@
approvalStatus != 'approved' or ($MR->compileID != 0 and $MR->compileStatus != 'success')) ? ' disabled' : ''; ?> - state == 'opened' and !$rawMR->has_conflicts) common::printIcon('mr', 'accept', "mr=$MR->id", $MR, 'button', 'flow', 'hiddenwin', 'mergeButton btn', false, $acceptDisabled, $lang->mr->acceptMR);?> - state == 'opened'): ?> + synced and $rawMR->state == 'opened' and !$rawMR->has_conflicts) common::printIcon('mr', 'accept', "mr=$MR->id", $MR, 'button', 'flow', 'hiddenwin', 'mergeButton btn', false, $acceptDisabled, $lang->mr->acceptMR);?> + synced and $rawMR->state == 'opened'): ?> has_conflicts or ($MR->compileID != 0 and $MR->compileStatus != 'success') or $MR->approvalStatus == 'approved'):?> id&action=approve", $MR, 'button', 'ok', 'hiddenwin', 'mergeButton', true, 'disabled', $lang->mr->approve);?> @@ -109,7 +111,7 @@ id", $MR, 'button', 'off', 'hiddenwin', 'mergeButton');?> id", $MR, 'button', 'edit');?> - state == 'closed') common::printIcon('mr', 'reopen', "mr=$MR->id", $MR, 'button', 'restart', 'hiddenwin', 'mergeButton'); ?> + synced and $rawMR->state == 'closed') common::printIcon('mr', 'reopen', "mr=$MR->id", $MR, 'button', 'restart', 'hiddenwin', 'mergeButton'); ?> id", $MR, 'button', 'trash', 'hiddenwin');?>