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
9dea1569
Commit
9dea1569
authored
Apr 02, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor validation of jira imports
- also small refactoring of specs
parent
2babea36
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
26 deletions
+43
-26
app/models/project.rb
app/models/project.rb
+10
-0
app/services/jira_import/start_import_service.rb
app/services/jira_import/start_import_service.rb
+4
-4
lib/gitlab/jira_import/base_importer.rb
lib/gitlab/jira_import/base_importer.rb
+2
-2
spec/requests/api/graphql/mutations/jira_import/start_spec.rb
.../requests/api/graphql/mutations/jira_import/start_spec.rb
+6
-6
spec/services/jira_import/start_import_service_spec.rb
spec/services/jira_import/start_import_service_spec.rb
+21
-14
No files found.
app/models/project.rb
View file @
9dea1569
...
@@ -866,6 +866,16 @@ class Project < ApplicationRecord
...
@@ -866,6 +866,16 @@ class Project < ApplicationRecord
latest_jira_import
&
.
status
||
'initial'
latest_jira_import
&
.
status
||
'initial'
end
end
def
validate_jira_import_settings!
(
user:
nil
)
raise
Projects
::
ImportService
::
Error
,
_
(
'Jira import feature is disabled.'
)
unless
jira_issues_import_feature_flag_enabled?
raise
Projects
::
ImportService
::
Error
,
_
(
'Jira integration not configured.'
)
unless
jira_service
&
.
active?
return
unless
user
raise
Projects
::
ImportService
::
Error
,
_
(
'Cannot import because issues are not available in this project.'
)
unless
feature_available?
(
:issues
,
user
)
raise
Projects
::
ImportService
::
Error
,
_
(
'You do not have permissions to run the import.'
)
unless
user
.
can?
(
:admin_project
,
self
)
end
def
human_import_status_name
def
human_import_status_name
import_state
&
.
human_status_name
||
'none'
import_state
&
.
human_status_name
||
'none'
end
end
...
...
app/services/jira_import/start_import_service.rb
View file @
9dea1569
...
@@ -62,12 +62,12 @@ module JiraImport
...
@@ -62,12 +62,12 @@ module JiraImport
end
end
def
validate
def
validate
return
build_error_response
(
_
(
'Jira import feature is disabled.'
))
unless
project
.
jira_issues_import_feature_flag_enabled?
project
.
validate_jira_import_settings!
(
user:
user
)
return
build_error_response
(
_
(
'You do not have permissions to run the import.'
))
unless
user
.
can?
(
:admin_project
,
project
)
return
build_error_response
(
_
(
'Cannot import because issues are not available in this project.'
))
unless
project
.
feature_available?
(
:issues
,
user
)
return
build_error_response
(
_
(
'Jira integration not configured.'
))
unless
project
.
jira_service
&
.
active?
return
build_error_response
(
_
(
'Unable to find Jira project to import data from.'
))
if
jira_project_key
.
blank?
return
build_error_response
(
_
(
'Unable to find Jira project to import data from.'
))
if
jira_project_key
.
blank?
return
build_error_response
(
_
(
'Jira import is already running.'
))
if
import_in_progress?
return
build_error_response
(
_
(
'Jira import is already running.'
))
if
import_in_progress?
rescue
Projects
::
ImportService
::
Error
=>
e
build_error_response
(
e
.
message
)
end
end
def
build_error_response
(
message
)
def
build_error_response
(
message
)
...
...
lib/gitlab/jira_import/base_importer.rb
View file @
9dea1569
...
@@ -6,10 +6,10 @@ module Gitlab
...
@@ -6,10 +6,10 @@ module Gitlab
attr_reader
:project
,
:client
,
:formatter
,
:jira_project_key
attr_reader
:project
,
:client
,
:formatter
,
:jira_project_key
def
initialize
(
project
)
def
initialize
(
project
)
raise
Projects
::
ImportService
::
Error
,
_
(
'Jira import feature is disabled.'
)
unless
project
.
jira_issues_import_feature_flag_enabled?
project
.
validate_jira_import_settings!
raise
Projects
::
ImportService
::
Error
,
_
(
'Jira integration not configured.'
)
unless
project
.
jira_service
&
.
active?
@jira_project_key
=
project
.
latest_jira_import
&
.
jira_project_key
@jira_project_key
=
project
.
latest_jira_import
&
.
jira_project_key
raise
Projects
::
ImportService
::
Error
,
_
(
'Unable to find Jira project to import data from.'
)
unless
@jira_project_key
raise
Projects
::
ImportService
::
Error
,
_
(
'Unable to find Jira project to import data from.'
)
unless
@jira_project_key
@project
=
project
@project
=
project
...
...
spec/requests/api/graphql/mutations/jira_import/start_spec.rb
View file @
9dea1569
...
@@ -99,12 +99,6 @@ describe 'Starting a Jira Import' do
...
@@ -99,12 +99,6 @@ describe 'Starting a Jira Import' do
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Jira integration not configured.'
]
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Jira integration not configured.'
]
end
end
context
'when issues feature are disabled'
do
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:issues_disabled
)
}
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Cannot import because issues are not available in this project.'
]
end
context
'when when project has Jira service'
do
context
'when when project has Jira service'
do
let!
(
:service
)
{
create
(
:jira_service
,
project:
project
)
}
let!
(
:service
)
{
create
(
:jira_service
,
project:
project
)
}
...
@@ -112,6 +106,12 @@ describe 'Starting a Jira Import' do
...
@@ -112,6 +106,12 @@ describe 'Starting a Jira Import' do
project
.
reload
project
.
reload
end
end
context
'when issues feature are disabled'
do
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:issues_disabled
)
}
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Cannot import because issues are not available in this project.'
]
end
context
'when jira_project_key not provided'
do
context
'when jira_project_key not provided'
do
let
(
:jira_project_key
)
{
''
}
let
(
:jira_project_key
)
{
''
}
...
...
spec/services/jira_import/start_import_service_spec.rb
View file @
9dea1569
...
@@ -5,8 +5,9 @@ require 'spec_helper'
...
@@ -5,8 +5,9 @@ require 'spec_helper'
describe
JiraImport
::
StartImportService
do
describe
JiraImport
::
StartImportService
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
)
}
let
(
:key
)
{
'KEY'
}
subject
{
described_class
.
new
(
user
,
project
,
''
).
execute
}
subject
{
described_class
.
new
(
user
,
project
,
key
).
execute
}
context
'when feature flag disabled'
do
context
'when feature flag disabled'
do
before
do
before
do
...
@@ -23,6 +24,8 @@ describe JiraImport::StartImportService do
...
@@ -23,6 +24,8 @@ describe JiraImport::StartImportService do
context
'when user does not have permissions to run the import'
do
context
'when user does not have permissions to run the import'
do
before
do
before
do
create
(
:jira_service
,
project:
project
,
active:
true
)
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
...
@@ -38,19 +41,21 @@ describe JiraImport::StartImportService do
...
@@ -38,19 +41,21 @@ describe JiraImport::StartImportService do
it_behaves_like
'responds with error'
,
'Jira integration not configured.'
it_behaves_like
'responds with error'
,
'Jira integration not configured.'
end
end
context
'when issues feature are disabled'
do
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:issues_disabled
)
}
it_behaves_like
'responds with error'
,
'Cannot import because issues are not available in this project.'
end
context
'when Jira service exists'
do
context
'when Jira service exists'
do
let!
(
:jira_service
)
{
create
(
:jira_service
,
project:
project
,
active:
true
)
}
let!
(
:jira_service
)
{
create
(
:jira_service
,
project:
project
,
active:
true
)
}
context
'when Jira project key is not provided'
do
context
'when Jira project key is not provided'
do
let
(
:key
)
{
''
}
it_behaves_like
'responds with error'
,
'Unable to find Jira project to import data from.'
it_behaves_like
'responds with error'
,
'Unable to find Jira project to import data from.'
end
end
context
'when issues feature are disabled'
do
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:issues_disabled
)
}
it_behaves_like
'responds with error'
,
'Cannot import because issues are not available in this project.'
end
context
'when correct data provided'
do
context
'when correct data provided'
do
let
(
:fake_key
)
{
'some-key'
}
let
(
:fake_key
)
{
'some-key'
}
...
@@ -62,15 +67,17 @@ describe JiraImport::StartImportService do
...
@@ -62,15 +67,17 @@ describe JiraImport::StartImportService do
it_behaves_like
'responds with error'
,
'Jira import is already running.'
it_behaves_like
'responds with error'
,
'Jira import is already running.'
end
end
it
'returns success response'
do
context
'when everything is ok'
do
expect
(
subject
).
to
be_a
(
ServiceResponse
)
it
'returns success response'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_a
(
ServiceResponse
)
end
expect
(
subject
).
to
be_success
end
it
'schedules jira import'
do
it
'schedules jira import'
do
subject
subject
expect
(
project
.
latest_jira_import
).
to
be_scheduled
expect
(
project
.
latest_jira_import
).
to
be_scheduled
end
end
end
it
'creates jira import data'
do
it
'creates jira import data'
do
...
...
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