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,72 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_valid_project_parameter
|
|
5
|
-
@stubs.post '/v1/messages/team_inbox/token' do |env|
|
|
1
|
+
describe CC::Service::Flowdock, type: :service do
|
|
2
|
+
it "valid project parameter" do
|
|
3
|
+
http_stubs.post "/v1/messages/team_inbox/token" do |env|
|
|
6
4
|
body = Hash[URI.decode_www_form(env[:body])]
|
|
7
|
-
|
|
8
|
-
[200, {},
|
|
5
|
+
expect(body["project"]).to eq("Exampleorg")
|
|
6
|
+
[200, {}, ""]
|
|
9
7
|
end
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
service_receive(
|
|
12
10
|
CC::Service::Flowdock,
|
|
13
11
|
{ api_token: "token" },
|
|
14
|
-
|
|
12
|
+
name: "test", repo_name: "Example.org",
|
|
15
13
|
)
|
|
16
14
|
end
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
it "test hook" do
|
|
19
17
|
assert_flowdock_receives(
|
|
20
18
|
"Test",
|
|
21
19
|
{ name: "test", repo_name: "Example" },
|
|
22
|
-
"This is a test of the Flowdock service hook"
|
|
20
|
+
"This is a test of the Flowdock service hook",
|
|
23
21
|
)
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
it "coverage improved" do
|
|
27
25
|
e = event(:coverage, to: 90.2, from: 80)
|
|
28
26
|
|
|
29
27
|
assert_flowdock_receives("Coverage", e, [
|
|
30
28
|
"<a href=\"https://codeclimate.com/repos/1/feed\">Test coverage</a>",
|
|
31
29
|
"has improved to 90.2% (+10.2%)",
|
|
32
|
-
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)"
|
|
30
|
+
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)",
|
|
33
31
|
].join(" "))
|
|
34
32
|
end
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
it "coverage declined" do
|
|
37
35
|
e = event(:coverage, to: 88.6, from: 94.6)
|
|
38
36
|
|
|
39
37
|
assert_flowdock_receives("Coverage", e, [
|
|
40
38
|
"<a href=\"https://codeclimate.com/repos/1/feed\">Test coverage</a>",
|
|
41
39
|
"has declined to 88.6% (-6.0%)",
|
|
42
|
-
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)"
|
|
40
|
+
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)",
|
|
43
41
|
].join(" "))
|
|
44
42
|
end
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
it "quality improved" do
|
|
47
45
|
e = event(:quality, to: "A", from: "B")
|
|
48
46
|
|
|
49
47
|
assert_flowdock_receives("Quality", e, [
|
|
50
48
|
"<a href=\"https://codeclimate.com/repos/1/feed\">User</a>",
|
|
51
49
|
"has improved from a B to an A",
|
|
52
|
-
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)"
|
|
50
|
+
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)",
|
|
53
51
|
].join(" "))
|
|
54
52
|
end
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
it "quality declined" do
|
|
57
55
|
e = event(:quality, to: "D", from: "C")
|
|
58
56
|
|
|
59
57
|
assert_flowdock_receives("Quality", e, [
|
|
60
58
|
"<a href=\"https://codeclimate.com/repos/1/feed\">User</a>",
|
|
61
59
|
"has declined from a C to a D",
|
|
62
|
-
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)"
|
|
60
|
+
"(<a href=\"https://codeclimate.com/repos/1/compare\">Compare</a>)",
|
|
63
61
|
].join(" "))
|
|
64
62
|
end
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
it "single vulnerability" do
|
|
67
65
|
e = event(:vulnerability, vulnerabilities: [
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
{ "warning_type" => "critical" },
|
|
67
|
+
])
|
|
70
68
|
|
|
71
69
|
assert_flowdock_receives("Vulnerability", e, [
|
|
72
70
|
"New <a href=\"https://codeclimate.com/repos/1/feed\">critical</a>",
|
|
@@ -74,11 +72,11 @@ class TestFlowdock < CC::Service::TestCase
|
|
|
74
72
|
].join(" "))
|
|
75
73
|
end
|
|
76
74
|
|
|
77
|
-
|
|
75
|
+
it "single vulnerability with location" do
|
|
78
76
|
e = event(:vulnerability, vulnerabilities: [{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
"warning_type" => "critical",
|
|
78
|
+
"location" => "app/user.rb line 120",
|
|
79
|
+
}])
|
|
82
80
|
|
|
83
81
|
assert_flowdock_receives("Vulnerability", e, [
|
|
84
82
|
"New <a href=\"https://codeclimate.com/repos/1/feed\">critical</a>",
|
|
@@ -86,14 +84,14 @@ class TestFlowdock < CC::Service::TestCase
|
|
|
86
84
|
].join(" "))
|
|
87
85
|
end
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
it "multiple vulnerabilities" do
|
|
90
88
|
e = event(:vulnerability, warning_type: "critical", vulnerabilities: [{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
"warning_type" => "unused",
|
|
90
|
+
"location" => "unused",
|
|
91
|
+
}, {
|
|
92
|
+
"warning_type" => "unused",
|
|
93
|
+
"location" => "unused",
|
|
94
|
+
}])
|
|
97
95
|
|
|
98
96
|
assert_flowdock_receives("Vulnerability", e, [
|
|
99
97
|
"2 new <a href=\"https://codeclimate.com/repos/1/feed\">critical</a>",
|
|
@@ -101,14 +99,14 @@ class TestFlowdock < CC::Service::TestCase
|
|
|
101
99
|
].join(" "))
|
|
102
100
|
end
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
[200, {},
|
|
102
|
+
it "receive test" do
|
|
103
|
+
http_stubs.post request_url do |_env|
|
|
104
|
+
[200, {}, ""]
|
|
107
105
|
end
|
|
108
106
|
|
|
109
107
|
response = receive_event(name: "test", repo_name: "foo")
|
|
110
108
|
|
|
111
|
-
|
|
109
|
+
expect(response[:message]).to eq("Test message sent")
|
|
112
110
|
end
|
|
113
111
|
|
|
114
112
|
private
|
|
@@ -126,23 +124,23 @@ class TestFlowdock < CC::Service::TestCase
|
|
|
126
124
|
end
|
|
127
125
|
|
|
128
126
|
def assert_flowdock_receives(subject, event_data, expected_body)
|
|
129
|
-
|
|
127
|
+
http_stubs.post request_url do |env|
|
|
130
128
|
body = Hash[URI.decode_www_form(env[:body])]
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
[200, {},
|
|
129
|
+
expect(body["source"]).to eq("Code Climate")
|
|
130
|
+
expect(body["from_address"]).to eq("hello@codeclimate.com")
|
|
131
|
+
expect(body["from_name"]).to eq("Code Climate")
|
|
132
|
+
expect(body["format"]).to eq("html")
|
|
133
|
+
expect(body["subject"]).to eq(subject)
|
|
134
|
+
expect(body["project"]).to eq("Example")
|
|
135
|
+
expect(body["content"]).to eq(expected_body)
|
|
136
|
+
expect(body["link"]).to eq("https://codeclimate.com")
|
|
137
|
+
[200, {}, ""]
|
|
140
138
|
end
|
|
141
139
|
|
|
142
140
|
receive_event(event_data)
|
|
143
141
|
end
|
|
144
142
|
|
|
145
143
|
def receive_event(event_data = nil)
|
|
146
|
-
|
|
144
|
+
service_receive(CC::Service::Flowdock, { api_token: "token" }, event_data || event(:quality, from: "D", to: "C"))
|
|
147
145
|
end
|
|
148
146
|
end
|
|
@@ -1,82 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class TestGitHubIssues < CC::Service::TestCase
|
|
4
|
-
def test_creation_success
|
|
1
|
+
describe CC::Service::GitHubIssues, type: :service do
|
|
2
|
+
it "creation success" do
|
|
5
3
|
id = 1234
|
|
6
4
|
number = 123
|
|
7
5
|
url = "https://github.com/#{project}/pulls/#{number}"
|
|
8
|
-
stub_http(request_url, [201, {},
|
|
6
|
+
stub_http(request_url, [201, {}, %({"id": #{id}, "number": #{number}, "html_url":"#{url}"})])
|
|
9
7
|
|
|
10
8
|
response = receive_event
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
expect(response[:id]).to eq(id)
|
|
11
|
+
expect(response[:number]).to eq(number)
|
|
12
|
+
expect(response[:url]).to eq(url)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
it "quality" do
|
|
18
16
|
assert_github_receives(
|
|
19
17
|
event(:quality, to: "D", from: "C"),
|
|
20
18
|
"Refactor User from a D on Code Climate",
|
|
21
|
-
"https://codeclimate.com/repos/1/feed"
|
|
19
|
+
"https://codeclimate.com/repos/1/feed",
|
|
22
20
|
)
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
it "quality without rating" do
|
|
26
24
|
assert_github_receives(
|
|
27
25
|
event(:quality, to: nil),
|
|
28
26
|
"Refactor User on Code Climate",
|
|
29
|
-
"https://codeclimate.com/repos/1/feed"
|
|
27
|
+
"https://codeclimate.com/repos/1/feed",
|
|
30
28
|
)
|
|
31
29
|
end
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
it "issue" do
|
|
34
32
|
payload = {
|
|
35
33
|
issue: {
|
|
36
34
|
"check_name" => "Style/LongLine",
|
|
37
|
-
"description" => "Line is too long [1000/80]"
|
|
35
|
+
"description" => "Line is too long [1000/80]",
|
|
38
36
|
},
|
|
39
37
|
constant_name: "foo.rb",
|
|
40
|
-
details_url: "http://example.com/repos/id/foo.rb#issue_123"
|
|
38
|
+
details_url: "http://example.com/repos/id/foo.rb#issue_123",
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
assert_github_receives(
|
|
44
42
|
event(:issue, payload),
|
|
45
43
|
"Fix \"Style/LongLine\" issue in foo.rb",
|
|
46
|
-
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
|
|
44
|
+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
|
|
47
45
|
)
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
|
|
48
|
+
it "vulnerability" do
|
|
51
49
|
assert_github_receives(
|
|
52
50
|
event(:vulnerability, vulnerabilities: [{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
"warning_type" => "critical",
|
|
52
|
+
"location" => "app/user.rb line 120",
|
|
53
|
+
}]),
|
|
56
54
|
"New critical issue found in app/user.rb line 120",
|
|
57
|
-
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
|
|
55
|
+
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
|
|
58
56
|
)
|
|
59
57
|
end
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
it "receive test" do
|
|
60
|
+
http_stubs.post request_url do |_env|
|
|
63
61
|
[200, {}, '{"number": 2, "html_url": "http://foo.bar"}']
|
|
64
62
|
end
|
|
65
63
|
|
|
66
64
|
response = receive_event(name: "test")
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
expect(response[:message]).to eq("Issue <a href='http://foo.bar'>#2</a> created.")
|
|
69
67
|
end
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
it "different base url" do
|
|
70
|
+
http_stubs.post request_url do |env|
|
|
71
|
+
expect(env[:url].to_s).to eq("http://example.com/#{request_url}")
|
|
74
72
|
[200, {}, '{"number": 2, "html_url": "http://foo.bar"}']
|
|
75
73
|
end
|
|
76
74
|
|
|
77
75
|
response = receive_event({ name: "test" }, base_url: "http://example.com")
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
expect(response[:message]).to eq("Issue <a href='http://foo.bar'>#2</a> created.")
|
|
80
78
|
end
|
|
81
79
|
|
|
82
80
|
private
|
|
@@ -94,22 +92,22 @@ class TestGitHubIssues < CC::Service::TestCase
|
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
def assert_github_receives(event_data, title, ticket_body)
|
|
97
|
-
|
|
95
|
+
http_stubs.post request_url do |env|
|
|
98
96
|
body = JSON.parse(env[:body])
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
[200, {},
|
|
97
|
+
expect(env[:request_headers]["Authorization"]).to eq("token #{oauth_token}")
|
|
98
|
+
expect(body["title"]).to eq(title)
|
|
99
|
+
expect(body["body"]).to eq(ticket_body)
|
|
100
|
+
[200, {}, "{}"]
|
|
103
101
|
end
|
|
104
102
|
|
|
105
103
|
receive_event(event_data)
|
|
106
104
|
end
|
|
107
105
|
|
|
108
106
|
def receive_event(event_data = nil, config = {})
|
|
109
|
-
|
|
107
|
+
service_receive(
|
|
110
108
|
CC::Service::GitHubIssues,
|
|
111
109
|
{ oauth_token: "123", project: project }.merge(config),
|
|
112
|
-
event_data || event(:quality, from: "D", to: "C")
|
|
110
|
+
event_data || event(:quality, from: "D", to: "C"),
|
|
113
111
|
)
|
|
114
112
|
end
|
|
115
113
|
end
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
describe CC::Service::GitHubPullRequests, type: :service do
|
|
2
|
+
it "pull request status pending" do
|
|
3
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "pending",
|
|
4
|
+
"description" => /is analyzing/)
|
|
5
|
+
|
|
6
|
+
receive_pull_request({}, github_slug: "pbrisbin/foo",
|
|
7
|
+
commit_sha: "abc123",
|
|
8
|
+
state: "pending")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "pull request status success detailed" do
|
|
12
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
|
|
13
|
+
"description" => "Code Climate found 2 new issues and 1 fixed issue.")
|
|
14
|
+
|
|
15
|
+
receive_pull_request(
|
|
16
|
+
{},
|
|
17
|
+
github_slug: "pbrisbin/foo",
|
|
18
|
+
commit_sha: "abc123",
|
|
19
|
+
state: "success",
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "pull request status failure" do
|
|
24
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "failure",
|
|
25
|
+
"description" => "Code Climate found 2 new issues and 1 fixed issue.")
|
|
26
|
+
|
|
27
|
+
receive_pull_request(
|
|
28
|
+
{},
|
|
29
|
+
github_slug: "pbrisbin/foo",
|
|
30
|
+
commit_sha: "abc123",
|
|
31
|
+
state: "failure",
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "pull request status success generic" do
|
|
36
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
|
|
37
|
+
"description" => /found 2 new issues and 1 fixed issue/)
|
|
38
|
+
|
|
39
|
+
receive_pull_request({}, github_slug: "pbrisbin/foo",
|
|
40
|
+
commit_sha: "abc123",
|
|
41
|
+
state: "success")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "pull request status error" do
|
|
45
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "error",
|
|
46
|
+
"description" => "Code Climate encountered an error attempting to analyze this pull request.")
|
|
47
|
+
|
|
48
|
+
receive_pull_request({}, github_slug: "pbrisbin/foo",
|
|
49
|
+
commit_sha: "abc123",
|
|
50
|
+
state: "error",
|
|
51
|
+
message: nil)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "pull request status error message provided" do
|
|
55
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "error",
|
|
56
|
+
"description" => "descriptive message")
|
|
57
|
+
|
|
58
|
+
receive_pull_request({}, github_slug: "pbrisbin/foo",
|
|
59
|
+
commit_sha: "abc123",
|
|
60
|
+
state: "error",
|
|
61
|
+
message: "descriptive message")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "pull request status skipped" do
|
|
65
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
|
|
66
|
+
"description" => /skipped analysis/)
|
|
67
|
+
|
|
68
|
+
receive_pull_request({}, github_slug: "pbrisbin/foo",
|
|
69
|
+
commit_sha: "abc123",
|
|
70
|
+
state: "skipped")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "pull request coverage status" do
|
|
74
|
+
expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
|
|
75
|
+
"description" => "87% test coverage (+2%)")
|
|
76
|
+
|
|
77
|
+
receive_pull_request_coverage({},
|
|
78
|
+
github_slug: "pbrisbin/foo",
|
|
79
|
+
commit_sha: "abc123",
|
|
80
|
+
state: "success",
|
|
81
|
+
covered_percent: 87,
|
|
82
|
+
covered_percent_delta: 2.0)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "pull request status test success" do
|
|
86
|
+
http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |_env| [422, {}, ""] }
|
|
87
|
+
|
|
88
|
+
expect(receive_test({}, github_slug: "pbrisbin/foo")[:ok]).to eq(true)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "pull request status test doesnt blow up when unused keys present in config" do
|
|
92
|
+
http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |_env| [422, {}, ""] }
|
|
93
|
+
|
|
94
|
+
expect(receive_test({ wild_flamingo: true }, github_slug: "pbrisbin/foo")[:ok]).to eq(true)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "pull request status test failure" do
|
|
98
|
+
http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |_env| [401, {}, ""] }
|
|
99
|
+
|
|
100
|
+
expect { receive_test({}, github_slug: "pbrisbin/foo") }.to raise_error(CC::Service::HTTPError)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "pull request unknown state" do
|
|
104
|
+
response = receive_pull_request({}, state: "unknown")
|
|
105
|
+
|
|
106
|
+
expect({ ok: false, message: "Unknown state" }).to eq(response)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "different base url" do
|
|
110
|
+
http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") do |env|
|
|
111
|
+
expect(env[:url].to_s).to eq("http://example.com/repos/pbrisbin/foo/statuses/#{"0" * 40}")
|
|
112
|
+
[422, { "x-oauth-scopes" => "gist, user, repo" }, ""]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
expect(receive_test({ base_url: "http://example.com" }, github_slug: "pbrisbin/foo")[:ok]).to eq(true)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "default context" do
|
|
119
|
+
expect_status_update("gordondiggs/ellis", "abc123", "context" => "codeclimate",
|
|
120
|
+
"state" => "pending")
|
|
121
|
+
|
|
122
|
+
receive_pull_request({}, github_slug: "gordondiggs/ellis",
|
|
123
|
+
commit_sha: "abc123",
|
|
124
|
+
state: "pending")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "different context" do
|
|
128
|
+
expect_status_update("gordondiggs/ellis", "abc123", "context" => "sup",
|
|
129
|
+
"state" => "pending")
|
|
130
|
+
|
|
131
|
+
receive_pull_request({ context: "sup" }, github_slug: "gordondiggs/ellis",
|
|
132
|
+
commit_sha: "abc123",
|
|
133
|
+
state: "pending")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe "pr status rollout" do
|
|
137
|
+
it "does not send the status if username is not part of rollout" do
|
|
138
|
+
instance = service(
|
|
139
|
+
CC::Service::GitHubPullRequests,
|
|
140
|
+
{ oauth_token: "123", rollout_usernames: "sup" },
|
|
141
|
+
{ name: "pull_request", github_slug: "gordondiggs/ellis", commit_sha: "abc123", state: "pending", github_login: "abbynormal", github_user_id: 1234 },
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
expect(instance).not_to receive(:update_status_pending)
|
|
145
|
+
|
|
146
|
+
instance.receive
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "does not send the status if user not part of percentage" do
|
|
150
|
+
instance = service(
|
|
151
|
+
CC::Service::GitHubPullRequests,
|
|
152
|
+
{ oauth_token: "123", rollout_percentage: 20 },
|
|
153
|
+
{ name: "pull_request", github_slug: "gordondiggs/ellis", commit_sha: "abc123", state: "pending", github_login: "abbynormal", github_user_id: 1234 },
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
expect(instance).not_to receive(:update_status_pending)
|
|
157
|
+
|
|
158
|
+
instance.receive
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "does send the status if username is part of rollout" do
|
|
162
|
+
instance = service(
|
|
163
|
+
CC::Service::GitHubPullRequests,
|
|
164
|
+
{ oauth_token: "123", rollout_usernames: "abbynormal", rollout_percentage: 0 },
|
|
165
|
+
{ name: "pull_request", github_slug: "gordondiggs/ellis", commit_sha: "abc123", state: "pending", github_login: "abbynormal", github_user_id: 1234 },
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
expect_status_update("gordondiggs/ellis", "abc123", "state" => "pending")
|
|
169
|
+
|
|
170
|
+
instance.receive
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "does send the status if user falls under rollout percentage" do
|
|
174
|
+
instance = service(
|
|
175
|
+
CC::Service::GitHubPullRequests,
|
|
176
|
+
{ oauth_token: "123", rollout_usernames: "sup", rollout_percentage: 60 },
|
|
177
|
+
{ name: "pull_request", github_slug: "gordondiggs/ellis", commit_sha: "abc123", state: "pending", github_login: "abbynormal", github_user_id: 1234 },
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
expect_status_update("gordondiggs/ellis", "abc123", "state" => "pending")
|
|
181
|
+
|
|
182
|
+
instance.receive
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
private
|
|
187
|
+
|
|
188
|
+
def expect_status_update(repo, commit_sha, params)
|
|
189
|
+
http_stubs.post "repos/#{repo}/statuses/#{commit_sha}" do |env|
|
|
190
|
+
expect(env[:request_headers]["Authorization"]).to eq("token 123")
|
|
191
|
+
|
|
192
|
+
body = JSON.parse(env[:body])
|
|
193
|
+
|
|
194
|
+
params.each do |k, v|
|
|
195
|
+
expect(v).to match(body[k])
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def receive_pull_request(config, event_data)
|
|
201
|
+
service_receive(
|
|
202
|
+
CC::Service::GitHubPullRequests,
|
|
203
|
+
{ oauth_token: "123" }.merge(config),
|
|
204
|
+
{ name: "pull_request", issue_comparison_counts: { "fixed" => 1, "new" => 2 } }.merge(event_data),
|
|
205
|
+
)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def receive_pull_request_coverage(config, event_data)
|
|
209
|
+
service_receive(
|
|
210
|
+
CC::Service::GitHubPullRequests,
|
|
211
|
+
{ oauth_token: "123" }.merge(config),
|
|
212
|
+
{ name: "pull_request_coverage", issue_comparison_counts: { "fixed" => 1, "new" => 2 } }.merge(event_data),
|
|
213
|
+
)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def receive_test(config, event_data = {})
|
|
217
|
+
service_receive(
|
|
218
|
+
CC::Service::GitHubPullRequests,
|
|
219
|
+
{ oauth_token: "123" }.merge(config),
|
|
220
|
+
{ name: "test", issue_comparison_counts: { "fixed" => 1, "new" => 2 } }.merge(event_data),
|
|
221
|
+
)
|
|
222
|
+
end
|
|
223
|
+
end
|