summaryrefslogtreecommitdiff
path: root/lib/gitlab/bitbucket_import/importer.rb
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-07 18:04:02 +0200
committerValery Sizov <valery@gitlab.com>2016-12-07 18:04:02 +0200
commit00cd864237d6c7ec57ecb49d304ca8dfa9e41d31 (patch)
tree2f1e369489f8bd9f1b2d4113b59e9761dd7cf6a8 /lib/gitlab/bitbucket_import/importer.rb
parentbd3bd9bcea11244c56a0f7b63a6afa6fe439bf01 (diff)
downloadgitlab-ce-00cd864237d6c7ec57ecb49d304ca8dfa9e41d31.tar.gz
BitBucket importer: import issues with labels
Diffstat (limited to 'lib/gitlab/bitbucket_import/importer.rb')
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index fba382e6fea..8852f5b0f3f 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -1,12 +1,18 @@
module Gitlab
module BitbucketImport
class Importer
+ LABELS = [{ title: 'bug', color: '#FF0000'},
+ { title: 'enhancement', color: '#428BCA'},
+ { title: 'proposal', color: '#69D100'},
+ { title: 'task', color: '#7F8C8D'}].freeze
+
attr_reader :project, :client
def initialize(project)
@project = project
@client = Bitbucket::Client.new(project.import_data.credentials)
@formatter = Gitlab::ImportFormatter.new
+ @labels = {}
end
def execute
@@ -34,10 +40,14 @@ module Gitlab
def import_issues
return unless repo.issues_enabled?
+ create_labels
+
client.issues(repo).each do |issue|
description = @formatter.author_line(issue.author)
description += issue.description
+ label_name = issue.kind
+
issue = project.issues.create(
iid: issue.iid,
title: issue.title,
@@ -48,6 +58,8 @@ module Gitlab
updated_at: issue.updated_at
)
+ assign_label(issue, label_name)
+
if issue.persisted?
client.issue_comments(repo, issue.iid).each do |comment|
# The note can be blank for issue service messages like "Changed title: ..."
@@ -74,6 +86,16 @@ module Gitlab
Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Couldn't import record properly #{e.message}")
end
+ def create_labels
+ LABELS.each do |label|
+ @labels[label[:title]] = project.labels.create!(label)
+ end
+ end
+
+ def assign_label(issue, label_name)
+ issue.labels << @labels[label_name]
+ end
+
def import_pull_requests
pull_requests = client.pull_requests(repo)