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

Commit 1be27de

Browse files
committed
Merge pull request #74 from codeclimate/mg-unexpected-value
Fix nil response when sending snapshot to Slack
2 parents 50cb9b7 + 4dcc840 commit 1be27de

File tree

4 files changed

+8
-26
lines changed

4 files changed

+8
-26
lines changed

lib/cc/formatters/snapshot_formatter.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ def initialize(payload)
5959
@improved_constants_payload = data.merge("constants" => improved_constants) if improved_constants.any?
6060
end
6161

62-
def changed?
63-
alert_constants_payload.present? || improved_constants_payload.present?
64-
end
65-
6662
private
6763

6864
def new_constants_selector

lib/cc/services/slack.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ def receive_test
2323
end
2424

2525
def receive_snapshot
26-
snapshot = CC::Formatters::SnapshotFormatter::Base.new(payload)
27-
28-
if snapshot.changed?
29-
send_snapshot_to_slack(snapshot)
30-
else
31-
{ ok: false, ignored: true, message: "No changes in snapshot" }
32-
end
26+
send_snapshot_to_slack(CC::Formatters::SnapshotFormatter::Base.new(payload))
3327
end
3428

3529
def receive_coverage
@@ -71,12 +65,14 @@ def speak(message, color = nil)
7165

7266
def send_snapshot_to_slack(snapshot)
7367
if snapshot.alert_constants_payload
74-
speak(alerts_message(snapshot.alert_constants_payload), RED_HEX)
68+
@response = speak(alerts_message(snapshot.alert_constants_payload), RED_HEX)
7569
end
7670

7771
if snapshot.improved_constants_payload
78-
speak(improvements_message(snapshot.improved_constants_payload), GREEN_HEX)
72+
@response = speak(improvements_message(snapshot.improved_constants_payload), GREEN_HEX)
7973
end
74+
75+
@response || { ok: false, ignored: true, message: "No changes in snapshot" }
8076
end
8177

8278
def alerts_message(constants_payload)

test/formatters/snapshot_formatter_test.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,4 @@ def test_snapshot_formatter_test_with_relaxed_constraints
4444
refute_nil f.alert_constants_payload
4545
refute_nil f.improved_constants_payload
4646
end
47-
48-
def test_changed_when_snapshot_changed
49-
f = described_class.new({"new_constants" => [],
50-
"changed_constants" => [{"to" => {"rating" => "A"}, "from" => {"rating" => "D"}}]
51-
})
52-
assert f.changed?
53-
end
54-
55-
def test_changed_when_no_changes
56-
f = described_class.new({"new_constants" => [], "changed_constants" => []})
57-
refute f.changed?
58-
end
5947
end

test/slack_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ def test_quality_alert_with_new_constants
8080
"changed_constants" => [],
8181
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z" }
8282

83-
assert_slack_receives(CC::Service::Slack::RED_HEX, data,
83+
response = assert_slack_receives(CC::Service::Slack::RED_HEX, data,
8484
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
8585
8686
• _Foo_ was just created and is a *D*
8787
• _bar.js_ was just created and is an *F*""")
88+
89+
assert response[:ok]
8890
end
8991

9092
def test_quality_alert_with_new_constants_and_declined_constants

0 commit comments

Comments
 (0)