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
8944a2f8
Commit
8944a2f8
authored
Jan 27, 2020
by
Arturo Herrero
Committed by
James Lopez
Jan 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More verbose JiraService error logs
parent
02ccaf48
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
26 deletions
+46
-26
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+14
-6
changelogs/unreleased/198411-more-verbose-jira-error-logs.yml
...gelogs/unreleased/198411-more-verbose-jira-error-logs.yml
+5
-0
spec/models/project_services/jira_service_spec.rb
spec/models/project_services/jira_service_spec.rb
+27
-20
No files found.
app/models/project_services/jira_service.rb
View file @
8944a2f8
...
@@ -194,7 +194,7 @@ class JiraService < IssueTrackerService
...
@@ -194,7 +194,7 @@ class JiraService < IssueTrackerService
def
test
(
_
)
def
test
(
_
)
result
=
test_settings
result
=
test_settings
success
=
result
.
present?
success
=
result
.
present?
result
=
@error
if
@error
&&
!
success
result
=
@error
&
.
message
unless
success
{
success:
success
,
result:
result
}
{
success:
success
,
result:
result
}
end
end
...
@@ -205,6 +205,8 @@ class JiraService < IssueTrackerService
...
@@ -205,6 +205,8 @@ class JiraService < IssueTrackerService
nil
nil
end
end
private
def
test_settings
def
test_settings
return
unless
client_url
.
present?
return
unless
client_url
.
present?
...
@@ -212,8 +214,6 @@ class JiraService < IssueTrackerService
...
@@ -212,8 +214,6 @@ class JiraService < IssueTrackerService
jira_request
{
client
.
ServerInfo
.
all
.
attrs
}
jira_request
{
client
.
ServerInfo
.
all
.
attrs
}
end
end
private
def
can_cross_reference?
(
noteable
)
def
can_cross_reference?
(
noteable
)
case
noteable
case
noteable
when
Commit
then
commit_events
when
Commit
then
commit_events
...
@@ -346,9 +346,17 @@ class JiraService < IssueTrackerService
...
@@ -346,9 +346,17 @@ class JiraService < IssueTrackerService
# Handle errors when doing Jira API calls
# Handle errors when doing Jira API calls
def
jira_request
def
jira_request
yield
yield
rescue
Timeout
::
Error
,
Errno
::
EINVAL
,
Errno
::
ECONNRESET
,
Errno
::
ECONNREFUSED
,
URI
::
InvalidURIError
,
JIRA
::
HTTPError
,
OpenSSL
::
SSL
::
SSLError
=>
e
rescue
Timeout
::
Error
,
Errno
::
EINVAL
,
Errno
::
ECONNRESET
,
Errno
::
ECONNREFUSED
,
URI
::
InvalidURIError
,
JIRA
::
HTTPError
,
OpenSSL
::
SSL
::
SSLError
=>
error
@error
=
e
.
message
@error
=
error
log_error
(
"Error sending message"
,
client_url:
client_url
,
error:
@error
)
log_error
(
"Error sending message"
,
client_url:
client_url
,
error:
{
exception_class:
error
.
class
.
name
,
exception_message:
error
.
message
,
exception_backtrace:
error
.
backtrace
.
join
(
"
\n
"
)
}
)
nil
nil
end
end
...
...
changelogs/unreleased/198411-more-verbose-jira-error-logs.yml
0 → 100644
View file @
8944a2f8
---
title
:
More verbose JiraService error logs
merge_request
:
23688
author
:
type
:
other
spec/models/project_services/jira_service_spec.rb
View file @
8944a2f8
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
require
'spec_helper'
require
'spec_helper'
describe
JiraService
do
describe
JiraService
do
include
Gitlab
::
Routing
include
AssetsHelpers
include
AssetsHelpers
let
(
:title
)
{
'custom title'
}
let
(
:title
)
{
'custom title'
}
...
@@ -543,47 +542,55 @@ describe JiraService do
...
@@ -543,47 +542,55 @@ describe JiraService do
end
end
end
end
describe
'#test
_settings
'
do
describe
'#test'
do
let
(
:jira_service
)
do
let
(
:jira_service
)
do
described_class
.
new
(
described_class
.
new
(
project:
create
(
:project
),
url:
url
,
url:
'http://jira.example.com'
,
username:
username
,
username:
'jira_username'
,
password:
password
password:
'jira_password'
)
)
end
end
def
test_settings
(
api_url
=
nil
)
def
test_settings
(
url
=
'jira.example.com'
)
api_url
||=
'jira.example.com'
test_url
=
"http://
#{
url
}
/rest/api/2/serverInfo"
test_url
=
"http://
#{
api_url
}
/rest/api/2/serverInfo"
WebMock
.
stub_request
(
:get
,
test_url
).
with
(
basic_auth:
%w(jira_username jira_password)
).
to_return
(
body:
{
url:
'http://url'
}.
to_json
)
WebMock
.
stub_request
(
:get
,
test_url
).
with
(
basic_auth:
[
username
,
password
])
.
to_return
(
body:
{
url:
'http://url'
}.
to_json
)
jira_service
.
test
(
nil
)
jira_service
.
test
(
nil
)
end
end
context
'when the test succeeds'
do
context
'when the test succeeds'
do
it
'
tries to get
Jira project with URL when API URL not set'
do
it
'
gets
Jira project with URL when API URL not set'
do
test_settings
(
'jira.example.com'
)
expect
(
test_settings
).
to
eq
(
success:
true
,
result:
{
'url'
=>
'http://url'
}
)
end
end
it
'returns correct result'
do
it
'gets Jira project with API URL if set'
do
expect
(
test_settings
).
to
eq
(
{
success:
true
,
result:
{
'url'
=>
'http://url'
}
})
end
it
'tries to get Jira project with API URL if set'
do
jira_service
.
update
(
api_url:
'http://jira.api.com'
)
jira_service
.
update
(
api_url:
'http://jira.api.com'
)
test_settings
(
'jira.api.com'
)
expect
(
test_settings
(
'jira.api.com'
)).
to
eq
(
success:
true
,
result:
{
'url'
=>
'http://url'
})
end
end
end
end
context
'when the test fails'
do
context
'when the test fails'
do
it
'returns result with the error'
do
it
'returns result with the error'
do
test_url
=
'http://jira.example.com/rest/api/2/serverInfo'
test_url
=
'http://jira.example.com/rest/api/2/serverInfo'
WebMock
.
stub_request
(
:get
,
test_url
).
with
(
basic_auth:
%w(jira_username jira_password)
)
WebMock
.
stub_request
(
:get
,
test_url
).
with
(
basic_auth:
[
username
,
password
])
.
to_raise
(
JIRA
::
HTTPError
.
new
(
double
(
message:
'Some specific failure.'
)))
.
to_raise
(
JIRA
::
HTTPError
.
new
(
double
(
message:
'Some specific failure.'
)))
expect
(
jira_service
.
test
(
nil
)).
to
eq
(
{
success:
false
,
result:
'Some specific failure.'
})
expect
(
jira_service
).
to
receive
(
:log_error
).
with
(
"Error sending message"
,
hash_including
(
client_url:
url
,
error:
hash_including
(
exception_class:
'JIRA::HTTPError'
,
exception_message:
'Some specific failure.'
)
)
)
expect
(
jira_service
.
test
(
nil
)).
to
eq
(
success:
false
,
result:
'Some specific failure.'
)
end
end
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