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
a0904651
Commit
a0904651
authored
Apr 29, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix creating labels for Jira import
parent
cc08fb76
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
9 deletions
+28
-9
app/workers/gitlab/jira_import/import_issue_worker.rb
app/workers/gitlab/jira_import/import_issue_worker.rb
+12
-6
spec/workers/gitlab/jira_import/import_issue_worker_spec.rb
spec/workers/gitlab/jira_import/import_issue_worker_spec.rb
+16
-3
No files found.
app/workers/gitlab/jira_import/import_issue_worker.rb
View file @
a0904651
...
...
@@ -28,19 +28,25 @@ module Gitlab
private
def
create_issue
(
issue_attributes
,
project_id
)
label_ids
=
issue_attributes
.
delete
(
'label_ids'
)
issue_id
=
insert_and_return_id
(
issue_attributes
,
Issue
)
label_issue
(
project_id
,
issue_id
)
label_issue
(
project_id
,
issue_id
,
label_ids
)
issue_id
end
def
label_issue
(
project_id
,
issue_id
)
label_id
=
JiraImport
.
get_import_label_id
(
project_id
)
return
unless
label_id
def
label_issue
(
project_id
,
issue_id
,
label_ids
)
label_link_attrs
=
label_ids
.
to_a
.
map
do
|
label_id
|
build_label_attrs
(
issue_id
,
label_id
.
to_i
)
end
import_label_id
=
JiraImport
.
get_import_label_id
(
project_id
)
return
unless
import_label_id
label_link_attrs
<<
build_label_attrs
(
issue_id
,
import_label_id
.
to_i
)
label_link_attrs
=
build_label_attrs
(
issue_id
,
label_id
.
to_i
)
insert_and_return_id
(
label_link_attrs
,
LabelLink
)
Gitlab
::
Database
.
bulk_insert
(
LabelLink
.
table_name
,
label_link_attrs
)
end
def
build_label_attrs
(
issue_id
,
label_id
)
...
...
spec/workers/gitlab/jira_import/import_issue_worker_spec.rb
View file @
a0904651
...
...
@@ -5,6 +5,8 @@ require 'spec_helper'
describe
Gitlab
::
JiraImport
::
ImportIssueWorker
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:jira_issue_label_1
)
{
create
(
:label
,
project:
project
)
}
let_it_be
(
:jira_issue_label_2
)
{
create
(
:label
,
project:
project
)
}
let
(
:some_key
)
{
'some-key'
}
describe
'modules'
do
...
...
@@ -17,7 +19,10 @@ describe Gitlab::JiraImport::ImportIssueWorker do
subject
{
described_class
.
new
}
describe
'#perform'
,
:clean_gitlab_redis_cache
do
let
(
:issue_attrs
)
{
build
(
:issue
,
project_id:
project
.
id
).
as_json
.
compact
}
let
(
:issue_attrs
)
do
build
(
:issue
,
project_id:
project
.
id
,
title:
'jira issue'
)
.
as_json
.
merge
(
'label_ids'
=>
[
jira_issue_label_1
.
id
,
jira_issue_label_2
.
id
]).
compact
end
context
'when any exception raised while inserting to DB'
do
before
do
...
...
@@ -47,14 +52,22 @@ describe Gitlab::JiraImport::ImportIssueWorker do
context
'when import label exists'
do
before
do
Gitlab
::
JiraImport
.
cache_import_label_id
(
project
.
id
,
label
.
id
)
end
it
'does not record import failure'
do
subject
.
perform
(
project
.
id
,
123
,
issue_attrs
,
some_key
)
end
it
'does not record import failure'
do
expect
(
label
.
issues
.
count
).
to
eq
(
1
)
expect
(
Gitlab
::
Cache
::
Import
::
Caching
.
read
(
Gitlab
::
JiraImport
.
failed_issues_counter_cache_key
(
project
.
id
)).
to_i
).
to
eq
(
0
)
end
it
'creates an issue with the correct attributes'
do
issue
=
Issue
.
last
expect
(
issue
.
title
).
to
eq
(
'jira issue'
)
expect
(
issue
.
project
).
to
eq
(
project
)
expect
(
issue
.
labels
).
to
match_array
([
label
,
jira_issue_label_1
,
jira_issue_label_2
])
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