From a5ceffb6cf67278170ef3fb990c291712fed11d2 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 6 Sep 2021 17:29:37 +0800 Subject: [PATCH] * 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'"); ?>