codeclimate-services 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +1 -0
- data/Gemfile +1 -2
- data/Rakefile +4 -7
- data/base_rubocop.yml +152 -0
- data/bin/bundler +5 -5
- data/bin/coderay +5 -5
- data/bin/nokogiri +5 -5
- data/bin/pry +5 -5
- data/bin/rake +5 -5
- data/codeclimate-services.gemspec +15 -15
- data/config/load.rb +2 -2
- data/lib/cc/formatters/linked_formatter.rb +2 -2
- data/lib/cc/formatters/snapshot_formatter.rb +10 -10
- data/lib/cc/formatters/ticket_formatter.rb +0 -2
- data/lib/cc/helpers/quality_helper.rb +2 -2
- data/lib/cc/helpers/vulnerability_helper.rb +0 -2
- data/lib/cc/presenters/pull_requests_presenter.rb +1 -5
- data/lib/cc/pull_requests.rb +7 -3
- data/lib/cc/service.rb +9 -10
- data/lib/cc/service/formatter.rb +3 -3
- data/lib/cc/service/helper.rb +2 -3
- data/lib/cc/service/http.rb +9 -9
- data/lib/cc/service/invocation.rb +6 -6
- data/lib/cc/service/invocation/with_error_handling.rb +9 -8
- data/lib/cc/service/invocation/with_metrics.rb +4 -4
- data/lib/cc/service/invocation/with_return_values.rb +0 -1
- data/lib/cc/service/response_check.rb +4 -5
- data/lib/cc/services.rb +2 -2
- data/lib/cc/services/asana.rb +8 -9
- data/lib/cc/services/campfire.rb +2 -3
- data/lib/cc/services/flowdock.rb +5 -5
- data/lib/cc/services/github_issues.rb +6 -7
- data/lib/cc/services/github_pull_requests.rb +42 -5
- data/lib/cc/services/gitlab_merge_requests.rb +6 -2
- data/lib/cc/services/hipchat.rb +3 -4
- data/lib/cc/services/jira.rb +8 -9
- data/lib/cc/services/lighthouse.rb +4 -5
- data/lib/cc/services/pivotal_tracker.rb +6 -7
- data/lib/cc/services/slack.rb +8 -8
- data/lib/cc/services/stash_pull_requests.rb +2 -2
- data/lib/cc/services/version.rb +1 -1
- data/pull_request_test.rb +11 -10
- data/service_test.rb +5 -5
- data/spec/axiom/types/password_spec.rb +14 -0
- data/spec/cc/formatters/snapshot_formatter_spec.rb +44 -0
- data/spec/cc/presenters/pull_requests_presenter_spec.rb +45 -0
- data/{test/asana_test.rb → spec/cc/service/asana_spec.rb} +27 -29
- data/{test/campfire_test.rb → spec/cc/service/campfire_spec.rb} +40 -44
- data/{test/flowdock_test.rb → spec/cc/service/flowdock_spec.rb} +46 -48
- data/{test/github_issues_test.rb → spec/cc/service/github_issues_spec.rb} +33 -35
- data/spec/cc/service/github_pull_requests_spec.rb +223 -0
- data/{test/gitlab_merge_requests_test.rb → spec/cc/service/gitlab_merge_requests_spec.rb} +30 -35
- data/{test/hipchat_test.rb → spec/cc/service/hipchat_spec.rb} +38 -40
- data/spec/cc/service/invocation/error_handling_spec.rb +49 -0
- data/spec/cc/service/invocation/return_values_spec.rb +19 -0
- data/spec/cc/service/invocation/with_metrics_spec.rb +18 -0
- data/{test/invocation_test.rb → spec/cc/service/invocation_spec.rb} +31 -34
- data/{test/jira_test.rb → spec/cc/service/jira_spec.rb} +25 -27
- data/{test/lighthouse_test.rb → spec/cc/service/lighthouse_spec.rb} +23 -26
- data/spec/cc/service/pivotal_tracker_spec.rb +70 -0
- data/{test/slack_test.rb → spec/cc/service/slack_spec.rb} +66 -77
- data/spec/cc/service/stash_pull_requests_spec.rb +132 -0
- data/spec/cc/service_spec.rb +78 -0
- data/{test → spec}/fixtures.rb +3 -4
- data/spec/spec_helper.rb +37 -0
- data/{test → spec}/support/fake_logger.rb +0 -0
- data/spec/support/service_context.rb +42 -0
- metadata +57 -52
- data/test/axiom/types/password_test.rb +0 -22
- data/test/formatters/snapshot_formatter_test.rb +0 -47
- data/test/github_pull_requests_test.rb +0 -217
- data/test/helper.rb +0 -58
- data/test/invocation_error_handling_test.rb +0 -51
- data/test/invocation_return_values_test.rb +0 -21
- data/test/pivotal_tracker_test.rb +0 -73
- data/test/presenters/pull_requests_presenter_test.rb +0 -70
- data/test/service_test.rb +0 -84
- data/test/stash_pull_requests_test.rb +0 -146
- data/test/with_metrics_test.rb +0 -19
|
@@ -1,70 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class TestJira < CC::Service::TestCase
|
|
4
|
-
def test_successful_receive
|
|
1
|
+
describe CC::Service::Jira, type: :service do
|
|
2
|
+
it "successful receive" do
|
|
5
3
|
response = assert_jira_receives(
|
|
6
4
|
event(:quality, to: "D", from: "C"),
|
|
7
5
|
"Refactor User from a D on Code Climate",
|
|
8
|
-
"https://codeclimate.com/repos/1/feed"
|
|
6
|
+
"https://codeclimate.com/repos/1/feed",
|
|
9
7
|
)
|
|
10
|
-
|
|
8
|
+
expect(response[:id]).to eq("10000")
|
|
11
9
|
end
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
it "quality" do
|
|
14
12
|
assert_jira_receives(
|
|
15
13
|
event(:quality, to: "D", from: "C"),
|
|
16
14
|
"Refactor User from a D on Code Climate",
|
|
17
|
-
"https://codeclimate.com/repos/1/feed"
|
|
15
|
+
"https://codeclimate.com/repos/1/feed",
|
|
18
16
|
)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
it "vulnerability" do
|
|
22
20
|
assert_jira_receives(
|
|
23
21
|
event(:vulnerability, vulnerabilities: [{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
"warning_type" => "critical",
|
|
23
|
+
"location" => "app/user.rb line 120",
|
|
24
|
+
}]),
|
|
27
25
|
"New critical issue found in app/user.rb line 120",
|
|
28
|
-
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
|
|
26
|
+
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
|
|
29
27
|
)
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
it "issue" do
|
|
33
31
|
payload = {
|
|
34
32
|
issue: {
|
|
35
33
|
"check_name" => "Style/LongLine",
|
|
36
|
-
"description" => "Line is too long [1000/80]"
|
|
34
|
+
"description" => "Line is too long [1000/80]",
|
|
37
35
|
},
|
|
38
36
|
constant_name: "foo.rb",
|
|
39
|
-
details_url: "http://example.com/repos/id/foo.rb#issue_123"
|
|
37
|
+
details_url: "http://example.com/repos/id/foo.rb#issue_123",
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
assert_jira_receives(
|
|
43
41
|
event(:issue, payload),
|
|
44
42
|
"Fix \"Style/LongLine\" issue in foo.rb",
|
|
45
|
-
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
|
|
43
|
+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
|
|
46
44
|
)
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
it "receive test" do
|
|
48
|
+
http_stubs.post "/rest/api/2/issue" do |_env|
|
|
51
49
|
[200, {}, '{"id": 12345, "key": "CC-123", "self": "http://foo.bar"}']
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
response = receive_event(name: "test")
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
expect(response[:message]).to eq("Ticket <a href='https://foo.com/browse/CC-123'>12345</a> created.")
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
private
|
|
60
58
|
|
|
61
59
|
def assert_jira_receives(event_data, title, ticket_body)
|
|
62
|
-
|
|
60
|
+
http_stubs.post "/rest/api/2/issue" do |env|
|
|
63
61
|
body = JSON.parse(env[:body])
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
expect(env[:request_headers]["Authorization"]).to eq("Basic Zm9vOmJhcg==")
|
|
63
|
+
expect(body["fields"]["summary"]).to eq(title)
|
|
64
|
+
expect(body["fields"]["description"]).to eq(ticket_body)
|
|
65
|
+
expect(body["fields"]["issuetype"]["name"]).to eq("Task")
|
|
68
66
|
[200, {}, '{"id":"10000"}']
|
|
69
67
|
end
|
|
70
68
|
|
|
@@ -72,10 +70,10 @@ class TestJira < CC::Service::TestCase
|
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
def receive_event(event_data = nil)
|
|
75
|
-
|
|
73
|
+
service_receive(
|
|
76
74
|
CC::Service::Jira,
|
|
77
75
|
{ domain: "foo.com", username: "foo", password: "bar", project_id: "100" },
|
|
78
|
-
event_data || event(:quality, from: "C", to: "D")
|
|
76
|
+
event_data || event(:quality, from: "C", to: "D"),
|
|
79
77
|
)
|
|
80
78
|
end
|
|
81
79
|
end
|
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class TestLighthouse < CC::Service::TestCase
|
|
4
|
-
def test_quality
|
|
1
|
+
describe CC::Service::Lighthouse, type: :service do
|
|
2
|
+
it "quality" do
|
|
5
3
|
response = assert_lighthouse_receives(
|
|
6
4
|
event(:quality, to: "D", from: "C"),
|
|
7
5
|
"Refactor User from a D on Code Climate",
|
|
8
|
-
"https://codeclimate.com/repos/1/feed"
|
|
6
|
+
"https://codeclimate.com/repos/1/feed",
|
|
9
7
|
)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
response[:url]
|
|
8
|
+
expect(response[:id]).to eq("123")
|
|
9
|
+
expect("http://lighthouse.com/projects/123/tickets/123.json").to eq(response[:url])
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
it "vulnerability" do
|
|
16
13
|
assert_lighthouse_receives(
|
|
17
14
|
event(:vulnerability, vulnerabilities: [{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
"warning_type" => "critical",
|
|
16
|
+
"location" => "app/user.rb line 120",
|
|
17
|
+
}]),
|
|
21
18
|
"New critical issue found in app/user.rb line 120",
|
|
22
|
-
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
|
|
19
|
+
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
|
|
23
20
|
)
|
|
24
21
|
end
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
it "issue" do
|
|
27
24
|
payload = {
|
|
28
25
|
issue: {
|
|
29
26
|
"check_name" => "Style/LongLine",
|
|
30
|
-
"description" => "Line is too long [1000/80]"
|
|
27
|
+
"description" => "Line is too long [1000/80]",
|
|
31
28
|
},
|
|
32
29
|
constant_name: "foo.rb",
|
|
33
|
-
details_url: "http://example.com/repos/id/foo.rb#issue_123"
|
|
30
|
+
details_url: "http://example.com/repos/id/foo.rb#issue_123",
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
assert_lighthouse_receives(
|
|
37
34
|
event(:issue, payload),
|
|
38
35
|
"Fix \"Style/LongLine\" issue in foo.rb",
|
|
39
|
-
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
|
|
36
|
+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
|
|
40
37
|
)
|
|
41
38
|
end
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
it "receive test" do
|
|
41
|
+
http_stubs.post "projects/123/tickets.json" do |_env|
|
|
45
42
|
[200, {}, '{"ticket":{"number": "123", "url":"http://foo.bar"}}']
|
|
46
43
|
end
|
|
47
44
|
|
|
48
45
|
response = receive_event(name: "test")
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
expect(response[:message]).to eq("Ticket <a href='http://foo.bar'>123</a> created.")
|
|
51
48
|
end
|
|
52
49
|
|
|
53
50
|
private
|
|
54
51
|
|
|
55
52
|
def assert_lighthouse_receives(event_data, title, ticket_body)
|
|
56
|
-
|
|
53
|
+
http_stubs.post "projects/123/tickets.json" do |env|
|
|
57
54
|
body = JSON.parse(env[:body])
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
expect(env[:request_headers]["X-LighthouseToken"]).to eq("token")
|
|
56
|
+
expect(body["ticket"]["title"]).to eq(title)
|
|
57
|
+
expect(body["ticket"]["body"]).to eq(ticket_body)
|
|
61
58
|
[200, {}, '{"ticket":{"number": "123", "url":"http://lighthouse.com/projects/123/tickets/123.json"}}']
|
|
62
59
|
end
|
|
63
60
|
|
|
@@ -65,10 +62,10 @@ class TestLighthouse < CC::Service::TestCase
|
|
|
65
62
|
end
|
|
66
63
|
|
|
67
64
|
def receive_event(event_data = nil)
|
|
68
|
-
|
|
65
|
+
service_receive(
|
|
69
66
|
CC::Service::Lighthouse,
|
|
70
67
|
{ subdomain: "foo", api_token: "token", project_id: "123" },
|
|
71
|
-
event_data || event(:quality, from: "C", to: "D")
|
|
68
|
+
event_data || event(:quality, from: "C", to: "D"),
|
|
72
69
|
)
|
|
73
70
|
end
|
|
74
71
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
describe CC::Service::PivotalTracker, type: :service do
|
|
2
|
+
it "quality" do
|
|
3
|
+
response = assert_pivotal_receives(
|
|
4
|
+
event(:quality, to: "D", from: "C"),
|
|
5
|
+
"Refactor User from a D on Code Climate",
|
|
6
|
+
"https://codeclimate.com/repos/1/feed",
|
|
7
|
+
)
|
|
8
|
+
expect(response[:id]).to eq("123")
|
|
9
|
+
expect("http://pivotaltracker.com/n/projects/123/stories/123").to eq(response[:url])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "vulnerability" do
|
|
13
|
+
assert_pivotal_receives(
|
|
14
|
+
event(:vulnerability, vulnerabilities: [{
|
|
15
|
+
"warning_type" => "critical",
|
|
16
|
+
"location" => "app/user.rb line 120",
|
|
17
|
+
}]),
|
|
18
|
+
"New critical issue found in app/user.rb line 120",
|
|
19
|
+
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "issue" do
|
|
24
|
+
payload = {
|
|
25
|
+
issue: {
|
|
26
|
+
"check_name" => "Style/LongLine",
|
|
27
|
+
"description" => "Line is too long [1000/80]",
|
|
28
|
+
},
|
|
29
|
+
constant_name: "foo.rb",
|
|
30
|
+
details_url: "http://example.com/repos/id/foo.rb#issue_123",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
assert_pivotal_receives(
|
|
34
|
+
event(:issue, payload),
|
|
35
|
+
"Fix \"Style/LongLine\" issue in foo.rb",
|
|
36
|
+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "receive test" do
|
|
41
|
+
http_stubs.post "services/v3/projects/123/stories" do |_env|
|
|
42
|
+
[200, {}, "<story><id>123</id><url>http://foo.bar</url></story>"]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
response = receive_event(name: "test")
|
|
46
|
+
|
|
47
|
+
expect(response[:message]).to eq("Ticket <a href='http://foo.bar'>123</a> created.")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def assert_pivotal_receives(event_data, name, description)
|
|
53
|
+
http_stubs.post "services/v3/projects/123/stories" do |env|
|
|
54
|
+
body = Hash[URI.decode_www_form(env[:body])]
|
|
55
|
+
expect(env[:request_headers]["X-TrackerToken"]).to eq("token")
|
|
56
|
+
expect(body["story[name]"]).to eq(name)
|
|
57
|
+
expect(body["story[description]"]).to eq(description)
|
|
58
|
+
[200, {}, "<doc><story><id>123</id><url>http://pivotaltracker.com/n/projects/123/stories/123</url></story></doc>"]
|
|
59
|
+
end
|
|
60
|
+
receive_event(event_data)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def receive_event(event_data = nil)
|
|
64
|
+
service_receive(
|
|
65
|
+
CC::Service::PivotalTracker,
|
|
66
|
+
{ api_token: "token", project_id: "123" },
|
|
67
|
+
event_data || event(:quality, from: "C", to: "D"),
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require File.expand_path('../helper', __FILE__)
|
|
4
|
-
|
|
5
|
-
class TestSlack < CC::Service::TestCase
|
|
6
|
-
def test_test_hook
|
|
1
|
+
describe CC::Service::Slack, type: :service do
|
|
2
|
+
it "test hook" do
|
|
7
3
|
assert_slack_receives(
|
|
8
4
|
nil,
|
|
9
5
|
{ name: "test", repo_name: "rails" },
|
|
10
|
-
"[rails] This is a test of the Slack service hook"
|
|
6
|
+
"[rails] This is a test of the Slack service hook",
|
|
11
7
|
)
|
|
12
8
|
end
|
|
13
9
|
|
|
14
|
-
|
|
10
|
+
it "coverage improved" do
|
|
15
11
|
e = event(:coverage, to: 90.2, from: 80)
|
|
16
12
|
|
|
17
13
|
assert_slack_receives("#38ae6f", e, [
|
|
18
14
|
"[Example]",
|
|
19
15
|
"<https://codeclimate.com/repos/1/feed|Test coverage>",
|
|
20
16
|
"has improved to 90.2% (+10.2%)",
|
|
21
|
-
"(<https://codeclimate.com/repos/1/compare|Compare>)"
|
|
17
|
+
"(<https://codeclimate.com/repos/1/compare|Compare>)",
|
|
22
18
|
].join(" "))
|
|
23
19
|
end
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
it "coverage declined" do
|
|
26
22
|
e = event(:coverage, to: 88.6, from: 94.6)
|
|
27
23
|
|
|
28
24
|
assert_slack_receives("#ed2f00", e, [
|
|
29
25
|
"[Example]",
|
|
30
26
|
"<https://codeclimate.com/repos/1/feed|Test coverage>",
|
|
31
27
|
"has declined to 88.6% (-6.0%)",
|
|
32
|
-
"(<https://codeclimate.com/repos/1/compare|Compare>)"
|
|
28
|
+
"(<https://codeclimate.com/repos/1/compare|Compare>)",
|
|
33
29
|
].join(" "))
|
|
34
30
|
end
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
it "single vulnerability" do
|
|
37
33
|
e = event(:vulnerability, vulnerabilities: [
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
{ "warning_type" => "critical" },
|
|
35
|
+
])
|
|
40
36
|
|
|
41
37
|
assert_slack_receives(nil, e, [
|
|
42
38
|
"[Example]",
|
|
@@ -45,11 +41,11 @@ class TestSlack < CC::Service::TestCase
|
|
|
45
41
|
].join(" "))
|
|
46
42
|
end
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
it "single vulnerability with location" do
|
|
49
45
|
e = event(:vulnerability, vulnerabilities: [{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
"warning_type" => "critical",
|
|
47
|
+
"location" => "app/user.rb line 120",
|
|
48
|
+
}])
|
|
53
49
|
|
|
54
50
|
assert_slack_receives(nil, e, [
|
|
55
51
|
"[Example]",
|
|
@@ -58,14 +54,14 @@ class TestSlack < CC::Service::TestCase
|
|
|
58
54
|
].join(" "))
|
|
59
55
|
end
|
|
60
56
|
|
|
61
|
-
|
|
57
|
+
it "multiple vulnerabilities" do
|
|
62
58
|
e = event(:vulnerability, warning_type: "critical", vulnerabilities: [{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
"warning_type" => "unused",
|
|
60
|
+
"location" => "unused",
|
|
61
|
+
}, {
|
|
62
|
+
"warning_type" => "unused",
|
|
63
|
+
"location" => "unused",
|
|
64
|
+
}])
|
|
69
65
|
|
|
70
66
|
assert_slack_receives(nil, e, [
|
|
71
67
|
"[Example]",
|
|
@@ -74,49 +70,47 @@ class TestSlack < CC::Service::TestCase
|
|
|
74
70
|
].join(" "))
|
|
75
71
|
end
|
|
76
72
|
|
|
77
|
-
|
|
73
|
+
it "quality alert with new constants" do
|
|
78
74
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
79
|
-
"new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}, {"name" => "bar.js", "to" => {"rating" => "F"}}],
|
|
75
|
+
"new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }, { "name" => "bar.js", "to" => { "rating" => "F" } }],
|
|
80
76
|
"changed_constants" => [],
|
|
81
77
|
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z" }
|
|
82
78
|
|
|
83
79
|
response = assert_slack_receives(CC::Service::Slack::RED_HEX, data,
|
|
84
|
-
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
80
|
+
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
85
81
|
|
|
86
82
|
• _Foo_ was just created and is a *D*
|
|
87
83
|
• _bar.js_ was just created and is an *F*""")
|
|
88
84
|
|
|
89
|
-
|
|
85
|
+
expect(response[:ok]).to eq(true)
|
|
90
86
|
end
|
|
91
87
|
|
|
92
|
-
|
|
88
|
+
it "quality alert with new constants and declined constants" do
|
|
93
89
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
94
|
-
"new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}],
|
|
95
|
-
"changed_constants" => [{"name" => "bar.js", "from" => {"rating" => "A"}, "to" => {"rating" => "F"}}],
|
|
90
|
+
"new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }],
|
|
91
|
+
"changed_constants" => [{ "name" => "bar.js", "from" => { "rating" => "A" }, "to" => { "rating" => "F" } }],
|
|
96
92
|
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z" }
|
|
97
93
|
|
|
98
94
|
assert_slack_receives(CC::Service::Slack::RED_HEX, data,
|
|
99
|
-
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
95
|
+
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
100
96
|
|
|
101
97
|
• _Foo_ was just created and is a *D*
|
|
102
98
|
• _bar.js_ just declined from an *A* to an *F*""")
|
|
103
99
|
end
|
|
104
100
|
|
|
105
|
-
|
|
101
|
+
it "quality alert with new constants and declined constants overflown" do
|
|
106
102
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
107
|
-
"new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}],
|
|
103
|
+
"new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }],
|
|
108
104
|
"changed_constants" => [
|
|
109
|
-
{"name" => "bar.js", "from" => {"rating" => "A"}, "to" => {"rating" => "F"}},
|
|
110
|
-
{"name" => "baz.js", "from" => {"rating" => "B"}, "to" => {"rating" => "D"}},
|
|
111
|
-
{"name" => "Qux",
|
|
105
|
+
{ "name" => "bar.js", "from" => { "rating" => "A" }, "to" => { "rating" => "F" } },
|
|
106
|
+
{ "name" => "baz.js", "from" => { "rating" => "B" }, "to" => { "rating" => "D" } },
|
|
107
|
+
{ "name" => "Qux", "from" => { "rating" => "A" }, "to" => { "rating" => "D" } },
|
|
112
108
|
],
|
|
113
109
|
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
|
|
114
|
-
"details_url" => "https://codeclimate.com/repos/1/feed"
|
|
115
|
-
}
|
|
116
|
-
|
|
110
|
+
"details_url" => "https://codeclimate.com/repos/1/feed" }
|
|
117
111
|
|
|
118
112
|
assert_slack_receives(CC::Service::Slack::RED_HEX, data,
|
|
119
|
-
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
113
|
+
"""Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
120
114
|
|
|
121
115
|
• _Foo_ was just created and is a *D*
|
|
122
116
|
• _bar.js_ just declined from an *A* to an *F*
|
|
@@ -125,39 +119,35 @@ class TestSlack < CC::Service::TestCase
|
|
|
125
119
|
And <https://codeclimate.com/repos/1/feed|1 other change>""")
|
|
126
120
|
end
|
|
127
121
|
|
|
128
|
-
|
|
122
|
+
it "quality improvements" do
|
|
129
123
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
130
124
|
"new_constants" => [],
|
|
131
125
|
"changed_constants" => [
|
|
132
|
-
{"name" => "bar.js", "from" => {"rating" => "F"}, "to" => {"rating" => "A"}},
|
|
126
|
+
{ "name" => "bar.js", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
|
|
133
127
|
],
|
|
134
128
|
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
|
|
135
|
-
"details_url" => "https://codeclimate.com/repos/1/feed"
|
|
136
|
-
}
|
|
137
|
-
|
|
129
|
+
"details_url" => "https://codeclimate.com/repos/1/feed" }
|
|
138
130
|
|
|
139
131
|
assert_slack_receives(CC::Service::Slack::GREEN_HEX, data,
|
|
140
|
-
"""Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
132
|
+
"""Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
141
133
|
|
|
142
134
|
• _bar.js_ just improved from an *F* to an *A*""")
|
|
143
135
|
end
|
|
144
136
|
|
|
145
|
-
|
|
137
|
+
it "quality improvements overflown" do
|
|
146
138
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
147
139
|
"new_constants" => [],
|
|
148
140
|
"changed_constants" => [
|
|
149
|
-
{"name" => "Foo",
|
|
150
|
-
{"name" => "bar.js", "from" => {"rating" => "D"}, "to" => {"rating" => "B"}},
|
|
151
|
-
{"name" => "baz.js", "from" => {"rating" => "D"}, "to" => {"rating" => "A"}},
|
|
152
|
-
{"name" => "Qux",
|
|
141
|
+
{ "name" => "Foo", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
|
|
142
|
+
{ "name" => "bar.js", "from" => { "rating" => "D" }, "to" => { "rating" => "B" } },
|
|
143
|
+
{ "name" => "baz.js", "from" => { "rating" => "D" }, "to" => { "rating" => "A" } },
|
|
144
|
+
{ "name" => "Qux", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
|
|
153
145
|
],
|
|
154
146
|
"compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
|
|
155
|
-
"details_url" => "https://codeclimate.com/repos/1/feed"
|
|
156
|
-
}
|
|
157
|
-
|
|
147
|
+
"details_url" => "https://codeclimate.com/repos/1/feed" }
|
|
158
148
|
|
|
159
149
|
assert_slack_receives(CC::Service::Slack::GREEN_HEX, data,
|
|
160
|
-
"""Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
150
|
+
"""Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
|
|
161
151
|
|
|
162
152
|
• _Foo_ just improved from an *F* to an *A*
|
|
163
153
|
• _bar.js_ just improved from a *D* to a *B*
|
|
@@ -166,57 +156,56 @@ And <https://codeclimate.com/repos/1/feed|1 other change>""")
|
|
|
166
156
|
And <https://codeclimate.com/repos/1/feed|1 other improvement>""")
|
|
167
157
|
end
|
|
168
158
|
|
|
169
|
-
|
|
159
|
+
it "received success" do
|
|
170
160
|
response = assert_slack_receives(
|
|
171
161
|
nil,
|
|
172
162
|
{ name: "test", repo_name: "rails" },
|
|
173
|
-
"[rails] This is a test of the Slack service hook"
|
|
163
|
+
"[rails] This is a test of the Slack service hook",
|
|
174
164
|
)
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
expect(response[:ok]).to eq(true)
|
|
166
|
+
expect(response[:message]).to eq("Test message sent")
|
|
177
167
|
end
|
|
178
168
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
[200, {},
|
|
169
|
+
it "receive test" do
|
|
170
|
+
http_stubs.post "/token" do |_env|
|
|
171
|
+
[200, {}, "ok"]
|
|
182
172
|
end
|
|
183
173
|
|
|
184
174
|
response = receive_event(name: "test")
|
|
185
175
|
|
|
186
|
-
|
|
176
|
+
expect(response[:message]).to eq("Test message sent")
|
|
187
177
|
end
|
|
188
178
|
|
|
189
|
-
|
|
179
|
+
it "no changes in snapshot" do
|
|
190
180
|
data = { "name" => "snapshot", "repo_name" => "Rails",
|
|
191
181
|
"new_constants" => [],
|
|
192
|
-
"changed_constants" => []
|
|
193
|
-
}
|
|
182
|
+
"changed_constants" => [] }
|
|
194
183
|
response = receive_event(data)
|
|
195
184
|
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
expect(response[:ok]).to eq(false)
|
|
186
|
+
expect(response[:ignored]).to eq(true)
|
|
198
187
|
end
|
|
199
188
|
|
|
200
189
|
private
|
|
201
190
|
|
|
202
191
|
def assert_slack_receives(color, event_data, expected_body)
|
|
203
|
-
|
|
192
|
+
http_stubs.post "/token" do |env|
|
|
204
193
|
body = JSON.parse(env[:body])
|
|
205
194
|
attachment = body["attachments"].first
|
|
206
195
|
field = attachment["fields"].first
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
[200, {},
|
|
196
|
+
attachment["color"] # may be expect(nil).to eq(color)
|
|
197
|
+
expect(attachment["fallback"]).to eq(expected_body)
|
|
198
|
+
expect(field["value"]).to eq(expected_body)
|
|
199
|
+
[200, {}, "ok"]
|
|
211
200
|
end
|
|
212
201
|
receive_event(event_data)
|
|
213
202
|
end
|
|
214
203
|
|
|
215
204
|
def receive_event(event_data = nil)
|
|
216
|
-
|
|
205
|
+
service_receive(
|
|
217
206
|
CC::Service::Slack,
|
|
218
207
|
{ webhook_url: "http://api.slack.com/token", channel: "#general" },
|
|
219
|
-
event_data || event(:quality, from: "C", to: "D")
|
|
208
|
+
event_data || event(:quality, from: "C", to: "D"),
|
|
220
209
|
)
|
|
221
210
|
end
|
|
222
211
|
end
|