From 206107d32dfe9e793b7b140ab5143c974b824bb7 Mon Sep 17 00:00:00 2001 From: Melanie Gilman Date: Mon, 16 Mar 2015 16:26:55 -0400 Subject: [PATCH] Update GitHub status description for skipped builds https://trello.com/c/q3ByzTqY When analysis for a commit is skipped because a newer commit was pushed to the branch, we want to set the status to "success" so that it isn't stuck in a yellow "pending" state, but we also want to indicate that analysis didn't run on the skipped commit. So we differentiate the skipped case with a different status message. Also, never add a comment for a commit that we have skipped, regardless of the config settings. --- lib/cc/services/github_pull_requests.rb | 8 ++++++ test/github_pull_requests_test.rb | 34 ++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/cc/services/github_pull_requests.rb b/lib/cc/services/github_pull_requests.rb index b29d0f7..74a1ab7 100644 --- a/lib/cc/services/github_pull_requests.rb +++ b/lib/cc/services/github_pull_requests.rb @@ -55,6 +55,10 @@ def receive_pull_request else simple_failure("Nothing happened") end + when "skipped" + if config.update_status + update_status_skipped + end when "error" update_status_error else @@ -68,6 +72,10 @@ def simple_failure(message) { ok: false, message: message } end + def update_status_skipped + update_status("success", "Code Climate has skipped analysis of this commit.") + end + def update_status_success update_status("success", "Code Climate has analyzed this pull request.") end diff --git a/test/github_pull_requests_test.rb b/test/github_pull_requests_test.rb index 5f32cf2..027a694 100644 --- a/test/github_pull_requests_test.rb +++ b/test/github_pull_requests_test.rb @@ -40,6 +40,39 @@ def test_pull_request_status_error }) end + def test_pull_request_status_skipped + expect_status_update("pbrisbin/foo", "abc123", { + "state" => "success", + "description" => /skipped analysis/, + }) + + receive_pull_request({ update_status: true }, { + github_slug: "pbrisbin/foo", + commit_sha: "abc123", + state: "skipped", + }) + end + + def test_no_status_update_for_skips_when_update_status_config_is_falsey + # With no POST expectation, test will fail if request is made. + + receive_pull_request({}, { + github_slug: "pbrisbin/foo", + commit_sha: "abc123", + state: "skipped", + }) + end + + def test_no_comment_for_skips_regardless_of_add_comment_config + # With no POST expectation, test will fail if request is made. + + receive_pull_request({ add_comment: true }, { + github_slug: "pbrisbin/foo", + commit_sha: "abc123", + state: "skipped", + }) + end + def test_pull_request_status_test_success @stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |env| [422, {}, ""] } @@ -169,5 +202,4 @@ def receive_test(config, event_data = {}) { name: "test" }.merge(event_data) ) end - end