diff --git a/module/gitlab/config.php b/module/gitlab/config.php index d4dfc228f9..9cd8d1da48 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -16,7 +16,8 @@ $config->gitlab->actions['issue'] = array(); $config->gitlab->zentaoObjectLabel = new stdclass; $config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; $config->gitlab->zentaoObjectLabel->description = "%s"; -$config->gitlab->zentaoObjectLabel->color = new stdclass; + +$config->gitlab->zentaoObjectLabel->color = new stdclass; $config->gitlab->zentaoObjectLabel->color->task = '#0033CC'; $config->gitlab->zentaoObjectLabel->color->story = '#69D100'; $config->gitlab->zentaoObjectLabel->color->bug = '#D10069'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0d1e7f9ccc..f55fcb0c37 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -770,7 +770,7 @@ class gitlabModel extends model { $label = new stdclass; $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; + $label->color = $this->config->gitlab->zentaoObjectLabel->color->$objectType; $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "id={$objectID}"); return $this->apiCreateLabel($gitlabID, $projectID, $label); @@ -816,7 +816,7 @@ class gitlabModel extends model * @access public * @return bool */ - public function createWebhook($products, $gitlabID, $projectID) + public function initWebhooks($products, $gitlabID, $projectID) { $gitlab = $this->getByID($gitlabID); $webhooks = $this->apiGetHooks($gitlabID, $projectID); @@ -844,19 +844,14 @@ class gitlabModel extends model { $object = $this->loadModel($objectType)->getByID($objectID); if(empty($object)) return false; - if(!$gitlabID or !$projectID) - { - $result = $this->getRelationByObject($objectType, $objectID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } + if(!$gitlabID or !$projectID) return false; $syncedIssue = $this->getRelationByObject($objectType, $objectID); $issue = $this->parseObjectToIssue($gitlabID, $projectID, $object, $objectType); if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->issueID, $issue); $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = $label->name; + $issue->labels = isset($label->name) ? '' :$label->name; $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); @@ -936,7 +931,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - if($issue->assignee_id == 'closed') unset($issue->assignee_id); + if($isset($issue->assignee_id) and $issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; @@ -1075,7 +1070,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - if($issue->assignee_id == 'closed') unset($issue->assignee_id); + if(isset($issue->assignee_id) and $issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; diff --git a/module/repo/model.php b/module/repo/model.php index 463dc12510..bccba49194 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -235,7 +235,7 @@ class repoModel extends model $this->loadModel("gitlab")->saveProjectRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); /* create webhook for zentao */ - $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->initWebhooks($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); } return $this->dao->lastInsertID(); } @@ -298,7 +298,7 @@ class repoModel extends model { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($id)->exec(); - if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->initWebhooks($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); return false; } diff --git a/module/story/model.php b/module/story/model.php index 153d6473db..dc9b65c26f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -441,7 +441,6 @@ class storyModel extends model dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->story->$field); return false; } - $data[$i] = $story; } diff --git a/module/task/model.php b/module/task/model.php index ddf4aea17e..ae519d1816 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -380,6 +380,10 @@ class taskModel extends model if(dao::isError()) return false; $taskID = $this->dao->lastInsertID(); + + /* Sync this task to gitlab issue. */ + $this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject); + $taskSpec = new stdClass(); $taskSpec->task = $taskID; $taskSpec->version = $task->version; @@ -1791,7 +1795,7 @@ class taskModel extends model } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); if(!dao::isError()) return common::createChanges($oldTask, $task); diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 53b185d58a..7dd700b77c 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -4991,4 +4991,30 @@ class upgradeModel extends model $this->dao->update(TABLE_PRODUCT)->set('createdVersion')->eq($this->config->version)->where('createdVersion')->eq('')->exec(); return true; } + + public function processGitlabRepo() + { + $repoList = $this->dao->select('*')->from(TABLE_REPO)->where('SCM')->eq('Gitlab')->fetchAll(); + foreach($repoList as $repo) + { + /* Create gitlab from repo. */ + $gitlab = new stdclass; + $gitlab->type = 'gitlab'; + $gitlab->name = $repo->client; + $gitlab->token = base64_decode($repo->password); + $gitlab->private = md5(uniqid()); + $this->dao->insert(TABLE_PIPELINE)->data($gitlab)->exec(); + + $gitlabID = $this->dao->lastInsertID(); + + preg_match('/projects\/(\d+)\/repository/', $repo->path, $matches); + $gitlabProject = $matches[1]; + $products = explode(',', $repo->product); + $this->loadModel('gitlab')->saveProjectRelation($products, $gitlabID, $gitlabProject); + + $this->dao->update(TABLE_REPO)->set('client')->eq($gitlabID)->set('path')->eq($gitlabProject)->where('id')->eq($repo->id)->exec(); + + $this->loadModel("gitlab")->initWebhooks($products, $gitlabID, $gitlabProject); + } + } }