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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-08 21:09:55 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-08 21:09:55 +0300
commitc0c1433fa5a9f31c8eb4292d13de744aa74e9e83 (patch)
treed3d0092f22ceca3d97bf5d882081b1fa70524911 /lib/gitlab/jira_import
parent2e4dcef627009fa11836f6f624e7313843cb4a38 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/jira_import')
-rw-r--r--lib/gitlab/jira_import/issue_serializer.rb33
-rw-r--r--lib/gitlab/jira_import/user_mapper.rb53
2 files changed, 57 insertions, 29 deletions
diff --git a/lib/gitlab/jira_import/issue_serializer.rb b/lib/gitlab/jira_import/issue_serializer.rb
index 9bbee901b14..df57680073e 100644
--- a/lib/gitlab/jira_import/issue_serializer.rb
+++ b/lib/gitlab/jira_import/issue_serializer.rb
@@ -51,32 +51,16 @@ module Gitlab
end
end
- def map_user_id(email)
- return unless email
-
- # We also include emails that are not yet confirmed
- users = User.by_any_email(email).to_a
-
- # this event should never happen but we should log it in case we have invalid data
- log_user_mapping_message('Multiple users found for an email address', email) if users.count > 1
-
- user = users.first
-
- unless project.project_member(user)
- log_user_mapping_message('Jira user not found', email)
-
- return
- end
-
- user.id
+ def map_user_id(jira_user)
+ Gitlab::JiraImport::UserMapper.new(project, jira_user).execute&.id
end
def reporter
- map_user_id(jira_issue&.reporter&.emailAddress) || import_owner_id
+ map_user_id(jira_issue.reporter&.attrs) || import_owner_id
end
def assignees
- found_user_id = map_user_id(jira_issue&.assignee&.emailAddress)
+ found_user_id = map_user_id(jira_issue.assignee&.attrs)
return unless found_user_id
@@ -95,15 +79,6 @@ module Gitlab
def logger
@logger ||= Gitlab::Import::Logger.build
end
-
- def log_user_mapping_message(message, email)
- logger.info(
- project_id: project.id,
- project_path: project.full_path,
- user_email: email,
- message: message
- )
- end
end
end
end
diff --git a/lib/gitlab/jira_import/user_mapper.rb b/lib/gitlab/jira_import/user_mapper.rb
new file mode 100644
index 00000000000..208ee49b724
--- /dev/null
+++ b/lib/gitlab/jira_import/user_mapper.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module JiraImport
+ class UserMapper
+ include ::Gitlab::Utils::StrongMemoize
+
+ def initialize(project, jira_user)
+ @project = project
+ @jira_user = jira_user
+ end
+
+ def execute
+ return unless jira_user
+
+ email = jira_user['emailAddress']
+
+ # We also include emails that are not yet confirmed
+ users = User.by_any_email(email).to_a
+
+ user = users.first
+
+ # this event should never happen but we should log it in case we have invalid data
+ log_user_mapping_message('Multiple users found for an email address', email) if users.count > 1
+
+ unless project.project_member(user) || project.group&.group_member(user)
+ log_user_mapping_message('Jira user not found', email)
+
+ return
+ end
+
+ user
+ end
+
+ private
+
+ attr_reader :project, :jira_user, :params
+
+ def log_user_mapping_message(message, email)
+ logger.info(
+ project_id: project.id,
+ project_path: project.full_path,
+ user_email: email,
+ message: message
+ )
+ end
+
+ def logger
+ @logger ||= Gitlab::Import::Logger.build
+ end
+ end
+ end
+end