Merge branch 'cyy_bug' into 'zenops_41'

Cyy bug

See merge request easycorp/zentaopms!4965
This commit is contained in:
李玉春
2022-08-15 02:29:03 +00:00
4 changed files with 42 additions and 2 deletions
+16
View File
@@ -2879,4 +2879,20 @@ class gitlabModel extends model
$html .= '</div>';
return $html;
}
/**
* Get pipeline with api.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @access public
* @return object|array
*/
public function apiGetPipeline($gitlabID, $projectID, $branch)
{
$apiRoot = $this->getApiRoot($gitlabID);
$url = sprintf($apiRoot, "/projects/$projectID/pipelines") . "&ref=$branch";
return json_decode(commonModel::http($url));
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$config->jenkins->create = new stdclass();
$config->jenkins->edit = new stdclass();
$config->jenkins->create->requiredFields = 'name,url';
$config->jenkins->edit->requiredFields = 'name,url';
$config->jenkins->create->requiredFields = 'name,url,account';
$config->jenkins->edit->requiredFields = 'name,url,account';
+18
View File
@@ -181,6 +181,15 @@ class jobModel extends model
{
$repo = $this->loadModel('repo')->getRepoByID($job->repo);
$project = zget($repo, 'project');
if(!empty($repo))
{
$pipeline = $this->loadModel('gitlab')->apiGetPipeline($repo->serviceHost, $repo->serviceProject, $this->post->reference);
if(!is_array($pipeline) or empty($pipeline))
{
dao::$errors['repo'] = $this->lang->job->engineTips->error;
return false;
}
}
$job->server = (int)zget($repo, 'serviceHost', 0);
$job->pipeline = json_encode(array('project' => $project, 'reference' => $this->post->reference));
@@ -298,6 +307,15 @@ class jobModel extends model
{
$repo = $this->loadModel('repo')->getRepoByID($job->gitlabRepo);
$project = zget($repo, 'project');
if(!empty($repo))
{
$pipeline = $this->loadModel('gitlab')->apiGetPipeline($repo->serviceHost, $repo->serviceProject, $this->post->reference);
if(!is_array($pipeline) or empty($pipeline))
{
dao::$errors['repo'] = $this->lang->job->engineTips->error;
return false;
}
}
$job->repo = $job->gitlabRepo;
$job->server = (int)zget($repo, 'serviceHost', 0);
+6
View File
@@ -87,6 +87,9 @@ class pipelineModel extends model
->batchCheck($this->config->pipeline->create->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->check('name', 'unique', "`type` = '$type'")
->checkIF($type == 'jenkins', 'account', 'notempty')
->checkIF($type == 'jenkins' and !$pipeline->token, 'password', 'notempty')
->checkIF($type == 'jenkins' and !$pipeline->password, 'token', 'notempty')
->autoCheck()
->exec();
if(dao::isError()) return false;
@@ -118,6 +121,9 @@ class pipelineModel extends model
->batchCheck($this->config->pipeline->edit->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->check('name', 'unique', "`type` = '$type' and id <> $id")
->checkIF($type == 'jenkins', 'account', 'notempty')
->checkIF($type == 'jenkins' and !$pipeline->token, 'password', 'notempty')
->checkIF($type == 'jenkins' and !$pipeline->password, 'token', 'notempty')
->autoCheck()
->where('id')->eq($id)
->exec();