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

Commit adc1369

Browse files
author
Ashley Baldwin-Hunter
committed
Merge pull request #76 from codeclimate/abh_update_failed_pr_message
update failed pr message
2 parents a09da57 + c239253 commit adc1369

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/cc/services/github_pull_requests.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ class Config < CC::Service::Config
2121
BASE_URL = "https://api.github.com"
2222
BODY_REGEX = %r{<b>Code Climate</b> has <a href=".*">analyzed this pull request</a>}
2323
COMMENT_BODY = '<img src="https://codeclimate.com/favicon.png" width="20" height="20" />&nbsp;<b>Code Climate</b> has <a href="%s">analyzed this pull request</a>.'
24-
2524
# Just make sure we can access GH using the configured token. Without
2625
# additional information (github-slug, PR number, etc) we can't test much
2726
# else.
27+
28+
MESSAGES = [
29+
DEFAULT_ERROR = "Code Climate encountered an error attempting to analyze this pull request",
30+
]
31+
2832
def receive_test
2933
setup_http
3034

@@ -87,8 +91,7 @@ def presenter
8791
def update_status_error
8892
update_status(
8993
"error",
90-
"Code Climate encountered an error while attempting to analyze this " +
91-
"pull request."
94+
@payload["message"] || DEFAULT_ERROR
9295
)
9396
end
9497

@@ -104,6 +107,9 @@ def update_status(state, description)
104107
target_url: @payload["details_url"],
105108
context: "codeclimate"
106109
}
110+
if state == "error"
111+
params.delete(:target_url)
112+
end
107113
@response = service_post(status_url, params.to_json)
108114
end
109115
end

test/github_pull_requests_test.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,28 @@ def test_pull_request_status_success_generic
6262
def test_pull_request_status_error
6363
expect_status_update("pbrisbin/foo", "abc123", {
6464
"state" => "error",
65-
"description" => /encountered an error/,
65+
"description" => CC::Service::GitHubPullRequests::DEFAULT_ERROR,
6666
})
6767

6868
receive_pull_request({ update_status: true }, {
6969
github_slug: "pbrisbin/foo",
7070
commit_sha: "abc123",
7171
state: "error",
72+
message: nil,
73+
})
74+
end
75+
76+
def test_pull_request_status_error_message_provided
77+
expect_status_update("pbrisbin/foo", "abc123", {
78+
"state" => "error",
79+
"description" => "descriptive message",
80+
})
81+
82+
receive_pull_request({ update_status: true }, {
83+
github_slug: "pbrisbin/foo",
84+
commit_sha: "abc123",
85+
state: "error",
86+
message: "descriptive message",
7287
})
7388
end
7489

@@ -112,6 +127,7 @@ def test_no_status_update_for_error_when_update_status_config_is_falsey
112127
github_slug: "pbrisbin/foo",
113128
commit_sha: "abc123",
114129
state: "error",
130+
message: nil,
115131
})
116132
end
117133

0 commit comments

Comments
 (0)