diff --git a/lib/cc/services/github_pull_requests.rb b/lib/cc/services/github_pull_requests.rb index bf89b7e..b5d9490 100644 --- a/lib/cc/services/github_pull_requests.rb +++ b/lib/cc/services/github_pull_requests.rb @@ -21,10 +21,14 @@ class Config < CC::Service::Config BASE_URL = "https://api.github.com" BODY_REGEX = %r{Code Climate has analyzed this pull request} COMMENT_BODY = ' Code Climate has analyzed this pull request.' - # Just make sure we can access GH using the configured token. Without # additional information (github-slug, PR number, etc) we can't test much # else. + + MESSAGES = [ + DEFAULT_ERROR = "Code Climate encountered an error attempting to analyze this pull request", + ] + def receive_test setup_http @@ -87,8 +91,7 @@ def presenter def update_status_error update_status( "error", - "Code Climate encountered an error while attempting to analyze this " + - "pull request." + @payload["message"] || DEFAULT_ERROR ) end @@ -104,6 +107,9 @@ def update_status(state, description) target_url: @payload["details_url"], context: "codeclimate" } + if state == "error" + params.delete(:target_url) + end @response = service_post(status_url, params.to_json) end end diff --git a/test/github_pull_requests_test.rb b/test/github_pull_requests_test.rb index cbd1333..376352e 100644 --- a/test/github_pull_requests_test.rb +++ b/test/github_pull_requests_test.rb @@ -62,13 +62,28 @@ def test_pull_request_status_success_generic def test_pull_request_status_error expect_status_update("pbrisbin/foo", "abc123", { "state" => "error", - "description" => /encountered an error/, + "description" => CC::Service::GitHubPullRequests::DEFAULT_ERROR, }) receive_pull_request({ update_status: true }, { github_slug: "pbrisbin/foo", commit_sha: "abc123", state: "error", + message: nil, + }) + end + + def test_pull_request_status_error_message_provided + expect_status_update("pbrisbin/foo", "abc123", { + "state" => "error", + "description" => "descriptive message", + }) + + receive_pull_request({ update_status: true }, { + github_slug: "pbrisbin/foo", + commit_sha: "abc123", + state: "error", + message: "descriptive message", }) end @@ -112,6 +127,7 @@ def test_no_status_update_for_error_when_update_status_config_is_falsey github_slug: "pbrisbin/foo", commit_sha: "abc123", state: "error", + message: nil, }) end