diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-29 18:09:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-29 18:09:58 +0300 |
commit | 647de7e6fd971d435396cc8730a2d162240e3d7c (patch) | |
tree | 3e2fc4e6e8027375d6061f2ad4badda04ef04476 /lib/gitlab/jira_import | |
parent | 4233d3aa86fe94e6288279aa55d42ed95bfe753c (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.rb | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/lib/gitlab/jira_import/issue_serializer.rb b/lib/gitlab/jira_import/issue_serializer.rb index f05b36e54da..244c9fd637d 100644 --- a/lib/gitlab/jira_import/issue_serializer.rb +++ b/lib/gitlab/jira_import/issue_serializer.rb @@ -21,7 +21,8 @@ module Gitlab state_id: map_status(jira_issue.status.statusCategory), updated_at: jira_issue.updated, created_at: jira_issue.created, - author_id: project.creator_id, # TODO: map actual author: https://gitlab.com/gitlab-org/gitlab/-/issues/210580 + author_id: reporter, + assignee_ids: assignees, label_ids: label_ids } end @@ -34,8 +35,6 @@ module Gitlab def description body = [] - body << formatter.author_line(jira_issue.reporter.displayName) - body << formatter.assignee_line(jira_issue.assignee.displayName) if jira_issue.assignee body << jira_issue.description body << MetadataCollector.new(jira_issue).execute @@ -51,6 +50,38 @@ 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 + end + + def reporter + map_user_id(jira_issue&.reporter&.emailAddress) || project.creator_id + end + + def assignees + found_user_id = map_user_id(jira_issue&.assignee&.emailAddress) + + return unless found_user_id + + [found_user_id] + end + # We already create labels in Gitlab::JiraImport::LabelsImporter stage but # there is a possibility it may fail or # new labels were created on the Jira in the meantime @@ -59,6 +90,19 @@ module Gitlab Gitlab::JiraImport::HandleLabelsService.new(project, jira_issue.fields['labels']).execute end + + 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 |