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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
23790570
Commit
23790570
authored
Aug 12, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide more feedback what went wrong if HipChat service failed test
Issue gitlab-com/support-forum#213
parent
cb6ad67f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
3 deletions
+76
-3
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+5
-2
app/models/project_services/hipchat_service.rb
app/models/project_services/hipchat_service.rb
+10
-0
app/models/service.rb
app/models/service.rb
+7
-1
spec/controllers/projects/services_controller_spec.rb
spec/controllers/projects/services_controller_spec.rb
+35
-0
spec/models/project_services/hipchat_service_spec.rb
spec/models/project_services/hipchat_service_spec.rb
+8
-0
spec/models/service_spec.rb
spec/models/service_spec.rb
+10
-0
No files found.
CHANGELOG
View file @
23790570
Please view this file on the master branch, on stable branches it's out of date.
Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased)
v 7.14.0 (unreleased)
- Provide more feedback what went wrong if HipChat service failed test (Stan Hu)
- Disable turbolinks when linking to Bitbucket import status (Stan Hu)
- Disable turbolinks when linking to Bitbucket import status (Stan Hu)
- Fix broken code import and display error messages if something went wrong with creating project (Stan Hu)
- Fix broken code import and display error messages if something went wrong with creating project (Stan Hu)
- Fix corrupted binary files when using API files endpoint (Stan Hu)
- Fix corrupted binary files when using API files endpoint (Stan Hu)
...
...
app/controllers/projects/services_controller.rb
View file @
23790570
...
@@ -39,10 +39,13 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -39,10 +39,13 @@ class Projects::ServicesController < Projects::ApplicationController
def
test
def
test
data
=
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
current_user
)
data
=
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
current_user
)
if
@service
.
execute
(
data
)
outcome
=
@service
.
test
(
data
)
if
outcome
[
:success
]
message
=
{
notice:
'We sent a request to the provided URL'
}
message
=
{
notice:
'We sent a request to the provided URL'
}
else
else
message
=
{
alert:
'We tried to send a request to the provided URL but an error occured'
}
error_message
=
"We tried to send a request to the provided URL but an error occurred"
error_message
<<
":
#{
outcome
[
:result
]
}
"
if
outcome
[
:result
].
present?
message
=
{
alert:
error_message
}
end
end
redirect_to
:back
,
message
redirect_to
:back
,
message
...
...
app/models/project_services/hipchat_service.rb
View file @
23790570
...
@@ -60,6 +60,16 @@ class HipchatService < Service
...
@@ -60,6 +60,16 @@ class HipchatService < Service
gate
[
room
].
send
(
'GitLab'
,
message
,
message_options
)
gate
[
room
].
send
(
'GitLab'
,
message
,
message_options
)
end
end
def
test
(
data
)
begin
result
=
execute
(
data
)
rescue
StandardError
=>
error
return
{
success:
false
,
result:
error
}
end
{
success:
true
,
result:
result
}
end
private
private
def
gate
def
gate
...
...
app/models/service.rb
View file @
23790570
...
@@ -87,10 +87,16 @@ class Service < ActiveRecord::Base
...
@@ -87,10 +87,16 @@ class Service < ActiveRecord::Base
%w(push tag_push issue merge_request)
%w(push tag_push issue merge_request)
end
end
def
execute
def
execute
(
data
)
# implement inside child
# implement inside child
end
end
def
test
(
data
)
# default implementation
result
=
execute
(
data
)
{
success:
result
.
present?
,
result:
result
}
end
def
can_test?
def
can_test?
!
project
.
empty_repo?
!
project
.
empty_repo?
end
end
...
...
spec/controllers/projects/services_controller_spec.rb
0 → 100644
View file @
23790570
require
'spec_helper'
describe
Projects
::
ServicesController
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
create
(
:service
,
project:
project
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
controller
.
instance_variable_set
(
:@project
,
project
)
controller
.
instance_variable_set
(
:@service
,
service
)
request
.
env
[
"HTTP_REFERER"
]
=
"/"
end
describe
"#test"
do
context
'success'
do
it
"should redirect and show success message"
do
expect
(
service
).
to
receive
(
:test
).
and_return
({
success:
true
,
result:
'done'
})
get
:test
,
namespace_id:
project
.
namespace
.
id
,
project_id:
project
.
id
,
id:
service
.
id
,
format: :html
expect
(
response
.
status
).
to
redirect_to
(
'/'
)
expect
(
flash
[
:notice
]).
to
eq
(
'We sent a request to the provided URL'
)
end
end
context
'failure'
do
it
"should redirect and show failure message"
do
expect
(
service
).
to
receive
(
:test
).
and_return
({
success:
false
,
result:
'Bad test'
})
get
:test
,
namespace_id:
project
.
namespace
.
id
,
project_id:
project
.
id
,
id:
service
.
id
,
format: :html
expect
(
response
.
status
).
to
redirect_to
(
'/'
)
expect
(
flash
[
:alert
]).
to
eq
(
'We tried to send a request to the provided URL but an error occurred: Bad test'
)
end
end
end
end
spec/models/project_services/hipchat_service_spec.rb
View file @
23790570
...
@@ -47,6 +47,14 @@ describe HipchatService do
...
@@ -47,6 +47,14 @@ describe HipchatService do
WebMock
.
stub_request
(
:post
,
api_url
)
WebMock
.
stub_request
(
:post
,
api_url
)
end
end
it
'should test and return errors'
do
allow
(
hipchat
).
to
receive
(
:execute
).
and_raise
(
StandardError
,
'no such room'
)
result
=
hipchat
.
test
(
push_sample_data
)
expect
(
result
[
:success
]).
to
be_falsey
expect
(
result
[
:result
].
to_s
).
to
eq
(
'no such room'
)
end
it
'should use v1 if version is provided'
do
it
'should use v1 if version is provided'
do
allow
(
hipchat
).
to
receive
(
:api_version
).
and_return
(
'v1'
)
allow
(
hipchat
).
to
receive
(
:api_version
).
and_return
(
'v1'
)
expect
(
HipChat
::
Client
).
to
receive
(
:new
).
expect
(
HipChat
::
Client
).
to
receive
(
:new
).
...
...
spec/models/service_spec.rb
View file @
23790570
...
@@ -46,6 +46,16 @@ describe Service do
...
@@ -46,6 +46,16 @@ describe Service do
describe
:can_test
do
describe
:can_test
do
it
{
expect
(
@testable
).
to
eq
(
true
)
}
it
{
expect
(
@testable
).
to
eq
(
true
)
}
end
end
describe
:test
do
let
(
:data
)
{
'test'
}
it
'test runs execute'
do
expect
(
@service
).
to
receive
(
:execute
).
with
(
data
)
@service
.
test
(
data
)
end
end
end
end
describe
"With commits"
do
describe
"With commits"
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