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
e38ec7c6
Commit
e38ec7c6
authored
Apr 27, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Map jira issue assignee and author
- map them to correct fields instead of description
parent
dea72e1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
19 deletions
+152
-19
changelogs/unreleased/jira-user-importer.yml
changelogs/unreleased/jira-user-importer.yml
+5
-0
lib/gitlab/jira_import/issue_serializer.rb
lib/gitlab/jira_import/issue_serializer.rb
+47
-3
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
+100
-16
No files found.
changelogs/unreleased/jira-user-importer.yml
0 → 100644
View file @
e38ec7c6
---
title
:
Map Jira issue assignee and author
merge_request
:
30498
author
:
type
:
added
lib/gitlab/jira_import/issue_serializer.rb
View file @
e38ec7c6
...
@@ -21,7 +21,8 @@ module Gitlab
...
@@ -21,7 +21,8 @@ module Gitlab
state_id:
map_status
(
jira_issue
.
status
.
statusCategory
),
state_id:
map_status
(
jira_issue
.
status
.
statusCategory
),
updated_at:
jira_issue
.
updated
,
updated_at:
jira_issue
.
updated
,
created_at:
jira_issue
.
created
,
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
label_ids:
label_ids
}
}
end
end
...
@@ -34,8 +35,6 @@ module Gitlab
...
@@ -34,8 +35,6 @@ module Gitlab
def
description
def
description
body
=
[]
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
<<
jira_issue
.
description
body
<<
MetadataCollector
.
new
(
jira_issue
).
execute
body
<<
MetadataCollector
.
new
(
jira_issue
).
execute
...
@@ -51,6 +50,38 @@ module Gitlab
...
@@ -51,6 +50,38 @@ module Gitlab
end
end
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
# We already create labels in Gitlab::JiraImport::LabelsImporter stage but
# there is a possibility it may fail or
# there is a possibility it may fail or
# new labels were created on the Jira in the meantime
# new labels were created on the Jira in the meantime
...
@@ -59,6 +90,19 @@ module Gitlab
...
@@ -59,6 +90,19 @@ module Gitlab
Gitlab
::
JiraImport
::
HandleLabelsService
.
new
(
project
,
jira_issue
.
fields
[
'labels'
]).
execute
Gitlab
::
JiraImport
::
HandleLabelsService
.
new
(
project
,
jira_issue
.
fields
[
'labels'
]).
execute
end
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
end
end
end
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
View file @
e38ec7c6
...
@@ -16,7 +16,8 @@ describe Gitlab::JiraImport::IssueSerializer do
...
@@ -16,7 +16,8 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:description
)
{
'basic description'
}
let
(
:description
)
{
'basic description'
}
let
(
:created_at
)
{
'2020-01-01 20:00:00'
}
let
(
:created_at
)
{
'2020-01-01 20:00:00'
}
let
(
:updated_at
)
{
'2020-01-10 20:00:00'
}
let
(
:updated_at
)
{
'2020-01-10 20:00:00'
}
let
(
:assignee
)
{
double
(
displayName:
'Solver'
)
}
let
(
:assignee
)
{
double
(
displayName:
'Solver'
,
emailAddress:
'assignee@example.com'
)
}
let
(
:reporter
)
{
double
(
displayName:
'Reporter'
,
emailAddress:
'reporter@example.com'
)
}
let
(
:jira_status
)
{
'new'
}
let
(
:jira_status
)
{
'new'
}
let
(
:parent_field
)
do
let
(
:parent_field
)
do
...
@@ -42,7 +43,7 @@ describe Gitlab::JiraImport::IssueSerializer do
...
@@ -42,7 +43,7 @@ describe Gitlab::JiraImport::IssueSerializer do
created:
created_at
,
created:
created_at
,
updated:
updated_at
,
updated:
updated_at
,
assignee:
assignee
,
assignee:
assignee
,
reporter:
double
(
displayName:
'Reporter'
)
,
reporter:
reporter
,
status:
double
(
statusCategory:
{
'key'
=>
jira_status
}),
status:
double
(
statusCategory:
{
'key'
=>
jira_status
}),
fields:
fields
fields:
fields
)
)
...
@@ -54,10 +55,6 @@ describe Gitlab::JiraImport::IssueSerializer do
...
@@ -54,10 +55,6 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:expected_description
)
do
let
(
:expected_description
)
do
<<~
MD
<<~
MD
*Created by: Reporter*
*Assigned to: Solver*
basic description
basic description
---
---
...
@@ -80,6 +77,7 @@ describe Gitlab::JiraImport::IssueSerializer do
...
@@ -80,6 +77,7 @@ describe Gitlab::JiraImport::IssueSerializer do
updated_at:
updated_at
,
updated_at:
updated_at
,
created_at:
created_at
,
created_at:
created_at
,
author_id:
project
.
creator_id
,
author_id:
project
.
creator_id
,
assignee_ids:
nil
,
label_ids:
[
project_label
.
id
,
group_label
.
id
]
+
Label
.
reorder
(
id: :asc
).
last
(
2
).
pluck
(
:id
)
label_ids:
[
project_label
.
id
,
group_label
.
id
]
+
Label
.
reorder
(
id: :asc
).
last
(
2
).
pluck
(
:id
)
)
)
end
end
...
@@ -88,22 +86,108 @@ describe Gitlab::JiraImport::IssueSerializer do
...
@@ -88,22 +86,108 @@ describe Gitlab::JiraImport::IssueSerializer do
expect
(
Issue
.
new
(
subject
)).
to
be_valid
expect
(
Issue
.
new
(
subject
)).
to
be_valid
end
end
it
'creates all missing labels (on project level)'
do
context
'labels'
do
expect
{
subject
}.
to
change
{
Label
.
count
}.
from
(
3
).
to
(
5
)
it
'creates all missing labels (on project level)'
do
expect
{
subject
}.
to
change
{
Label
.
count
}.
from
(
3
).
to
(
5
)
expect
(
Label
.
find_by
(
title:
'frontend'
).
project
).
to
eq
(
project
)
expect
(
Label
.
find_by
(
title:
'backend'
).
project
).
to
eq
(
project
)
end
context
'when there are no new labels'
do
let
(
:labels_field
)
{
%w(bug dev)
}
expect
(
Label
.
find_by
(
title:
'frontend'
).
project
).
to
eq
(
project
)
it
'assigns the labels to the Issue hash'
do
expect
(
Label
.
find_by
(
title:
'backend'
).
project
).
to
eq
(
project
)
expect
(
subject
[
:label_ids
]).
to
match_array
([
project_label
.
id
,
group_label
.
id
])
end
it
'does not create new labels'
do
expect
{
subject
}.
not_to
change
{
Label
.
count
}.
from
(
3
)
end
end
end
end
context
'when there are no new labels'
do
context
'author'
do
let
(
:labels_field
)
{
%w(bug dev)
}
context
'when reporter maps to a GitLab user who is a project member'
do
let!
(
:user
)
{
create
(
:user
,
email:
'reporter@example.com'
)
}
it
'assigns the labels to the Issue hash'
do
it
'sets the issue author to the mapped user'
do
expect
(
subject
[
:label_ids
]).
to
match_array
([
project_label
.
id
,
group_label
.
id
])
project
.
add_developer
(
user
)
expect
(
subject
[
:author_id
]).
to
eq
(
user
.
id
)
end
end
end
it
'does not create new labels'
do
context
'when reporter maps to a GitLab user who is not a project member'
do
expect
{
subject
}.
not_to
change
{
Label
.
count
}.
from
(
3
)
let!
(
:user
)
{
create
(
:user
,
email:
'reporter@example.com'
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creator
.
id
)
end
end
context
'when reporter does not map to a GitLab user'
do
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creator
.
id
)
end
end
context
'when reporter field is empty'
do
let
(
:reporter
)
{
nil
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creator
.
id
)
end
end
context
'when reporter field is missing email address'
do
let
(
:reporter
)
{
double
(
name:
'Reporter'
,
emailAddress:
nil
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creator
.
id
)
end
end
end
context
'assignee'
do
context
'when assignee maps to a GitLab user who is a project member'
do
let!
(
:user
)
{
create
(
:user
,
email:
'assignee@example.com'
)
}
it
'sets the issue assignees to the mapped user'
do
project
.
add_developer
(
user
)
expect
(
subject
[
:assignee_ids
]).
to
eq
([
user
.
id
])
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
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
end
end
context
'when assginee field is empty'
do
let
(
:assignee
)
{
nil
}
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
end
end
context
'when assginee field is missing email address'
do
let
(
:assignee
)
{
double
(
name:
'Assignee'
,
emailAddress:
nil
)
}
it
'leaves the assignee empty'
do
expect
(
subject
[
:assignee_ids
]).
to
be_nil
end
end
end
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