BigW Consortium Gitlab

Move Gitlab::BitbucketImport::KeyDeleter to it's own importer

parent 6dd88e09
...@@ -49,10 +49,6 @@ module Projects ...@@ -49,10 +49,6 @@ module Projects
unless importer.execute unless importer.execute
raise Error, 'The remote data could not be imported.' raise Error, 'The remote data could not be imported.'
end end
if project.import_type == 'bitbucket'
Gitlab::BitbucketImport::KeyDeleter.new(project).execute
end
end end
def has_importer? def has_importer?
......
...@@ -13,12 +13,34 @@ module Gitlab ...@@ -13,12 +13,34 @@ module Gitlab
end end
def execute def execute
project_identifier = project.import_source import_issues if has_issues?
return true unless client.project(project_identifier)["has_issues"] true
ensure
Gitlab::BitbucketImport::KeyDeleter.new(project).execute
end
#Issues && Comments private
issues = client.issues(project_identifier)
def gl_user_id(project, bitbucket_id)
if bitbucket_id
user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s)
(user && user.id) || project.creator_id
else
project.creator_id
end
end
def identifier
project.import_source
end
def has_issues?
client.project(identifier)["has_issues"]
end
def import_issues
issues = client.issues(identifier)
issues.each do |issue| issues.each do |issue|
body = '' body = ''
...@@ -33,7 +55,7 @@ module Gitlab ...@@ -33,7 +55,7 @@ module Gitlab
body = @formatter.author_line(author) body = @formatter.author_line(author)
body += issue["content"] body += issue["content"]
comments = client.issue_comments(project_identifier, issue["local_id"]) comments = client.issue_comments(identifier, issue["local_id"])
if comments.any? if comments.any?
body += @formatter.comments_header body += @formatter.comments_header
...@@ -56,20 +78,9 @@ module Gitlab ...@@ -56,20 +78,9 @@ module Gitlab
author_id: gl_user_id(project, reporter) author_id: gl_user_id(project, reporter)
) )
end end
rescue ActiveRecord::RecordInvalid => e
true raise Projects::ImportService::Error, e.message
end end
private
def gl_user_id(project, bitbucket_id)
if bitbucket_id
user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s)
(user && user.id) || project.creator_id
else
project.creator_id
end
end
end end
end end
end end
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