Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-14 16:18:30 +0300
committerValery Sizov <valery@gitlab.com>2016-12-14 16:18:30 +0300
commit6bbe2f118ee17ac8b1d43a77f4020c048c427b77 (patch)
tree6cab0b31098e2272a64e36557b4d8145076a9a2f /lib/gitlab/bitbucket_import
parent468d575fc73881900f4a4cb1fa71c187d77429a7 (diff)
BB importer: More advanced error handling
Diffstat (limited to 'lib/gitlab/bitbucket_import')
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb80
1 files changed, 47 insertions, 33 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index b6a0b122cdb..567f2b314aa 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -6,24 +6,34 @@ module Gitlab
{ title: 'proposal', color: '#69D100' },
{ title: 'task', color: '#7F8C8D' }].freeze
- attr_reader :project, :client
+ attr_reader :project, :client, :errors
def initialize(project)
@project = project
@client = Bitbucket::Client.new(project.import_data.credentials)
@formatter = Gitlab::ImportFormatter.new
@labels = {}
+ @errors = []
end
def execute
import_issues
import_pull_requests
+ handle_errors
true
end
private
+ def handle_errors
+ return unless errors.any?
+ project.update_column(:import_error, {
+ message: 'The remote data could not be fully imported.',
+ errors: errors
+ }.to_json)
+ end
+
def gitlab_user_id(project, username)
if username
user = find_user(username)
@@ -51,21 +61,25 @@ module Gitlab
create_labels
client.issues(repo).each do |issue|
- description = ''
- description += @formatter.author_line(issue.author) unless existing_gitlab_user?(issue.author)
- description += issue.description
-
- label_name = issue.kind
-
- issue = project.issues.create(
- iid: issue.iid,
- title: issue.title,
- description: description,
- state: issue.state,
- author_id: gitlab_user_id(project, issue.author),
- created_at: issue.created_at,
- updated_at: issue.updated_at
- )
+ begin
+ description = ''
+ description += @formatter.author_line(issue.author) unless existing_gitlab_user?(issue.author)
+ description += issue.description
+
+ label_name = issue.kind
+
+ issue = project.issues.create!(
+ iid: issue.iid,
+ title: issue.title,
+ description: description,
+ state: issue.state,
+ author_id: gitlab_user_id(project, issue.author),
+ created_at: issue.created_at,
+ updated_at: issue.updated_at
+ )
+ rescue StandardError => e
+ errors << { type: :issue, iid: issue.iid, errors: e.message }
+ end
issue.labels << @labels[label_name]
@@ -82,18 +96,20 @@ module Gitlab
note += @formatter.author_line(comment.author) unless existing_gitlab_user?(comment.author)
note += comment.note
- issue.notes.create!(
- project: project,
- note: note,
- author_id: gitlab_user_id(project, comment.author),
- created_at: comment.created_at,
- updated_at: comment.updated_at
- )
+ begin
+ issue.notes.create!(
+ project: project,
+ note: note,
+ author_id: gitlab_user_id(project, comment.author),
+ created_at: comment.created_at,
+ updated_at: comment.updated_at
+ )
+ rescue StandardError => e
+ errors << { type: :issue_comment, iid: issue.iid, errors: e.message }
+ end
end
end
end
- rescue ActiveRecord::RecordInvalid => e
- Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Couldn't import record properly #{e.message}")
end
def create_labels
@@ -129,8 +145,8 @@ module Gitlab
)
import_pull_request_comments(pull_request, merge_request) if merge_request.persisted?
- rescue ActiveRecord::RecordInvalid
- Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Invalid pull request #{e.message}")
+ rescue StandardError => e
+ errors << { type: :pull_request, iid: pull_request.iid, errors: e.message }
end
end
end
@@ -169,9 +185,8 @@ module Gitlab
type: 'DiffNote')
merge_request.notes.create!(attributes)
- rescue ActiveRecord::RecordInvalid => e
- Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Invalid pull request comment #{e.message}")
- nil
+ rescue StandardError => e
+ errors << { type: :pull_request, iid: comment.iid, errors: e.message }
end
end
end
@@ -192,9 +207,8 @@ module Gitlab
pr_comments.each do |comment|
begin
merge_request.notes.create!(pull_request_comment_attributes(comment))
- rescue ActiveRecord::RecordInvalid => e
- Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Invalid standalone pull request comment #{e.message}")
- nil
+ rescue StandardError => e
+ errors << { type: :pull_request, iid: comment.iid, errors: e.message }
end
end
end