Commit 00cd8642 authored by Valery Sizov's avatar Valery Sizov

BitBucket importer: import issues with labels

parent bd3bd9bc
...@@ -7,6 +7,10 @@ module Bitbucket ...@@ -7,6 +7,10 @@ module Bitbucket
raw['id'] raw['id']
end end
def kind
raw['kind']
end
def author def author
raw.dig('reporter', 'username') || 'Anonymous' raw.dig('reporter', 'username') || 'Anonymous'
end end
......
module Gitlab module Gitlab
module BitbucketImport module BitbucketImport
class Importer class Importer
LABELS = [{ title: 'bug', color: '#FF0000'},
{ title: 'enhancement', color: '#428BCA'},
{ title: 'proposal', color: '#69D100'},
{ title: 'task', color: '#7F8C8D'}].freeze
attr_reader :project, :client attr_reader :project, :client
def initialize(project) def initialize(project)
@project = project @project = project
@client = Bitbucket::Client.new(project.import_data.credentials) @client = Bitbucket::Client.new(project.import_data.credentials)
@formatter = Gitlab::ImportFormatter.new @formatter = Gitlab::ImportFormatter.new
@labels = {}
end end
def execute def execute
...@@ -34,10 +40,14 @@ module Gitlab ...@@ -34,10 +40,14 @@ module Gitlab
def import_issues def import_issues
return unless repo.issues_enabled? return unless repo.issues_enabled?
create_labels
client.issues(repo).each do |issue| client.issues(repo).each do |issue|
description = @formatter.author_line(issue.author) description = @formatter.author_line(issue.author)
description += issue.description description += issue.description
label_name = issue.kind
issue = project.issues.create( issue = project.issues.create(
iid: issue.iid, iid: issue.iid,
title: issue.title, title: issue.title,
...@@ -48,6 +58,8 @@ module Gitlab ...@@ -48,6 +58,8 @@ module Gitlab
updated_at: issue.updated_at updated_at: issue.updated_at
) )
assign_label(issue, label_name)
if issue.persisted? if issue.persisted?
client.issue_comments(repo, issue.iid).each do |comment| client.issue_comments(repo, issue.iid).each do |comment|
# The note can be blank for issue service messages like "Changed title: ..." # The note can be blank for issue service messages like "Changed title: ..."
...@@ -74,6 +86,16 @@ module Gitlab ...@@ -74,6 +86,16 @@ module Gitlab
Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Couldn't import record properly #{e.message}") Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Couldn't import record properly #{e.message}")
end 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 def import_pull_requests
pull_requests = client.pull_requests(repo) pull_requests = client.pull_requests(repo)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment