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
8c2143a0
Commit
8c2143a0
authored
Oct 27, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to test JIRA service when project does not have repository
parent
e4c05de7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
7 deletions
+75
-7
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+15
-0
app/views/projects/services/_form.html.haml
app/views/projects/services/_form.html.haml
+5
-2
changelogs/unreleased/issue_23032.yml
changelogs/unreleased/issue_23032.yml
+4
-0
spec/models/project_services/jira_service_spec.rb
spec/models/project_services/jira_service_spec.rb
+51
-5
No files found.
app/models/project_services/jira_service.rb
View file @
8c2143a0
...
@@ -163,6 +163,21 @@ class JiraService < IssueTrackerService
...
@@ -163,6 +163,21 @@ class JiraService < IssueTrackerService
add_comment
(
data
,
issue_key
)
add_comment
(
data
,
issue_key
)
end
end
# reason why service cannot be tested
def
disabled_title
"Please fill in Password and Username."
end
def
can_test?
username
.
present?
&&
password
.
present?
end
# JIRA does not need test data.
# We are requesting the project that belongs to the project key.
def
test_data
(
user
=
nil
,
project
=
nil
)
nil
end
def
test_settings
def
test_settings
return
unless
url
.
present?
return
unless
url
.
present?
# Test settings by getting the project
# Test settings by getting the project
...
...
app/views/projects/services/_form.html.haml
View file @
8c2143a0
...
@@ -12,6 +12,9 @@
...
@@ -12,6 +12,9 @@
=
form
.
submit
'Save changes'
,
class:
'btn btn-save'
=
form
.
submit
'Save changes'
,
class:
'btn btn-save'
-
if
@service
.
valid?
&&
@service
.
activated?
-
if
@service
.
valid?
&&
@service
.
activated?
-
disabled
=
@service
.
can_test?
?
''
:
'disabled'
-
unless
@service
.
can_test?
=
link_to
'Test settings'
,
test_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
),
class:
"btn
#{
disabled
}
"
,
title:
@service
.
disabled_title
-
disabled_class
=
'disabled'
-
disabled_title
=
@service
.
disabled_title
=
link_to
'Test settings'
,
test_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
),
class:
"btn
#{
disabled_class
}
"
,
title:
disabled_title
=
link_to
"Cancel"
,
namespace_project_services_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-cancel"
=
link_to
"Cancel"
,
namespace_project_services_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-cancel"
changelogs/unreleased/issue_23032.yml
0 → 100644
View file @
8c2143a0
---
title
:
Allow to test JIRA service settings without having a repository
merge_request
:
author
:
spec/models/project_services/jira_service_spec.rb
View file @
8c2143a0
...
@@ -33,6 +33,41 @@ describe JiraService, models: true do
...
@@ -33,6 +33,41 @@ describe JiraService, models: true do
end
end
end
end
describe
'#can_test?'
do
let
(
:jira_service
)
{
described_class
.
new
}
it
'returns false if username is blank'
do
allow
(
jira_service
).
to
receive_messages
(
url:
'http://jira.example.com'
,
username:
''
,
password:
'12345678'
)
expect
(
jira_service
.
can_test?
).
to
be_falsy
end
it
'returns false if password is blank'
do
allow
(
jira_service
).
to
receive_messages
(
url:
'http://jira.example.com'
,
username:
'tester'
,
password:
''
)
expect
(
jira_service
.
can_test?
).
to
be_falsy
end
it
'returns true if password and username are present'
do
jira_service
=
described_class
.
new
allow
(
jira_service
).
to
receive_messages
(
url:
'http://jira.example.com'
,
username:
'tester'
,
password:
'12345678'
)
expect
(
jira_service
.
can_test?
).
to
be_truthy
end
end
describe
"Execute"
do
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
...
@@ -46,16 +81,19 @@ describe JiraService, models: true do
...
@@ -46,16 +81,19 @@ describe JiraService, models: true do
service_hook:
true
,
service_hook:
true
,
url:
'http://jira.example.com'
,
url:
'http://jira.example.com'
,
username:
'gitlab_jira_username'
,
username:
'gitlab_jira_username'
,
password:
'gitlab_jira_password'
password:
'gitlab_jira_password'
,
project_key:
'GitLabProject'
)
)
@jira_service
.
save
@jira_service
.
save
project_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123'
project_issues_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123'
@transitions_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions'
@project_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/project/GitLabProject'
@comment_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment'
@transitions_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions'
@comment_url
=
'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment'
WebMock
.
stub_request
(
:get
,
project_url
)
WebMock
.
stub_request
(
:get
,
@project_url
)
WebMock
.
stub_request
(
:get
,
project_issues_url
)
WebMock
.
stub_request
(
:post
,
@transitions_url
)
WebMock
.
stub_request
(
:post
,
@transitions_url
)
WebMock
.
stub_request
(
:post
,
@comment_url
)
WebMock
.
stub_request
(
:post
,
@comment_url
)
end
end
...
@@ -99,6 +137,14 @@ describe JiraService, models: true do
...
@@ -99,6 +137,14 @@ describe JiraService, models: true do
body:
/this-is-a-custom-id/
body:
/this-is-a-custom-id/
).
once
).
once
end
end
context
"when testing"
do
it
"tries to get jira project"
do
@jira_service
.
execute
(
nil
)
expect
(
WebMock
).
to
have_requested
(
:get
,
@project_url
)
end
end
end
end
describe
"Stored password invalidation"
do
describe
"Stored password invalidation"
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