* Add manage reference of gitlab job function.

This commit is contained in:
Guan Xiying
2021-09-01 10:57:07 +08:00
parent 761c5d282e
commit ff83efb066
6 changed files with 84 additions and 13 deletions
+17
View File
@@ -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));
}
}
+20 -2
View File
@@ -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("<option value='" + reference + "'>" + name + "</option>");
});
}
$('#reference').trigger('chosen:updated');
});
}
});
$('#triggerType').change();
});
+21
View File
@@ -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("<option value='" + reference + "'>" + name + "</option>");
});
}
$('#reference').trigger('chosen:updated');
});
}
});
$('#engine').change();
$('#jkServer').change();
+21 -8
View File
@@ -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';
+3 -2
View File
@@ -48,7 +48,8 @@
</tr>
<tr class='gitlabRepo hide'>
<th><?php echo $lang->job->repo; ?></th>
<td><?php echo html::select('gitlabRepo', $gitlabRepos, '', "class='form-control'"); ?></td>
<td> <?php echo html::select('gitlabRepo', $gitlabRepos, '', "class='chosen form-control'");?> </td>
<td> <?php echo html::select('reference', array(), '', "class='chosen form-control'");?> </td>
</tr>
<tr>
<th><?php echo $lang->job->product; ?></th>
@@ -95,7 +96,7 @@
<div class='table-col'><?php echo html::select('jkServer', $jenkinsServerList, '', "class='form-control chosen'"); ?></div>
<div class='table-col'>
<div class='input-group'>
<span class='input-group-addon'><?php echo $lang->job->pipeline; ?></span>
<span class='input-group-addon'><?php echo $lang->job->pipeline;?></span>
<?php echo html::select('jkTask', array('' => ''), '', "class='form-control chosen'"); ?>
</div>
</div>
+2 -1
View File
@@ -43,7 +43,8 @@
</tr>
<tr class='gitlabRepo hide'>
<th><?php echo $lang->job->repo; ?></th>
<td><?php echo html::select('gitlabRepo', $gitlabRepos, $job->repo, "class='form-control'"); ?></td>
<td> <?php echo html::select('gitlabRepo', $gitlabRepos, $job->repo, "class='chosen form-control'");?> </td>
<td> <?php echo html::select('reference', $refList, $job->reference, "class='chosen form-control'");?> </td>
</tr>
<tr>
<th><?php echo $lang->job->product;?></th>