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
df808882
Commit
df808882
authored
Apr 27, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use jira import owner as the issue author
- the user who runs the import is the issues author
parent
a7298fff
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
27 deletions
+38
-27
changelogs/unreleased/215569-jira-import-fix-default-author.yml
...logs/unreleased/215569-jira-import-fix-default-author.yml
+5
-0
lib/gitlab/jira_import/base_importer.rb
lib/gitlab/jira_import/base_importer.rb
+3
-2
lib/gitlab/jira_import/issue_serializer.rb
lib/gitlab/jira_import/issue_serializer.rb
+4
-3
lib/gitlab/jira_import/issues_importer.rb
lib/gitlab/jira_import/issues_importer.rb
+1
-1
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
+7
-6
spec/lib/gitlab/jira_import/issues_importer_spec.rb
spec/lib/gitlab/jira_import/issues_importer_spec.rb
+18
-15
No files found.
changelogs/unreleased/215569-jira-import-fix-default-author.yml
0 → 100644
View file @
df808882
---
title
:
Use Jira import owner as the issue author when importing issues from Jira
merge_request
:
30504
author
:
type
:
fixed
lib/gitlab/jira_import/base_importer.rb
View file @
df808882
...
...
@@ -3,12 +3,13 @@
module
Gitlab
module
JiraImport
class
BaseImporter
attr_reader
:project
,
:client
,
:formatter
,
:jira_project_key
attr_reader
:project
,
:client
,
:formatter
,
:jira_project_key
,
:running_import
def
initialize
(
project
)
project
.
validate_jira_import_settings!
@jira_project_key
=
project
.
latest_jira_import
&
.
jira_project_key
@running_import
=
project
.
latest_jira_import
@jira_project_key
=
running_import
&
.
jira_project_key
raise
Projects
::
ImportService
::
Error
,
_
(
'Unable to find Jira project to import data from.'
)
unless
@jira_project_key
...
...
lib/gitlab/jira_import/issue_serializer.rb
View file @
df808882
...
...
@@ -3,11 +3,12 @@
module
Gitlab
module
JiraImport
class
IssueSerializer
attr_reader
:jira_issue
,
:project
,
:params
,
:formatter
attr_reader
:jira_issue
,
:project
,
:
import_owner_id
,
:
params
,
:formatter
def
initialize
(
project
,
jira_issue
,
params
=
{})
def
initialize
(
project
,
jira_issue
,
import_owner_id
,
params
=
{})
@jira_issue
=
jira_issue
@project
=
project
@import_owner_id
=
import_owner_id
@params
=
params
@formatter
=
Gitlab
::
ImportFormatter
.
new
end
...
...
@@ -71,7 +72,7 @@ module Gitlab
end
def
reporter
map_user_id
(
jira_issue
&
.
reporter
&
.
emailAddress
)
||
project
.
creato
r_id
map_user_id
(
jira_issue
&
.
reporter
&
.
emailAddress
)
||
import_owne
r_id
end
def
assignees
...
...
lib/gitlab/jira_import/issues_importer.rb
View file @
df808882
...
...
@@ -57,7 +57,7 @@ module Gitlab
# For such cases we exit early if issue was already imported.
next
if
already_imported?
(
jira_issue
.
id
)
issue_attrs
=
IssueSerializer
.
new
(
project
,
jira_issue
,
{
iid:
next_iid
}).
execute
issue_attrs
=
IssueSerializer
.
new
(
project
,
jira_issue
,
running_import
.
user_id
,
{
iid:
next_iid
}).
execute
Gitlab
::
JiraImport
::
ImportIssueWorker
.
perform_async
(
project
.
id
,
jira_issue
.
id
,
issue_attrs
,
job_waiter
.
key
)
job_waiter
.
jobs_remaining
+=
1
...
...
spec/lib/gitlab/jira_import/issue_serializer_spec.rb
View file @
df808882
...
...
@@ -9,6 +9,7 @@ describe Gitlab::JiraImport::IssueSerializer do
let_it_be
(
:project_label
)
{
create
(
:label
,
project:
project
,
title:
'bug'
)
}
let_it_be
(
:other_project_label
)
{
create
(
:label
,
project:
project
,
title:
'feature'
)
}
let_it_be
(
:group_label
)
{
create
(
:group_label
,
group:
group
,
title:
'dev'
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let
(
:iid
)
{
5
}
let
(
:key
)
{
'PROJECT-5'
}
...
...
@@ -51,7 +52,7 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:params
)
{
{
iid:
iid
}
}
subject
{
described_class
.
new
(
project
,
jira_issue
,
params
).
execute
}
subject
{
described_class
.
new
(
project
,
jira_issue
,
current_user
.
id
,
params
).
execute
}
let
(
:expected_description
)
do
<<~
MD
...
...
@@ -76,7 +77,7 @@ describe Gitlab::JiraImport::IssueSerializer do
state_id:
1
,
updated_at:
updated_at
,
created_at:
created_at
,
author_id:
project
.
creator_
id
,
author_id:
current_user
.
id
,
assignee_ids:
nil
,
label_ids:
[
project_label
.
id
,
group_label
.
id
]
+
Label
.
reorder
(
id: :asc
).
last
(
2
).
pluck
(
:id
)
)
...
...
@@ -122,13 +123,13 @@ describe Gitlab::JiraImport::IssueSerializer do
let!
(
:user
)
{
create
(
:user
,
email:
'reporter@example.com'
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creato
r
.
id
)
expect
(
subject
[
:author_id
]).
to
eq
(
current_use
r
.
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
.
creato
r
.
id
)
expect
(
subject
[
:author_id
]).
to
eq
(
current_use
r
.
id
)
end
end
...
...
@@ -136,7 +137,7 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:reporter
)
{
nil
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creato
r
.
id
)
expect
(
subject
[
:author_id
]).
to
eq
(
current_use
r
.
id
)
end
end
...
...
@@ -144,7 +145,7 @@ describe Gitlab::JiraImport::IssueSerializer do
let
(
:reporter
)
{
double
(
name:
'Reporter'
,
emailAddress:
nil
)
}
it
'defaults the issue author to project creator'
do
expect
(
subject
[
:author_id
]).
to
eq
(
project
.
creato
r
.
id
)
expect
(
subject
[
:author_id
]).
to
eq
(
current_use
r
.
id
)
end
end
end
...
...
spec/lib/gitlab/jira_import/issues_importer_spec.rb
View file @
df808882
...
...
@@ -6,8 +6,9 @@ describe Gitlab::JiraImport::IssuesImporter do
include
JiraServiceHelper
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:jira_import
)
{
create
(
:jira_import_state
,
project:
project
)
}
let_it_be
(
:jira_import
)
{
create
(
:jira_import_state
,
project:
project
,
user:
current_user
)
}
let_it_be
(
:jira_service
)
{
create
(
:jira_service
,
project:
project
)
}
subject
{
described_class
.
new
(
project
)
}
...
...
@@ -39,8 +40,16 @@ describe Gitlab::JiraImport::IssuesImporter do
context
'with results returned'
do
JiraIssue
=
Struct
.
new
(
:id
)
let_it_be
(
:jira_issue1
)
{
JiraIssue
.
new
(
1
)
}
let_it_be
(
:jira_issue2
)
{
JiraIssue
.
new
(
2
)
}
let_it_be
(
:jira_issues
)
{
[
JiraIssue
.
new
(
1
),
JiraIssue
.
new
(
2
)]
}
def
mock_issue_serializer
(
count
)
serializer
=
instance_double
(
Gitlab
::
JiraImport
::
IssueSerializer
,
execute:
{
key:
'data'
})
count
.
times
do
|
i
|
expect
(
Gitlab
::
JiraImport
::
IssueSerializer
).
to
receive
(
:new
)
.
with
(
project
,
jira_issues
[
i
],
current_user
.
id
,
{
iid:
i
+
1
}).
and_return
(
serializer
)
end
end
context
'when single page of results is returned'
do
before
do
...
...
@@ -48,13 +57,11 @@ describe Gitlab::JiraImport::IssuesImporter do
end
it
'schedules 2 import jobs'
do
expect
(
subject
).
to
receive
(
:fetch_issues
).
and_return
([
jira_issue1
,
jira_issue2
])
expect
(
subject
).
to
receive
(
:fetch_issues
).
with
(
0
).
and_return
([
jira_issues
[
0
],
jira_issues
[
1
]
])
expect
(
Gitlab
::
JiraImport
::
ImportIssueWorker
).
to
receive
(
:perform_async
).
twice
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_add
).
twice
.
and_call_original
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_includes?
).
twice
.
and_call_original
allow_next_instance_of
(
Gitlab
::
JiraImport
::
IssueSerializer
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
({
key:
'data'
})
end
mock_issue_serializer
(
2
)
job_waiter
=
subject
.
execute
...
...
@@ -69,13 +76,11 @@ describe Gitlab::JiraImport::IssuesImporter do
end
it
'schedules 3 import jobs'
do
expect
(
subject
).
to
receive
(
:fetch_issues
).
with
(
0
).
and_return
([
jira_issue
1
,
jira_issue2
])
expect
(
subject
).
to
receive
(
:fetch_issues
).
with
(
0
).
and_return
([
jira_issue
s
[
0
],
jira_issues
[
1
]
])
expect
(
Gitlab
::
JiraImport
::
ImportIssueWorker
).
to
receive
(
:perform_async
).
twice
.
times
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_add
).
twice
.
times
.
and_call_original
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_includes?
).
twice
.
times
.
and_call_original
allow_next_instance_of
(
Gitlab
::
JiraImport
::
IssueSerializer
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
({
key:
'data'
})
end
mock_issue_serializer
(
2
)
job_waiter
=
subject
.
execute
...
...
@@ -90,13 +95,11 @@ describe Gitlab::JiraImport::IssuesImporter do
end
it
'schedules 2 import jobs'
do
expect
(
subject
).
to
receive
(
:fetch_issues
).
with
(
0
).
and_return
([
jira_issue
1
,
jira_issue1
])
expect
(
subject
).
to
receive
(
:fetch_issues
).
with
(
0
).
and_return
([
jira_issue
s
[
0
],
jira_issues
[
0
]
])
expect
(
Gitlab
::
JiraImport
::
ImportIssueWorker
).
to
receive
(
:perform_async
).
once
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_add
).
once
.
and_call_original
expect
(
Gitlab
::
Cache
::
Import
::
Caching
).
to
receive
(
:set_includes?
).
twice
.
times
.
and_call_original
allow_next_instance_of
(
Gitlab
::
JiraImport
::
IssueSerializer
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
({
key:
'data'
})
end
mock_issue_serializer
(
1
)
job_waiter
=
subject
.
execute
...
...
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