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
data/pull_request_test.rb
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
# Generate new token
|
|
16
16
|
#
|
|
17
17
|
###
|
|
18
|
-
require
|
|
18
|
+
require "cc/services"
|
|
19
19
|
CC::Service.load_services
|
|
20
20
|
|
|
21
21
|
class WithResponseLogging
|
|
@@ -28,17 +28,18 @@ class WithResponseLogging
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
service = CC::Service::GitHubPullRequests.new(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
service = CC::Service::GitHubPullRequests.new(
|
|
32
|
+
{
|
|
33
|
+
oauth_token: ENV.fetch("OAUTH_TOKEN"),
|
|
34
|
+
},
|
|
35
|
+
name: "pull_request",
|
|
35
36
|
# https://github.com/codeclimate/nillson/pull/33
|
|
36
|
-
state:
|
|
37
|
+
state: "success",
|
|
37
38
|
github_slug: "codeclimate/nillson",
|
|
38
|
-
issue_comparison_counts: {"new" => 0, "fixed" => 0},
|
|
39
|
-
number:
|
|
40
|
-
commit_sha:
|
|
41
|
-
|
|
39
|
+
issue_comparison_counts: { "new" => 0, "fixed" => 0 },
|
|
40
|
+
number: 33,
|
|
41
|
+
commit_sha: "986ec903b8420f4e8c8d696d8950f7bd0667ff0c",
|
|
42
|
+
)
|
|
42
43
|
|
|
43
44
|
CC::Service::Invocation.new(service) do |i|
|
|
44
45
|
i.wrap(WithResponseLogging)
|
data/service_test.rb
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
# REPO_NAME Defaults to "App"
|
|
19
19
|
#
|
|
20
20
|
###
|
|
21
|
-
require
|
|
21
|
+
require "cc/services"
|
|
22
22
|
CC::Service.load_services
|
|
23
23
|
|
|
24
24
|
class WithResponseLogging
|
|
@@ -40,7 +40,7 @@ class ServiceTest
|
|
|
40
40
|
def test(payload = {})
|
|
41
41
|
config = {}
|
|
42
42
|
|
|
43
|
-
puts "-"*80
|
|
43
|
+
puts "-" * 80
|
|
44
44
|
puts @klass
|
|
45
45
|
|
|
46
46
|
@params.each do |param|
|
|
@@ -59,7 +59,7 @@ class ServiceTest
|
|
|
59
59
|
test_service(@klass, config, payload)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
private
|
|
62
|
+
private
|
|
63
63
|
|
|
64
64
|
def to_env_var(param)
|
|
65
65
|
"#{@klass.to_s.split("::").last}_#{param}".upcase
|
|
@@ -70,7 +70,7 @@ private
|
|
|
70
70
|
|
|
71
71
|
service = klass.new(
|
|
72
72
|
config,
|
|
73
|
-
{ name: :test, repo_name: repo_name }.merge(payload)
|
|
73
|
+
{ name: :test, repo_name: repo_name }.merge(payload),
|
|
74
74
|
)
|
|
75
75
|
|
|
76
76
|
CC::Service::Invocation.new(service) do |i|
|
|
@@ -83,4 +83,4 @@ ServiceTest.new(CC::Service::Slack, :webhook_url).test
|
|
|
83
83
|
ServiceTest.new(CC::Service::Flowdock, :api_token).test
|
|
84
84
|
ServiceTest.new(CC::Service::Jira, :username, :password, :domain, :project_id).test
|
|
85
85
|
ServiceTest.new(CC::Service::Asana, :api_key, :workspace_id, :project_id).test
|
|
86
|
-
ServiceTest.new(CC::Service::GitHubPullRequests, :oauth_token).test(
|
|
86
|
+
ServiceTest.new(CC::Service::GitHubPullRequests, :oauth_token).test(github_slug: "codeclimate/codeclimate")
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
describe Axiom::Types::Password do
|
|
2
|
+
class TestConfiguration < CC::Service::Config
|
|
3
|
+
attribute :password_attribute, Password
|
|
4
|
+
attribute :string_attribute, String
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "password type inference" do
|
|
8
|
+
expect(Axiom::Types::Password).to eq(TestConfiguration.attribute_set[:password_attribute].type)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "string type inference" do
|
|
12
|
+
expect(Axiom::Types::String).to eq(TestConfiguration.attribute_set[:string_attribute].type)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
describe CC::Formatters::SnapshotFormatter do
|
|
2
|
+
def described_class
|
|
3
|
+
CC::Formatters::SnapshotFormatter::Base
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "quality alert with new constants" do
|
|
7
|
+
f = described_class.new("new_constants" => [{ "to" => { "rating" => "D" } }], "changed_constants" => [])
|
|
8
|
+
expect(f.alert_constants_payload).not_to be_nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "quality alert with decreased constants" do
|
|
12
|
+
f = described_class.new("new_constants" => [],
|
|
13
|
+
"changed_constants" => [{ "to" => { "rating" => "D" }, "from" => { "rating" => "A" } }])
|
|
14
|
+
expect(f.alert_constants_payload).not_to be_nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "quality improvements with better ratings" do
|
|
18
|
+
f = described_class.new("new_constants" => [],
|
|
19
|
+
"changed_constants" => [{ "to" => { "rating" => "A" }, "from" => { "rating" => "D" } }])
|
|
20
|
+
expect(f.improved_constants_payload).not_to be_nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "nothing set without changes" do
|
|
24
|
+
f = described_class.new("new_constants" => [], "changed_constants" => [])
|
|
25
|
+
expect(f.alert_constants_payload).to be_nil
|
|
26
|
+
expect(f.improved_constants_payload).to be_nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "snapshot formatter test with relaxed constraints" do
|
|
30
|
+
f = CC::Formatters::SnapshotFormatter::Sample.new(
|
|
31
|
+
"new_constants" => [{ "name" => "foo", "to" => { "rating" => "A" } }, { "name" => "bar", "to" => { "rating" => "A" } }],
|
|
32
|
+
"changed_constants" => [
|
|
33
|
+
{ "from" => { "rating" => "B" }, "to" => { "rating" => "C" } },
|
|
34
|
+
{ "from" => { "rating" => "D" }, "to" => { "rating" => "D" } },
|
|
35
|
+
{ "from" => { "rating" => "D" }, "to" => { "rating" => "D" } },
|
|
36
|
+
{ "from" => { "rating" => "A" }, "to" => { "rating" => "B" } },
|
|
37
|
+
{ "from" => { "rating" => "C" }, "to" => { "rating" => "B" } },
|
|
38
|
+
],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
expect(f.alert_constants_payload).not_to be_nil
|
|
42
|
+
expect(f.improved_constants_payload).not_to be_nil
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "cc/presenters/pull_requests_presenter"
|
|
2
|
+
|
|
3
|
+
describe CC::Service::PullRequestsPresenter, type: :service do
|
|
4
|
+
it "message singular" do
|
|
5
|
+
expect("Code Climate found 1 new issue and 1 fixed issue.").to eq(build_presenter("fixed" => 1, "new" => 1).success_message)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "message plural" do
|
|
9
|
+
expect("Code Climate found 2 new issues and 1 fixed issue.").to eq(build_presenter("fixed" => 1, "new" => 2).success_message)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "message only fixed" do
|
|
13
|
+
expect("Code Climate found 1 fixed issue.").to eq(build_presenter("fixed" => 1, "new" => 0).success_message)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "message only new" do
|
|
17
|
+
expect("Code Climate found 3 new issues.").to eq(build_presenter("fixed" => 0, "new" => 3).success_message)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "message no new or fixed" do
|
|
21
|
+
expect("Code Climate didn't find any new or fixed issues.").to eq(build_presenter("fixed" => 0, "new" => 0).success_message)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "message coverage same" do
|
|
25
|
+
expect("85% test coverage").to eq(build_presenter({}, "covered_percent" => 85, "covered_percent_delta" => 0).coverage_message)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "message coverage up" do
|
|
29
|
+
expect("85.5% test coverage (+2.46%)").to eq(build_presenter({}, "covered_percent" => 85.5, "covered_percent_delta" => 2.4567).coverage_message)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "message coverage down" do
|
|
33
|
+
expect("85.35% test coverage (-3%)").to eq( build_presenter({}, "covered_percent" => 85.348, "covered_percent_delta" => -3.0).coverage_message)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def build_payload(issue_counts)
|
|
39
|
+
{ "issue_comparison_counts" => issue_counts }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def build_presenter(issue_counts, payload = {})
|
|
43
|
+
CC::Service::PullRequestsPresenter.new(build_payload(issue_counts).merge(payload))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -1,73 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class TestAsana < CC::Service::TestCase
|
|
4
|
-
def test_quality
|
|
1
|
+
describe CC::Service::Asana, type: :service do
|
|
2
|
+
it "quality" do
|
|
5
3
|
assert_asana_receives(
|
|
6
4
|
event(:quality, to: "D", from: "C"),
|
|
7
|
-
"Refactor User from a D on Code Climate - https://codeclimate.com/repos/1/feed"
|
|
5
|
+
"Refactor User from a D on Code Climate - https://codeclimate.com/repos/1/feed",
|
|
8
6
|
)
|
|
9
7
|
end
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
it "vulnerability" do
|
|
12
10
|
assert_asana_receives(
|
|
13
11
|
event(:vulnerability, vulnerabilities: [{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"New critical issue found in app/user.rb line 120 - https://codeclimate.com/repos/1/feed"
|
|
12
|
+
"warning_type" => "critical",
|
|
13
|
+
"location" => "app/user.rb line 120",
|
|
14
|
+
}]),
|
|
15
|
+
"New critical issue found in app/user.rb line 120 - https://codeclimate.com/repos/1/feed",
|
|
18
16
|
)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
it "issue" do
|
|
22
20
|
payload = {
|
|
23
21
|
issue: {
|
|
24
22
|
"check_name" => "Style/LongLine",
|
|
25
|
-
"description" => "Line is too long [1000/80]"
|
|
23
|
+
"description" => "Line is too long [1000/80]",
|
|
26
24
|
},
|
|
27
25
|
constant_name: "foo.rb",
|
|
28
|
-
details_url: "http://example.com/repos/id/foo.rb#issue_123"
|
|
26
|
+
details_url: "http://example.com/repos/id/foo.rb#issue_123",
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
assert_asana_receives(
|
|
32
30
|
event(:issue, payload),
|
|
33
31
|
"Fix \"Style/LongLine\" issue in foo.rb",
|
|
34
|
-
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
|
|
32
|
+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
|
|
35
33
|
)
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
it "successful post" do
|
|
37
|
+
http_stubs.post "/api/1.0/tasks" do |_env|
|
|
40
38
|
[200, {}, '{"data":{"id":"2"}}']
|
|
41
39
|
end
|
|
42
40
|
|
|
43
41
|
response = receive_event
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
expect(response[:id]).to eq("2")
|
|
44
|
+
expect(response[:url]).to eq("https://app.asana.com/0/1/2")
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
it "receive test" do
|
|
48
|
+
http_stubs.post "/api/1.0/tasks" do |_env|
|
|
51
49
|
[200, {}, '{"data":{"id":"4"}}']
|
|
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://app.asana.com/0/1/4'>4</a> created.")
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
private
|
|
60
58
|
|
|
61
59
|
def assert_asana_receives(event_data, name, notes = "")
|
|
62
|
-
|
|
60
|
+
http_stubs.post "/api/1.0/tasks" do |env|
|
|
63
61
|
body = JSON.parse(env[:body])
|
|
64
62
|
data = body["data"]
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
expect(data["workspace"]).to eq("1")
|
|
65
|
+
expect(data["projects"].first).to eq("2")
|
|
66
|
+
expect(data["assignee"]).to eq("jim@asana.com")
|
|
67
|
+
expect(data["name"]).to eq(name)
|
|
68
|
+
expect(data["notes"]).to eq(notes)
|
|
71
69
|
|
|
72
70
|
[200, {}, '{"data":{"id":4}}']
|
|
73
71
|
end
|
|
@@ -76,10 +74,10 @@ class TestAsana < CC::Service::TestCase
|
|
|
76
74
|
end
|
|
77
75
|
|
|
78
76
|
def receive_event(event_data = nil)
|
|
79
|
-
|
|
77
|
+
service_receive(
|
|
80
78
|
CC::Service::Asana,
|
|
81
79
|
{ api_key: "abc123", workspace_id: "1", project_id: "2", assignee: "jim@asana.com" },
|
|
82
|
-
event_data || event(:quality, to: "D", from: "C")
|
|
80
|
+
event_data || event(:quality, to: "D", from: "C"),
|
|
83
81
|
)
|
|
84
82
|
end
|
|
85
83
|
end
|
|
@@ -1,109 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_config
|
|
5
|
-
assert_raises CC::Service::ConfigurationError do
|
|
6
|
-
service(CC::Service::Campfire, {}, {name: "test"})
|
|
7
|
-
end
|
|
1
|
+
describe CC::Service::Campfire, type: :service do
|
|
2
|
+
it "config" do
|
|
3
|
+
expect { service(CC::Service::Campfire, {}, name: "test") }.to raise_error(CC::Service::ConfigurationError)
|
|
8
4
|
end
|
|
9
5
|
|
|
10
|
-
|
|
6
|
+
it "test hook" do
|
|
11
7
|
assert_campfire_receives(
|
|
12
8
|
{ name: "test", repo_name: "Rails" },
|
|
13
|
-
"[Code Climate][Rails] This is a test of the Campfire service hook"
|
|
9
|
+
"[Code Climate][Rails] This is a test of the Campfire service hook",
|
|
14
10
|
)
|
|
15
11
|
end
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
it "coverage improved" do
|
|
18
14
|
e = event(:coverage, to: 90.2, from: 80)
|
|
19
15
|
|
|
20
16
|
assert_campfire_receives(e, [
|
|
21
17
|
"[Code Climate][Example] :sunny:",
|
|
22
18
|
"Test coverage has improved to 90.2% (+10.2%).",
|
|
23
|
-
"(https://codeclimate.com/repos/1/feed)"
|
|
19
|
+
"(https://codeclimate.com/repos/1/feed)",
|
|
24
20
|
].join(" "))
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
it "coverage declined" do
|
|
28
24
|
e = event(:coverage, to: 88.6, from: 94.6)
|
|
29
25
|
|
|
30
26
|
assert_campfire_receives(e, [
|
|
31
27
|
"[Code Climate][Example] :umbrella:",
|
|
32
28
|
"Test coverage has declined to 88.6% (-6.0%).",
|
|
33
|
-
"(https://codeclimate.com/repos/1/feed)"
|
|
29
|
+
"(https://codeclimate.com/repos/1/feed)",
|
|
34
30
|
].join(" "))
|
|
35
31
|
end
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
it "quality improved" do
|
|
38
34
|
e = event(:quality, to: "A", from: "B")
|
|
39
35
|
|
|
40
36
|
assert_campfire_receives(e, [
|
|
41
37
|
"[Code Climate][Example] :sunny:",
|
|
42
38
|
"User has improved from a B to an A.",
|
|
43
|
-
"(https://codeclimate.com/repos/1/feed)"
|
|
39
|
+
"(https://codeclimate.com/repos/1/feed)",
|
|
44
40
|
].join(" "))
|
|
45
41
|
end
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
it "quality declined" do
|
|
48
44
|
e = event(:quality, to: "D", from: "C")
|
|
49
45
|
|
|
50
46
|
assert_campfire_receives(e, [
|
|
51
47
|
"[Code Climate][Example] :umbrella:",
|
|
52
48
|
"User has declined from a C to a D.",
|
|
53
|
-
"(https://codeclimate.com/repos/1/feed)"
|
|
49
|
+
"(https://codeclimate.com/repos/1/feed)",
|
|
54
50
|
].join(" "))
|
|
55
51
|
end
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
it "single vulnerability" do
|
|
58
54
|
e = event(:vulnerability, vulnerabilities: [
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
{ "warning_type" => "critical" },
|
|
56
|
+
])
|
|
61
57
|
|
|
62
58
|
assert_campfire_receives(e, [
|
|
63
59
|
"[Code Climate][Example]",
|
|
64
60
|
"New critical issue found.",
|
|
65
|
-
"Details: https://codeclimate.com/repos/1/feed"
|
|
61
|
+
"Details: https://codeclimate.com/repos/1/feed",
|
|
66
62
|
].join(" "))
|
|
67
63
|
end
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
it "single vulnerability with location" do
|
|
70
66
|
e = event(:vulnerability, vulnerabilities: [{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
"warning_type" => "critical",
|
|
68
|
+
"location" => "app/user.rb line 120",
|
|
69
|
+
}])
|
|
74
70
|
|
|
75
71
|
assert_campfire_receives(e, [
|
|
76
72
|
"[Code Climate][Example]",
|
|
77
73
|
"New critical issue found",
|
|
78
74
|
"in app/user.rb line 120.",
|
|
79
|
-
"Details: https://codeclimate.com/repos/1/feed"
|
|
75
|
+
"Details: https://codeclimate.com/repos/1/feed",
|
|
80
76
|
].join(" "))
|
|
81
77
|
end
|
|
82
78
|
|
|
83
|
-
|
|
79
|
+
it "multiple vulnerabilities" do
|
|
84
80
|
e = event(:vulnerability, warning_type: "critical", vulnerabilities: [{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
"warning_type" => "unused",
|
|
82
|
+
"location" => "unused",
|
|
83
|
+
}, {
|
|
84
|
+
"warning_type" => "unused",
|
|
85
|
+
"location" => "unused",
|
|
86
|
+
}])
|
|
91
87
|
|
|
92
88
|
assert_campfire_receives(e, [
|
|
93
89
|
"[Code Climate][Example]",
|
|
94
90
|
"2 new critical issues found.",
|
|
95
|
-
"Details: https://codeclimate.com/repos/1/feed"
|
|
91
|
+
"Details: https://codeclimate.com/repos/1/feed",
|
|
96
92
|
].join(" "))
|
|
97
93
|
end
|
|
98
94
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
[200, {},
|
|
95
|
+
it "receive test" do
|
|
96
|
+
http_stubs.post request_url do |_env|
|
|
97
|
+
[200, {}, ""]
|
|
102
98
|
end
|
|
103
99
|
|
|
104
100
|
response = receive_event(name: "test")
|
|
105
101
|
|
|
106
|
-
|
|
102
|
+
expect(response[:message]).to eq("Test message sent")
|
|
107
103
|
end
|
|
108
104
|
|
|
109
105
|
private
|
|
@@ -125,20 +121,20 @@ class TestCampfire < CC::Service::TestCase
|
|
|
125
121
|
end
|
|
126
122
|
|
|
127
123
|
def assert_campfire_receives(event_data, expected_body)
|
|
128
|
-
|
|
124
|
+
http_stubs.post request_url do |env|
|
|
129
125
|
body = JSON.parse(env[:body])
|
|
130
|
-
|
|
131
|
-
[200, {},
|
|
126
|
+
expect(body["message"]["body"]).to eq(expected_body)
|
|
127
|
+
[200, {}, ""]
|
|
132
128
|
end
|
|
133
129
|
|
|
134
130
|
receive_event(event_data)
|
|
135
131
|
end
|
|
136
132
|
|
|
137
133
|
def receive_event(event_data = nil)
|
|
138
|
-
|
|
134
|
+
service_receive(
|
|
139
135
|
CC::Service::Campfire,
|
|
140
|
-
{ token: "token", subdomain: subdomain, room_id: room},
|
|
141
|
-
event_data || event(:quality, to: "D", from: "C")
|
|
136
|
+
{ token: "token", subdomain: subdomain, room_id: room },
|
|
137
|
+
event_data || event(:quality, to: "D", from: "C"),
|
|
142
138
|
)
|
|
143
139
|
end
|
|
144
140
|
end
|