-
Notifications
You must be signed in to change notification settings - Fork 9
Do not send status update if user disable it #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,30 +40,15 @@ def receive_test | |
|
||
def receive_pull_request | ||
setup_http | ||
state = @payload["state"] | ||
|
||
case @payload["state"] | ||
when "pending" | ||
update_status_pending | ||
when "success" | ||
if config.update_status && config.add_comment | ||
update_status_success | ||
add_comment | ||
elsif config.update_status | ||
update_status_success | ||
elsif config.add_comment | ||
add_comment | ||
else | ||
simple_failure("Nothing happened") | ||
end | ||
when "skipped" | ||
if config.update_status | ||
update_status_skipped | ||
end | ||
when "error" | ||
update_status_error | ||
if %w(pending success skipped error).include?(state) | ||
send("update_status_#{state}") | ||
else | ||
simple_failure("Unknown state") | ||
@response = simple_failure("Unknown state") | ||
end | ||
|
||
response | ||
end | ||
|
||
private | ||
|
@@ -72,19 +57,27 @@ def simple_failure(message) | |
{ ok: false, message: message } | ||
end | ||
|
||
def response | ||
@response || simple_failure("Nothing happened") | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Goodbye cruel conditionals! |
||
def update_status_skipped | ||
update_status("success", "Code Climate has skipped analysis of this commit.") | ||
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.") | ||
add_comment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in love with having status mixed in with commenting, but it's a larger issue with this class in general (that it does two things). Commenting should go away soon, so I'm ok with this. However -- I think we swap the order of these lines for now. We're not capturing both results in the response back (just the last one), but the PR one is the more important one right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. This class is doing too much. I'm fine with the swap, but that means we're actually change the functionality of this (and its return value). Currently, we return the status of add comment only. Do you think we should swap it anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fair. Perhaps a separate PR then is appropriate for this change. I think it's in scope however, because we're now capturing the result of these calls -- and the most important result is the one that comes back from posting a status to a PR (not the comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Let's do that swap in another PR. 🥚 |
||
end | ||
|
||
def update_status_error | ||
update_status( | ||
"error", | ||
"Code Climate encountered an error while attempting to analyze this " + | ||
"pull request." | ||
"pull request." | ||
) | ||
end | ||
|
||
|
@@ -93,27 +86,34 @@ def update_status_pending | |
end | ||
|
||
def update_status(state, description) | ||
params = { | ||
state: state, | ||
description: description, | ||
target_url: @payload["details_url"], | ||
context: "codeclimate" | ||
} | ||
service_post(status_url, params.to_json) | ||
if config.update_status | ||
params = { | ||
state: state, | ||
description: description, | ||
target_url: @payload["details_url"], | ||
context: "codeclimate" | ||
} | ||
@response = service_post(status_url, params.to_json) | ||
end | ||
end | ||
|
||
def add_comment | ||
if !comment_present? | ||
body = { | ||
body: COMMENT_BODY % @payload["compare_url"] | ||
}.to_json | ||
|
||
service_post(comments_url, body) do |response| | ||
doc = JSON.parse(response.body) | ||
{ id: doc["id"] } | ||
if config.add_comment | ||
if !comment_present? | ||
body = { | ||
body: COMMENT_BODY % @payload["compare_url"] | ||
}.to_json | ||
|
||
@response = service_post(comments_url, body) do |response| | ||
doc = JSON.parse(response.body) | ||
{ id: doc["id"] } | ||
end | ||
else | ||
@response = { | ||
ok: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be a pre-existing problem but I don't think this branch should respond with My understanding is that an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's also the current behavior. If we're to change it, let's do it in another PR/card. But yeah, I agree with you. It used to be the case where the return value may/may not matter, but now it does matter. |
||
message: "Comment already present" | ||
} | ||
end | ||
else | ||
{ ok: false, message: "Comment already present" } | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is getting pretty long and hard to read. Ideas on breaking it down? De-compose the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@noahd1 - I think the new
#receive_pull_request
is easier to understand. wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍