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

Commit b23cfa8

Browse files
author
Jon Yurek
committed
Give an OK of false if the PR comment exists
1 parent d3abaf6 commit b23cfa8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/cc/services/github_pull_requests.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,17 @@ def update_status_pending
8585
end
8686

8787
def update_status(state, description)
88-
if config.update_status
89-
params = {
90-
state: state,
91-
description: description,
92-
target_url: @payload["details_url"],
93-
context: "codeclimate"
94-
}
95-
service_post(status_url, params.to_json)
96-
end
88+
params = {
89+
state: state,
90+
description: description,
91+
target_url: @payload["details_url"],
92+
context: "codeclimate"
93+
}
94+
service_post(status_url, params.to_json)
9795
end
9896

9997
def add_comment
100-
if config.add_comment && !comment_present?
98+
if !comment_present?
10199
body = {
102100
body: COMMENT_BODY % @payload["compare_url"]
103101
}.to_json
@@ -106,6 +104,8 @@ def add_comment
106104
doc = JSON.parse(response.body)
107105
{ id: doc["id"] }
108106
end
107+
else
108+
{ ok: false, message: "Comment already present" }
109109
end
110110
end
111111

test/github_pull_requests_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_pull_request_status_error
3838
commit_sha: "abc123",
3939
state: "error",
4040
})
41-
4241
end
4342

4443
def test_pull_request_status_test_success
@@ -115,11 +114,13 @@ def test_pull_request_comment_already_present
115114

116115
# With no POST expectation, test will fail if request is made.
117116

118-
receive_pull_request({ add_comment: true }, {
117+
rsp = receive_pull_request({ add_comment: true, update_status: false }, {
119118
github_slug: "pbrisbin/foo",
120119
number: 1,
121120
state: "success",
122121
})
122+
assert_not_nil rsp
123+
assert_false rsp[:ok]
123124
end
124125

125126
private

0 commit comments

Comments
 (0)