summaryrefslogtreecommitdiff
path: root/lib/gitlab/github_import/importer.rb
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-04-18 20:50:07 +0000
committerRobert Speicher <robert@gitlab.com>2016-04-18 20:50:07 +0000
commit17b60d681828567e47c8a62ef312abc46e2beeea (patch)
tree2714a8bc5f1b9a1f5665c26e00d23fd3b930b341 /lib/gitlab/github_import/importer.rb
parent387b025d15c3e0536d37128c282e02e9025dcd75 (diff)
parent696b1e965732e229f9b0f6f49297e78265379bb4 (diff)
downloadgitlab-ce-17b60d681828567e47c8a62ef312abc46e2beeea.tar.gz
Merge branch 'gh-import-labels' into 'master'
Import labels from GitHub Closes #15292 See merge request !3776
Diffstat (limited to 'lib/gitlab/github_import/importer.rb')
-rw-r--r--lib/gitlab/github_import/importer.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 0b1ed510229..7f70ab63f37 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -16,7 +16,7 @@ module Gitlab
end
def execute
- import_issues && import_pull_requests && import_wiki
+ import_labels && import_issues && import_pull_requests && import_wiki
end
private
@@ -25,6 +25,16 @@ module Gitlab
@import_data_credentials ||= project.import_data.credentials if project.import_data
end
+ def import_labels
+ client.labels(project.import_source).each do |raw_data|
+ Label.create!(LabelFormatter.new(project, raw_data).attributes)
+ end
+
+ true
+ rescue ActiveRecord::RecordInvalid => e
+ raise Projects::ImportService::Error, e.message
+ end
+
def import_issues
client.list_issues(project.import_source, state: :all,
sort: :created,
@@ -33,6 +43,7 @@ module Gitlab
if gh_issue.valid?
issue = Issue.create!(gh_issue.attributes)
+ apply_labels(gh_issue.number, issue)
if gh_issue.has_comments?
import_comments(gh_issue.number, issue)
@@ -55,6 +66,7 @@ module Gitlab
merge_request = MergeRequest.new(pull_request.attributes)
if merge_request.save
+ apply_labels(pull_request.number, merge_request)
import_comments(pull_request.number, merge_request)
import_comments_on_diff(pull_request.number, merge_request)
end
@@ -66,6 +78,18 @@ module Gitlab
raise Projects::ImportService::Error, e.message
end
+ def apply_labels(number, issuable)
+ issue = client.issue(project.import_source, number)
+
+ if issue.labels.count > 0
+ label_ids = issue.labels.map do |raw|
+ Label.find_by(LabelFormatter.new(project, raw).attributes).try(:id)
+ end
+
+ issuable.update_attribute(:label_ids, label_ids)
+ end
+ end
+
def import_comments(issue_number, noteable)
comments = client.issue_comments(project.import_source, issue_number)
create_comments(comments, noteable)