* Add compile status of job when creating a MR.

This commit is contained in:
dingguodong
2021-11-09 12:10:03 +08:00
parent 65d9c524bb
commit efb3a369c8
9 changed files with 213 additions and 48 deletions
+4
View File
@@ -664,6 +664,10 @@ CREATE TABLE IF NOT EXISTS `zt_mr` (
`status` char(30) NOT NULL,
`mergeStatus` char(30) NOT NULL,
`approvalStatus` char(30) NOT NULL,
`repoID` mediumint(8) unsigned NOT NULL,
`jobID` mediumint(8) unsigned NOT NULL,
`compileID` mediumint(8) unsigned NOT NULL,
`compileStatus` char(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- DROP TABLE IF NOT EXISTS `zt_mrapproval`;
+16
View File
@@ -45,6 +45,22 @@ class compileModel extends model
->page($pager)
->fetchAll('id');
}
/**
* Get list by jobID.
*
* @param int $jobID
* @return array
*/
public function getListByJobID($jobID)
{
return $this->dao->select('id, name, status')->from(TABLE_COMPILE)
->where('deleted')->eq('0')
->andWhere('job')->ne('0')
->beginIF(!empty($jobID))->andWhere('job')->eq($jobID)->fi()
->orderBy('id_desc')
->fetchAll('id');
}
/**
* Get unexecuted list.
+17 -1
View File
@@ -50,7 +50,23 @@ class jobModel extends model
->fetchAll('id');
}
/**
/**
* Get job list by RepoID.
*
* @param int $repoID
* @access public
* @return array
*/
public function getListByRepoID($repoID)
{
return $this->dao->select('id, name, lastStatus')->from(TABLE_JOB)
->where('deleted')->eq('0')
->andWhere('repo')->eq($repoID)
->orderBy('id_desc')
->fetchAll('id');
}
/**
* Get list by triggerType field.
*
* @param string $triggerType
+1 -1
View File
@@ -2,7 +2,7 @@
$config->mr = new stdclass();
$config->mr->create = new stdclass();
$config->mr->create->skippedFields = 'projectID';
$config->mr->create->skippedFields = 'projectID,repo,job,compile';
$config->mr->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title';
$config->mr->edit = new stdclass;
+95 -40
View File
@@ -66,7 +66,10 @@ class mr extends control
return $this->send($result);
}
$this->app->loadLang('repo'); /* Import lang in repo module. */
$this->app->loadLang('compile');
$this->view->title = $this->lang->mr->create;
$this->view->jobList = $this->loadModel('job')->getList();
$this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
$this->display();
}
@@ -219,46 +222,6 @@ class mr extends control
return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}")));
}
/**
* AJAX: Get MR target projects.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function ajaxGetMRTargetProjects($gitlabID, $projectID)
{
$this->loadModel('gitlab');
/* First step: get forks. Only get first level forks(not recursively). */
$projects = $this->gitlab->apiGetForks($gitlabID, $projectID);
/* Second step: get project itself. */
$projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
/* Last step: find its upstream recursively. */
$project = $this->gitlab->apiGetUpstream($gitlabID, $projectID);
if(!empty($project)) $projects[] = $project;
while(!empty($project) and isset($project->id))
{
$project = $this->gitlab->apiGetUpstream($gitlabID, $project->id);
if(empty($project)) break;
$projects[] = $project;
}
if(!$projects) return $this->send(array('message' => array()));
$options = "<option value=''></option>";
foreach($projects as $project)
{
$options .= "<option value='{$project->id}' data-name='{$project->name}'>{$project->name_with_namespace}</option>";
}
$this->send($options);
}
/**
* View diff between MR source and target branches.
*
@@ -374,4 +337,96 @@ class mr extends control
$MR = $this->mr->getByID($MRID);
return $this->send($this->mr->reopen($MR));
}
/**
* AJAX: Get MR target projects.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function ajaxGetMRTargetProjects($gitlabID, $projectID)
{
$this->loadModel('gitlab');
/* First step: get forks. Only get first level forks(not recursively). */
$projects = $this->gitlab->apiGetForks($gitlabID, $projectID);
/* Second step: get project itself. */
$projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
/* Last step: find its upstream recursively. */
$project = $this->gitlab->apiGetUpstream($gitlabID, $projectID);
if(!empty($project)) $projects[] = $project;
while(!empty($project) and isset($project->id))
{
$project = $this->gitlab->apiGetUpstream($gitlabID, $project->id);
if(empty($project)) break;
$projects[] = $project;
}
if(!$projects) return $this->send(array('message' => array()));
$options = "<option value=''></option>";
foreach($projects as $project)
{
$options .= "<option value='{$project->id}' data-name='{$project->name}'>{$project->name_with_namespace}</option>";
}
$this->send($options);
}
/**
* AJAX: Get repo list.
*
* @param int $gitlabID
* @param int $projectID
* @return void
*/
public function ajaxGetRepoList($gitlabID, $projectID)
{
$this->loadModel('repo');
$repoList = $this->repo->getGitLabRepoList($gitlabID, $projectID);
if(!$repoList) return $this->send(array('message' => array()));
$options = "<option value=''></option>";
foreach($repoList as $repo) $options .= "<option value='{$repo->id}' data-name='{$repo->name}'>[{$repo->id}] {$repo->name}</option>";
$this->send($options);
}
/**
* AJAX: Get job list.
*
* @param int $repoID
* @return void
*/
public function ajaxGetJobList($repoID)
{
$this->loadModel('job');
$jobList = $this->job->getListByRepoID($repoID);
if(!$jobList) return $this->send(array('message' => array()));
$options = "<option value=''></option>";
foreach($jobList as $job) $options .= "<option value='{$job->id}' data-name='{$job->name}'>[{$job->id}] {$job->name}</option>";
$this->send($options);
}
/**
* AJAX: Get compile list.
*
* @param int $jobID
* @return void
*/
public function ajaxGetCompileList($jobID)
{
$this->loadModel('compile');
$compileList = $this->compile->getListByJobID($jobID);
if(!$compileList) return $this->send(array('message' => array()));
$options = "<option value=''></option>";
foreach($compileList as $compile) $options .= "<option value='{$compile->id}' data-name='{$compile->name}'>[{$compile->id}] [{$compile->status}] {$compile->name}</option>";
$this->send($options);
}
}
+28
View File
@@ -35,6 +35,13 @@ $(function()
$('#targetProject').html('').append(response);
$('#targetProject').chosen().trigger("chosen:updated");;
});
repoUrl = createLink('mr', 'ajaxGetRepoList', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
$.get(repoUrl, function(response)
{
$('#repo').html('').append(response);
$('#repo').chosen().trigger("chosen:updated");;
});
});
$('#targetProject').change(function()
@@ -52,5 +59,26 @@ $(function()
});
});
$('#repo').change(function()
{
repoID = $(this).val();
jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
$.get(jobUrl, function(response)
{
$('#job').html('').append(response);
$('#job').chosen().trigger("chosen:updated");;
});
});
$('#job').change(function()
{
jobID = $(this).val();
compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
$.get(compileUrl, function(response)
{
$('#compile').html('').append(response);
$('#compile').chosen().trigger("chosen:updated");;
});
});
});
+23 -6
View File
@@ -85,10 +85,29 @@ class mrModel extends model
*/
public function create()
{
$MR = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->get();
if (!empty($_POST['compile']))
{
$repoID = $this->post->repo;
$jobID = $this->post->job;
$compileID = $this->post->compile;
$compileStatus = $this->loadModel('compile')->getByID($this->post->compile)->status;
$MR = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->add('repoID', $repoID)
->add('jobID', $jobID)
->add('compileID', $compileID)
->add('compileStatus', $compileStatus)
->get();
}
else
{
$MR = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->get();
}
$this->dao->insert(TABLE_MR)->data($MR, $this->config->mr->create->skippedFields)
->batchCheck($this->config->mr->create->requiredFields, 'notempty')
@@ -719,6 +738,4 @@ class mrModel extends model
if(isset($rawMR->state) and $rawMR->state == 'opened') return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'view', "mr={$MR->id}"));
return array('result' => 'fail', 'message' => $this->lang->fail, 'locate' => helper::createLink('mr', 'view', "mr={$MR->id}"));
}
}
+12
View File
@@ -50,6 +50,18 @@
<th><?php echo $lang->mr->description; ?></th>
<td colspan='1'><?php echo html::textarea('description', '', "rows='3' class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->devops->repo; ?></th>
<td colspan='1'><?php echo html::select('repo', array(''), '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->job->common; ?></th>
<td colspan='1'><?php echo html::select('job', array(''), '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->compile->result; ?></th>
<td colspan='1'><?php echo html::select('compile', array(''), '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->mr->assignee;?></th>
<td><?php echo html::select('assignee', array(''), '', "class='form-control chosen'")?></td>
+17
View File
@@ -1772,4 +1772,21 @@ class repoModel extends model
$repo->password = $gitlab->token;
return $repo;
}
/**
* Get repositories which scm is GitLab and specified gitlabID and projectID.
*
* @param int $gitlabID
* @param int $projectID
* @return array
*/
public function getGitLabRepoList($gitlabID, $projectID)
{
return $this->dao->select('*')->from(TABLE_REPO)->where('deleted')->eq('0')
->andWhere('SCM')->eq('Gitlab')
->andWhere('synced')->eq(1)
->andWhere('client')->eq($gitlabID)
->andWhere('path')->eq($projectID)
->fetchAll();
}
}