* Add sync bug to issue.
This commit is contained in:
@@ -557,6 +557,13 @@ class bug extends control
|
||||
$this->view->customFields = $customFields;
|
||||
$this->view->showFields = $this->config->bug->custom->createFields;
|
||||
|
||||
/* Set gitlabProjects. */
|
||||
$allGitlabs = $this->loadModel('gitlab')->getPairs();
|
||||
$gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID);
|
||||
foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]);
|
||||
$this->view->gitlabList = $allGitlabs;
|
||||
$this->view->gitlabProjects = $gitlabProjects;
|
||||
|
||||
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->create;
|
||||
$this->view->position[] = html::a($this->createLink('bug', 'browse', "productID=$productID"), $this->products[$productID]);
|
||||
$this->view->position[] = $this->lang->bug->create;
|
||||
|
||||
@@ -155,3 +155,23 @@ $(function()
|
||||
$(window).unload(function(){
|
||||
if(blockID) window.parent.refreshBlock($('#block' + blockID));
|
||||
});
|
||||
|
||||
$(document).ready(function()
|
||||
{
|
||||
$('#gitlab').change(function()
|
||||
{
|
||||
host = $('#gitlab').val();
|
||||
if(host == '') return false;
|
||||
projects = '';
|
||||
$.each(gitlabProjects[host], function(id, obj){projects = projects + ',' + obj.gitlabProject});
|
||||
url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + "&projects=" + projects);
|
||||
|
||||
$.get(url, function(response)
|
||||
{
|
||||
$('#gitlabProject').html('').append(response);
|
||||
$('#gitlabProject').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -24,6 +24,7 @@ $lang->bug->storyVersion = "{$lang->SRCommon}版本";
|
||||
$lang->bug->color = '标题颜色';
|
||||
$lang->bug->task = '相关任务';
|
||||
$lang->bug->title = 'Bug标题';
|
||||
$lang->bug->sync2gitlab = '同步gitlab';
|
||||
$lang->bug->severity = '严重程度';
|
||||
$lang->bug->severityAB = '级别';
|
||||
$lang->bug->pri = '优先级';
|
||||
|
||||
@@ -84,10 +84,14 @@ class bugModel extends model
|
||||
/* Use classic mode to replace required project. */
|
||||
if($this->config->systemMode == 'classic' and strpos($this->config->bug->create->requiredFields, 'project') !== false) $this->config->bug->create->requiredFields = str_replace('project', 'execution', $this->config->bug->create->requiredFields);
|
||||
|
||||
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
|
||||
$this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
|
||||
if(!dao::isError())
|
||||
{
|
||||
$bugID = $this->dao->lastInsertID();
|
||||
|
||||
/* Sync this bug to gitlab issue. */
|
||||
$this->loadModel('gitlab')->syncBug($bugID, $this->post->gitlab, $this->post->gitlabProject);
|
||||
|
||||
$this->file->updateObjectID($this->post->uid, $bugID, 'bug');
|
||||
$this->file->saveUpload('bug', $bugID);
|
||||
empty($bug->case) ? $this->loadModel('score')->create('bug', 'create', $bugID) : $this->loadModel('score')->create('bug', 'createFormCase', $bug->case);
|
||||
|
||||
@@ -26,6 +26,7 @@ js::set('isStepsTemplate', $isStepsTemplate);
|
||||
js::set('oldProjectID', $projectID);
|
||||
js::set('blockID', $blockID);
|
||||
js::set('moduleID', $moduleID);
|
||||
js::set('gitlabProjects', $gitlabProjects);
|
||||
?>
|
||||
<div id="mainContent" class="main-content fade">
|
||||
<div class="center-block">
|
||||
@@ -312,6 +313,13 @@ js::set('moduleID', $moduleID);
|
||||
<?php endif;?>
|
||||
</tr>
|
||||
<?php endif;?>
|
||||
<?php if(!empty($gitlabProjects)):?>
|
||||
<tr>
|
||||
<th><?php echo $lang->task->sync2Gitlab;?></th>
|
||||
<td><?php echo html::select('gitlab', $gitlabList, '', "class='form-control chosen'");?></td>
|
||||
<td><?php echo html::select('gitlabProject', '', '', "class='form-control chosen'");?></td>
|
||||
</tr>
|
||||
<?php endif;?>
|
||||
<tr class='hide'>
|
||||
<th><?php echo $lang->bug->status;?></th>
|
||||
<td><?php echo html::hidden('status', 'active');?></td>
|
||||
|
||||
@@ -2230,7 +2230,6 @@ EOD;
|
||||
}
|
||||
|
||||
if($options) curl_setopt_array($curl, $options);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$errors = curl_error($curl);
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ class gitlab extends control
|
||||
|
||||
public function test($id = 11)
|
||||
{
|
||||
$gitlabID = 11; $projectID = 36;
|
||||
$gitlabID = 1; $projectID = 7;
|
||||
$task = $this->loadModel('task')->getByID($id);
|
||||
$issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task);
|
||||
$issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue);
|
||||
|
||||
@@ -580,6 +580,30 @@ class gitlabModel extends model
|
||||
if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync bug to gitlab issue.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @param int $gitlab
|
||||
* @param int $gitlabProject
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function syncBug($bugID, $gitlab, $gitlabProject)
|
||||
{
|
||||
$bug = $this->loadModel('bug')->getByID($bugID);
|
||||
|
||||
$syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab);
|
||||
$issue = $this->bugToIssue($gitlab, $gitlabProject, $bug);
|
||||
|
||||
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID);
|
||||
$issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $storyID);
|
||||
|
||||
if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
|
||||
$issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue);
|
||||
if($issue) $this->saveSyncedIssue('bug', $story, $gitlab, $issue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get synced issue from relation table.
|
||||
*
|
||||
@@ -690,6 +714,43 @@ class gitlabModel extends model
|
||||
return $issue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse bug to issue.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $gitlabProjectID
|
||||
* @param object $story
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function bugToIssue($gitlabID, $gitlabProjectID, $bug)
|
||||
{
|
||||
$map = $this->config->gitlab->maps->bug;
|
||||
$issue = new stdclass;
|
||||
$gitlabUsers = $this->getUserAccountIdPairs($gitlabID);
|
||||
if(empty($gitlabUsers)) return false;
|
||||
|
||||
foreach($map as $storyField => $config)
|
||||
{
|
||||
$value = '';
|
||||
list($field, $optionType, $options) = explode('|', $config);
|
||||
if($optionType == 'field') $value = $bug->$bugField;
|
||||
if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $story->$options;
|
||||
if($optionType == 'userPairs')
|
||||
{
|
||||
$value = zget($gitlabUsers, $story->$bugField);
|
||||
}
|
||||
if($optionType == 'configItems')
|
||||
{
|
||||
$value = zget($this->config->gitlab->$options, $bug->$bugField, '');
|
||||
}
|
||||
if($value) $issue->$field = $value;
|
||||
}
|
||||
|
||||
var_dump($issue);die;
|
||||
return $issue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api create issue.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user