Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 6806316

Browse files
author
Jon Yurek
committed
Give a not-ok result if there is no handler
1 parent b4bb9b2 commit 6806316

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

lib/cc/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def receive
8787
end
8888
end
8989

90-
nil
90+
{ ok: false, message: "No service handler found" }
9191
end
9292

9393
private

lib/cc/services/github_pull_requests.rb

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def receive_test
3434
elsif config.add_comment
3535
receive_test_comment
3636
else
37-
{ ok: true, message: "Nothing happened" }
37+
simple_failure("Nothing happened")
3838
end
3939
end
4040

@@ -43,21 +43,47 @@ def receive_pull_request
4343

4444
case @payload["state"]
4545
when "pending"
46-
update_status("pending", "Code Climate is analyzing this code.")
46+
update_status_pending
4747
when "success"
48-
add_comment
49-
update_status("success", "Code Climate has analyzed this pull request.")
48+
if config.update_status && config.add_comment
49+
update_status_success
50+
add_comment
51+
elsif config.update_status
52+
update_status_success
53+
elsif config.add_comment
54+
add_comment
55+
else
56+
simple_failure("Nothing happened")
57+
end
5058
when "error"
51-
update_status(
52-
"error",
53-
"Code Climate encountered an error while attempting to analyze this " +
54-
"pull request."
55-
)
59+
update_status_error
60+
else
61+
simple_failure("Unknown state")
5662
end
5763
end
5864

5965
private
6066

67+
def simple_failure(message)
68+
{ ok: false, message: message }
69+
end
70+
71+
def update_status_success
72+
update_status("success", "Code Climate has analyzed this pull request.")
73+
end
74+
75+
def update_status_error
76+
update_status(
77+
"error",
78+
"Code Climate encountered an error while attempting to analyze this " +
79+
"pull request."
80+
)
81+
end
82+
83+
def update_status_pending
84+
update_status("pending", "Code Climate is analyzing this code.")
85+
end
86+
6187
def update_status(state, description)
6288
if config.update_status
6389
params = {

test/service_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ def test_custom_path_to_ca_file
2121
ENV.delete("CODECLIMATE_CA_FILE")
2222
end
2323

24+
def test_nothing_has_a_handler
25+
service = CC::Service.new({}, {name: "test"})
26+
27+
result = service.receive
28+
29+
assert_equal false, result[:ok]
30+
assert_equal "No service handler found", result[:message]
31+
end
32+
2433
def test_post_success
2534
stub_http("/my/test/url", [200, {}, '{"ok": true, "thing": "123"}'])
2635

0 commit comments

Comments
 (0)