codeclimate-services 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62974a5f010b848b43edd501e04b3fd7e7efcc81
4
- data.tar.gz: 6bf203a29ac168df6c9e420c47b180b9bca13660
3
+ metadata.gz: 3a4f61a5b3f784878457cd8e81bfe7982eae48d4
4
+ data.tar.gz: 5af929445d6091a1c6694eecd0a5f2d4985c8382
5
5
  SHA512:
6
- metadata.gz: 2a0eb59655aff194805a6ec28ffb5275d2f038585cdbb0df9cd3e927808e6ea67fa61603fcbd46bdd66aa7e1617e3cf8d6a18f6ecd532465a06a1dc824fcd21c
7
- data.tar.gz: cfb76a9402d0ee2edb54378b2a4735b8f01586b37739281cd507b9e6844289ecb19a6fe378bae4241553f2f4f1de42b7b2b0dd218d9a42b79adc136ac6536d6b
6
+ metadata.gz: 3cf81df8fcfe3d364fc4024e2b89529177c5d5e6206b74ce8545168c78c6f3d7424ddeb56d7785f682790f6912a3fe8093764b54fa66f021bd1ed76b8363713b
7
+ data.tar.gz: efd09827e835d99ed4210525bba7bc764441925670477c7726002e9b02e8d45cbae2f9a9d1aa50589bdfd9e156aed314d97600e5f29699846a4b28d5ed740be6
data/README.md CHANGED
@@ -95,6 +95,22 @@ Event-specific attributes:
95
95
  }
96
96
  ```
97
97
 
98
+ ### Pull Request Coverage
99
+
100
+ Event name: `pull_request_coverage`
101
+
102
+ Event-specific attributes:
103
+
104
+ ```javascript
105
+ {
106
+ "state": String, // "pending", "success", or "failure"
107
+ "github_slug": String, // user/repo
108
+ "number": String,
109
+ "commit_sha": String,
110
+ "covered_percent_delta": Float,
111
+ }
112
+ ```
113
+
98
114
  ## Other Events
99
115
 
100
116
  The following are not fully implemented yet.
@@ -10,6 +10,8 @@ module CC
10
10
  @fixed_count = issue_comparison_counts["fixed"]
11
11
  @new_count = issue_comparison_counts["new"]
12
12
  end
13
+
14
+ @covered_percent = payload["covered_percent"]
13
15
  end
14
16
 
15
17
  def error_message
@@ -24,6 +26,10 @@ module CC
24
26
  "Code Climate has skipped analysis of this commit."
25
27
  end
26
28
 
29
+ def coverage_success_message
30
+ "Test coverage for this commit: #{@covered_percent}%"
31
+ end
32
+
27
33
  def success_message
28
34
  if both_issue_counts_zero?
29
35
  "Code Climate didn't find any new or fixed issues."
@@ -30,7 +30,17 @@ module CC
30
30
 
31
31
  attr_reader :event, :config, :payload
32
32
 
33
- ALL_EVENTS = %w[test unit coverage quality vulnerability snapshot pull_request issue]
33
+ ALL_EVENTS = %w[
34
+ coverage
35
+ issue
36
+ pull_request
37
+ pull_request_coverage
38
+ quality
39
+ snapshot
40
+ test
41
+ unit
42
+ vulnerability
43
+ ].freeze
34
44
 
35
45
  # Tracks the defined services.
36
46
  def self.services
@@ -6,9 +6,13 @@ class CC::Service::GitHubPullRequests < CC::Service
6
6
  label: "OAuth Token",
7
7
  description: "A personal OAuth token with permissions for the repo."
8
8
  attribute :update_status, Axiom::Types::Boolean,
9
- label: "Update status?",
9
+ label: "Update analysis status?",
10
10
  description: "Update the pull request status after analyzing?",
11
11
  default: true
12
+ attribute :update_coverage_status, Axiom::Types::Boolean,
13
+ label: "Update coverage status?",
14
+ description: "Update the pull request status with test coverage reports?",
15
+ default: false
12
16
  attribute :base_url, Axiom::Types::String,
13
17
  label: "Github API Base URL",
14
18
  description: "Base URL for the Github API",
@@ -38,13 +42,30 @@ class CC::Service::GitHubPullRequests < CC::Service
38
42
  end
39
43
 
40
44
  def receive_pull_request
41
- setup_http
42
- state = @payload["state"]
45
+ if update_status?
46
+ setup_http
47
+ state = @payload["state"]
48
+
49
+ if %w[pending success failure skipped error].include?(state)
50
+ send("update_status_#{state}")
51
+ else
52
+ @response = simple_failure("Unknown state")
53
+ end
54
+ end
43
55
 
44
- if %w[pending success failure skipped error].include?(state)
45
- send("update_status_#{state}")
46
- else
47
- @response = simple_failure("Unknown state")
56
+ response
57
+ end
58
+
59
+ def receive_pull_request_coverage
60
+ if update_coverage_status?
61
+ setup_http
62
+ state = @payload["state"]
63
+
64
+ if state == "success"
65
+ update_coverage_status_success
66
+ else
67
+ @response = simple_failure("Unknown state")
68
+ end
48
69
  end
49
70
 
50
71
  response
@@ -53,7 +74,15 @@ class CC::Service::GitHubPullRequests < CC::Service
53
74
  private
54
75
 
55
76
  def update_status?
56
- [true, "1"].include?(config.update_status)
77
+ effective_boolean?(config.update_status)
78
+ end
79
+
80
+ def update_coverage_status?
81
+ effective_boolean?(config.update_coverage_status)
82
+ end
83
+
84
+ def effective_boolean?(value)
85
+ [true, "1"].include?(value)
57
86
  end
58
87
 
59
88
  def simple_failure(message)
@@ -72,6 +101,10 @@ private
72
101
  update_status("success", presenter.success_message)
73
102
  end
74
103
 
104
+ def update_coverage_status_success
105
+ update_status("success", presenter.coverage_success_message, "#{config.context}/coverage")
106
+ end
107
+
75
108
  def update_status_failure
76
109
  update_status("failure", presenter.success_message)
77
110
  end
@@ -94,16 +127,14 @@ private
94
127
  )
95
128
  end
96
129
 
97
- def update_status(state, description)
98
- if update_status?
99
- params = {
100
- state: state,
101
- description: description,
102
- target_url: @payload["details_url"],
103
- context: config.context,
104
- }
105
- @response = service_post(status_url, params.to_json)
106
- end
130
+ def update_status(state, description, context = config.context)
131
+ params = {
132
+ state: state,
133
+ description: description,
134
+ target_url: @payload["details_url"],
135
+ context: context,
136
+ }
137
+ @response = service_post(status_url, params.to_json)
107
138
  end
108
139
 
109
140
  def receive_test_status
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Services
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -100,6 +100,20 @@ class TestGitHubPullRequests < CC::Service::TestCase
100
100
  })
101
101
  end
102
102
 
103
+ def test_pull_request_coverage_status_success
104
+ expect_status_update("pbrisbin/foo", "abc123", {
105
+ "state" => "success",
106
+ "description" => "Test coverage for this commit: 87%",
107
+ })
108
+
109
+ receive_pull_request_coverage({ update_coverage_status: true }, {
110
+ github_slug: "pbrisbin/foo",
111
+ commit_sha: "abc123",
112
+ state: "success",
113
+ covered_percent: 87
114
+ })
115
+ end
116
+
103
117
  def test_no_status_update_for_skips_when_update_status_config_is_falsey
104
118
  # With no POST expectation, test will fail if request is made.
105
119
 
@@ -233,6 +247,14 @@ private
233
247
  )
234
248
  end
235
249
 
250
+ def receive_pull_request_coverage(config, event_data)
251
+ receive(
252
+ CC::Service::GitHubPullRequests,
253
+ { oauth_token: "123" }.merge(config),
254
+ { name: "pull_request_coverage", issue_comparison_counts: {'fixed' => 1, 'new' => 2} }.merge(event_data)
255
+ )
256
+ end
257
+
236
258
  def receive_test(config, event_data = {})
237
259
  receive(
238
260
  CC::Service::GitHubPullRequests,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.4.5
240
+ rubygems_version: 2.5.1
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Service classes for Code Climate