summaryrefslogtreecommitdiff
path: root/lib/gitlab/bitbucket_import
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-22 16:13:56 -0300
committerStan Hu <stanhu@gmail.com>2016-11-21 16:47:26 -0800
commit317b020932736d2cd629542e3a8b3aef2219e033 (patch)
treeace63a0d7f5691e0dcc1777ccb707307cfe880d2 /lib/gitlab/bitbucket_import
parent3c756b83ef04dbbb2a82a53cf785a87da0772255 (diff)
downloadgitlab-ce-317b020932736d2cd629542e3a8b3aef2219e033.tar.gz
Refactoring Bitbucket importer to use the new OAuth2 client
Diffstat (limited to 'lib/gitlab/bitbucket_import')
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb74
1 files changed, 33 insertions, 41 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index f4b5097adb1..67e906431f0 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -5,18 +5,14 @@ module Gitlab
def initialize(project)
@project = project
- @client = Client.from_project(@project)
+ @client = Bitbucket::Client.new(project.import_data.credentials)
@formatter = Gitlab::ImportFormatter.new
end
def execute
- import_issues if has_issues?
+ import_issues
true
- rescue ActiveRecord::RecordInvalid => e
- raise Projects::ImportService::Error.new, e.message
- ensure
- Gitlab::BitbucketImport::KeyDeleter.new(project).execute
end
private
@@ -30,44 +26,40 @@ module Gitlab
end
end
- def identifier
- project.import_source
- end
-
- def has_issues?
- client.project(identifier)["has_issues"]
+ def repo
+ @repo ||= client.repo(project.import_source)
end
def import_issues
- issues = client.issues(identifier)
-
- issues.each do |issue|
- body = ''
- reporter = nil
- author = 'Anonymous'
-
- if issue["reported_by"] && issue["reported_by"]["username"]
- reporter = issue["reported_by"]["username"]
- author = reporter
- end
-
- body = @formatter.author_line(author)
- body += issue["content"]
-
- comments = client.issue_comments(identifier, issue["local_id"])
-
- if comments.any?
- body += @formatter.comments_header
- end
-
- comments.each do |comment|
- author = 'Anonymous'
+ return unless repo.has_issues?
+
+ client.issues(repo).each do |issue|
+ description = @formatter.author_line(issue.author)
+ description += issue.description
+
+ issue = project.issues.create(
+ iid: issue.iid,
+ title: issue.title,
+ description: description,
+ state: issue.state,
+ author_id: gl_user_id(project, issue.author),
+ created_at: issue.created_at,
+ updated_at: issue.updated_at
+ )
- if comment["author_info"] && comment["author_info"]["username"]
- author = comment["author_info"]["username"]
+ if issue.persisted?
+ client.issue_comments(repo, issue.iid).each do |comment|
+ note = @formatter.author_line(comment.author)
+ note += comment.note
+
+ issue.notes.create!(
+ project: project,
+ note: note,
+ author_id: gl_user_id(project, comment.author),
+ created_at: comment.created_at,
+ updated_at: comment.updated_at
+ )
end
-
- body += @formatter.comment(author, comment["utc_created_on"], comment["content"])
end
project.issues.create!(
@@ -77,8 +69,8 @@ module Gitlab
author_id: gitlab_user_id(project, reporter)
)
end
- rescue ActiveRecord::RecordInvalid => e
- raise Projects::ImportService::Error, e.message
+ rescue ActiveRecord::RecordInvalid
+ nil
end
end
end