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
26657f81
Commit
26657f81
authored
Apr 23, 2020
by
Jarka Košanová
Committed by
Nick Thomas
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add format checks for complex fields
parent
b08b2cf2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
5 deletions
+105
-5
lib/gitlab/jira_import/metadata_collector.rb
lib/gitlab/jira_import/metadata_collector.rb
+8
-4
spec/lib/gitlab/jira_import/metadata_collector_spec.rb
spec/lib/gitlab/jira_import/metadata_collector_spec.rb
+97
-1
No files found.
lib/gitlab/jira_import/metadata_collector.rb
View file @
26657f81
...
...
@@ -34,22 +34,26 @@ module Gitlab
end
def
add_labels
return
if
fields
[
'labels'
].
blank?
return
if
fields
[
'labels'
].
blank?
||
!
fields
[
'labels'
].
is_a?
(
Array
)
metadata
<<
"- Labels:
#{
fields
[
'labels'
].
join
(
', '
)
}
"
end
def
add_parent
parent_issue_key
=
fields
.
dig
(
'parent'
,
'key'
)
return
if
parent_issue_key
.
blank?
metadata
<<
"- Parent issue: [
#{
parent_issue_key
}
]
#{
fields
[
'parent'
][
'fields'
][
'summary'
]
}
"
parent_summary_key
=
fields
.
dig
(
'parent'
,
'fields'
,
'summary'
)
metadata
<<
"- Parent issue: [
#{
parent_issue_key
}
]
#{
parent_summary_key
}
"
.
strip
end
def
add_versions
return
if
fields
[
'fixVersions'
].
blank?
return
if
fields
[
'fixVersions'
].
blank?
||
!
fields
[
'fixVersions'
].
is_a?
(
Array
)
metadata
<<
"- Fix versions:
#{
fields
[
'fixVersions'
].
map
{
|
version
|
version
[
'name'
]
}
.join(', ')}"
versions
=
fields
[
'fixVersions'
].
map
{
|
version
|
version
[
'name'
]
}.
compact
.
join
(
', '
)
metadata
<<
"- Fix versions:
#{
versions
}
"
end
def
fields
...
...
spec/lib/gitlab/jira_import/metadata_collector_spec.rb
View file @
26657f81
...
...
@@ -51,7 +51,7 @@ describe Gitlab::JiraImport::MetadataCollector do
subject
{
described_class
.
new
(
jira_issue
).
execute
}
context
'when all metadata fields are present'
do
it
'
skips
writes all fields'
do
it
'writes all fields'
do
expected_result
=
<<~
MD
---
...
...
@@ -70,6 +70,102 @@ describe Gitlab::JiraImport::MetadataCollector do
end
end
context
'when some fields are in incorrect format'
do
let
(
:assignee
)
{
nil
}
let
(
:parent_field
)
{
nil
}
let
(
:fix_versions_field
)
{
[]
}
let
(
:priority_field
)
{
nil
}
let
(
:labels_field
)
{
[]
}
let
(
:environment_field
)
{
nil
}
let
(
:duedate_field
)
{
nil
}
context
'when fixVersions field is not an array'
do
let
(
:fix_versions_field
)
{
{
'title'
=>
'1.0'
,
'name'
=>
'1.1'
}
}
it
'skips these fields'
do
expected_result
=
<<~
MD
---
**Issue metadata**
- Issue type: Task
MD
expect
(
subject
.
strip
).
to
eq
(
expected_result
.
strip
)
end
end
context
'when a fixVersions element is in incorrect format'
do
let
(
:fix_versions_field
)
{
[{
'title'
=>
'1.0'
},
{
'name'
=>
'1.1'
}]
}
it
'skips the element'
do
expected_result
=
<<~
MD
---
**Issue metadata**
- Issue type: Task
- Fix versions: 1.1
MD
expect
(
subject
.
strip
).
to
eq
(
expected_result
.
strip
)
end
end
context
'when a labels field is not an array'
do
let
(
:labels_field
)
{
{
'first'
=>
'bug'
}
}
it
'skips the labels'
do
expected_result
=
<<~
MD
---
**Issue metadata**
- Issue type: Task
MD
expect
(
subject
.
strip
).
to
eq
(
expected_result
.
strip
)
end
end
context
'when a parent field has incorrectly formatted summary'
do
let
(
:parent_field
)
do
{
'key'
=>
'FOO-2'
,
'id'
=>
'1050'
,
'other_field'
=>
{
'summary'
=>
'parent issue FOO'
}
}
end
it
'skips the summary'
do
expected_result
=
<<~
MD
---
**Issue metadata**
- Issue type: Task
- Parent issue: [FOO-2]
MD
expect
(
subject
.
strip
).
to
eq
(
expected_result
.
strip
)
end
end
context
'when a parent field is missing the key'
do
let
(
:parent_field
)
do
{
'not_key'
=>
'FOO-2'
,
'id'
=>
'1050'
,
'other_field'
=>
{
'summary'
=>
'parent issue FOO'
}
}
end
it
'skips the field'
do
expected_result
=
<<~
MD
---
**Issue metadata**
- Issue type: Task
MD
expect
(
subject
.
strip
).
to
eq
(
expected_result
.
strip
)
end
end
end
context
'when some metadata fields are missing'
do
let
(
:assignee
)
{
nil
}
let
(
:parent_field
)
{
nil
}
...
...
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