@@ -312,6 +313,13 @@ js::set('moduleID', $moduleID); + + + task->sync2Gitlab;?> + + + + bug->status;?> diff --git a/module/common/model.php b/module/common/model.php index 242e393959..03a0fe0b96 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -2230,7 +2230,6 @@ EOD; } if($options) curl_setopt_array($curl, $options); - $response = curl_exec($curl); $errors = curl_error($curl); diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 95120075f8..91e2b57aa6 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -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); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index c91272bf39..89951b3aab 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -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); + sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); + + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); + } + /** * Get synced issue from relation table. * @@ -690,6 +714,42 @@ 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 $bugField => $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, $bug->$bugField); + } + if($optionType == 'configItems') + { + $value = zget($this->config->gitlab->$options, $bug->$bugField, ''); + } + if($value) $issue->$field = $value; + } + + return $issue; + } + /** * Api create issue. *