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:
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 592e75b1430..e785ce558db 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -10,6 +10,8 @@ module Gitlab
attr_reader :project, :client, :errors, :users
+ ALREADY_IMPORTED_CACHE_KEY = 'bitbucket_cloud-importer/already-imported/%{project}/%{collection}'
+
def initialize(project)
@project = project
@client = Bitbucket::Client.new(project.import_data.credentials)
@@ -31,6 +33,18 @@ module Gitlab
private
+ def already_imported?(collection, iid)
+ Gitlab::Cache::Import::Caching.set_includes?(cache_key(collection), iid)
+ end
+
+ def mark_as_imported(collection, iid)
+ Gitlab::Cache::Import::Caching.set_add(cache_key(collection), iid)
+ end
+
+ def cache_key(collection)
+ format(ALREADY_IMPORTED_CACHE_KEY, project: project.id, collection: collection)
+ end
+
def handle_errors
return unless errors.any?
@@ -97,6 +111,8 @@ module Gitlab
issue_type_id = ::WorkItems::Type.default_issue_type.id
client.issues(repo).each_with_index do |issue, index|
+ next if already_imported?(:issues, issue.iid)
+
# If a user creates an issue while the import is in progress, this can lead to an import failure.
# The workaround is to allocate IIDs before starting the importer.
allocate_issues_internal_id!(project, client) if index == 0
@@ -127,6 +143,8 @@ module Gitlab
updated_at: issue.updated_at
)
+ mark_as_imported(:issues, issue.iid)
+
metrics.issues_counter.increment
gitlab_issue.labels << @labels[label_name]
@@ -179,6 +197,8 @@ module Gitlab
pull_requests = client.pull_requests(repo)
pull_requests.each do |pull_request|
+ next if already_imported?(:pull_requests, pull_request.iid)
+
import_pull_request(pull_request)
end
end
@@ -209,6 +229,8 @@ module Gitlab
updated_at: pull_request.updated_at
)
+ mark_as_imported(:pull_requests, pull_request.iid)
+
metrics.merge_requests_counter.increment
import_pull_request_comments(pull_request, merge_request) if merge_request.persisted?