Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
be1dd4d4
Commit
be1dd4d4
authored
Apr 30, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor mapping users for jira import
Extract user mapping from IssueSerializer
parent
9955183f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
53 deletions
+150
-53
changelogs/unreleased/jira-user-importer-prep.yml
changelogs/unreleased/jira-user-importer-prep.yml
+5
-0
lib/gitlab/jira_import/issue_serializer.rb
lib/gitlab/jira_import/issue_serializer.rb
+4
-29
lib/gitlab/jira_import/user_mapper.rb
lib/gitlab/jira_import/user_mapper.rb
+53
-0
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
+8
-24
spec/lib/gitlab/jira_import/user_mapper_spec.rb
spec/lib/gitlab/jira_import/user_mapper_spec.rb
+80
-0
No files found.
changelogs/unreleased/jira-user-importer-prep.yml
0 → 100644
View file @
be1dd4d4
---
title
:
Fix mapping group membets as Jira issues authors/assignees
merge_request
:
30820
author
:
type
:
fixed
lib/gitlab/jira_import/issue_serializer.rb
View file @
be1dd4d4
...
...
@@ -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
&
.
emailAddres
s
)
||
import_owner_id
map_user_id
(
jira_issue
.
reporter
&
.
attr
s
)
||
import_owner_id
end
def
assignees
found_user_id
=
map_user_id
(
jira_issue
&
.
assignee
&
.
emailAddres
s
)
found_user_id
=
map_user_id
(
jira_issue
.
assignee
&
.
attr
s
)
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
lib/gitlab/jira_import/user_mapper.rb
0 → 100644
View file @
be1dd4d4
# 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
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
View file @
be1dd4d4
...
...
@@ -17,8 +17,8 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:description
)
{
'basic description'
}
let
(
:created_at
)
{
'2020-01-01 20:00:00'
}
let
(
:updated_at
)
{
'2020-01-10 20:00:00'
}
let
(
:assignee
)
{
double
(
displayName:
'Solver'
,
emailAddress:
'assignee@example.com'
)
}
let
(
:reporter
)
{
double
(
displayName:
'Reporter'
,
emailAddress:
'reporter@example.com'
)
}
let
(
:assignee
)
{
double
(
attrs:
{
'displayName'
=>
'Solver'
,
'emailAddress'
=>
'assignee@example.com'
}
)
}
let
(
:reporter
)
{
double
(
attrs:
{
'displayName'
=>
'Reporter'
,
'emailAddress'
=>
'reporter@example.com'
}
)
}
let
(
:jira_status
)
{
'new'
}
let
(
:parent_field
)
do
...
...
@@ -109,7 +109,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
context
'author'
do
context
'when reporter maps to a
GitLab user who is a project memb
er'
do
context
'when reporter maps to a
valid GitLab us
er'
do
let!
(
:user
)
{
create
(
:user
,
email:
'reporter@example.com'
)
}
it
'sets the issue author to the mapped user'
do
...
...
@@ -119,15 +119,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
end
context
'when reporter maps to a GitLab user who is not a project member'
do
let!
(
:user
)
{
create
(
:user
,
email:
'reporter@example.com'
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
current_user
.
id
)
end
end
context
'when reporter does not map to a GitLab user'
do
context
'when reporter does not map to a valid Gitlab user'
do
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
current_user
.
id
)
end
...
...
@@ -142,7 +134,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
context
'when reporter field is missing email address'
do
let
(
:reporter
)
{
double
(
name:
'Reporter'
,
emailAddress:
nil
)
}
let
(
:reporter
)
{
double
(
attrs:
{
'displayName'
=>
'Reporter'
}
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
current_user
.
id
)
...
...
@@ -151,7 +143,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
context
'assignee'
do
context
'when assignee maps to a
GitLab user who is a project memb
er'
do
context
'when assignee maps to a
valid GitLab us
er'
do
let!
(
:user
)
{
create
(
:user
,
email:
'assignee@example.com'
)
}
it
'sets the issue assignees to the mapped user'
do
...
...
@@ -161,15 +153,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
end
context
'when assignee maps to a GitLab user who is not a project member'
do
let!
(
:user
)
{
create
(
:user
,
email:
'assignee@example.com'
)
}
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
end
end
context
'when assignee does not map to a GitLab user'
do
context
'when assignee does not map to a valid GitLab user'
do
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
end
...
...
@@ -184,7 +168,7 @@ describe Gitlab::JiraImport::IssueSerializer do
end
context
'when assginee field is missing email address'
do
let
(
:assignee
)
{
double
(
name:
'Assignee'
,
emailAddress:
nil
)
}
let
(
:assignee
)
{
double
(
attrs:
{
'displayName'
=>
'Reporter'
}
)
}
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
...
...
spec/lib/gitlab/jira_import/user_mapper_spec.rb
0 → 100644
View file @
be1dd4d4
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
JiraImport
::
UserMapper
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:user
)
{
create
(
:user
,
email:
'user@example.com'
)
}
let_it_be
(
:email
)
{
create
(
:email
,
user:
user
,
email:
'second_email@example.com'
,
confirmed_at:
nil
)
}
let
(
:jira_user
)
{
{
'acountId'
=>
'1a2b'
,
'emailAddress'
=>
'user@example.com'
}
}
describe
'#execute'
do
subject
{
described_class
.
new
(
project
,
jira_user
).
execute
}
context
'when jira_user is nil'
do
let
(
:jira_user
)
{
nil
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
context
'when Gitlab user is not found by email'
do
let
(
:jira_user
)
{
{
'acountId'
=>
'1a2b'
,
'emailAddress'
=>
'other@example.com'
}
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
context
'when jira_user emailAddress is nil'
do
let
(
:jira_user
)
{
{
'acountId'
=>
'1a2b'
,
'emailAddress'
=>
nil
}
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
context
'when jira_user emailAddress key is missing'
do
let
(
:jira_user
)
{
{
'acountId'
=>
'1a2b'
}
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
context
'when found user is not a project member'
do
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
context
'when found user is a project member'
do
it
'returns the found user'
do
project
.
add_developer
(
user
)
expect
(
subject
).
to
eq
(
user
)
end
end
context
'when user found by unconfirmd secondary address is a project member'
do
let
(
:jira_user
)
{
{
'acountId'
=>
'1a2b'
,
'emailAddress'
=>
'second_email@example.com'
}
}
it
'returns the found user'
do
project
.
add_developer
(
user
)
expect
(
subject
).
to
eq
(
user
)
end
end
context
'when user is a group member'
do
it
'returns the found user'
do
group
.
add_developer
(
user
)
expect
(
subject
).
to
eq
(
user
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment