codecov_api 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b48651bc577638f6224494f15789aff728ecd0c
4
+ data.tar.gz: e779ee1c67a6b315e9e2ed5c24367aa440a65b14
5
+ SHA512:
6
+ metadata.gz: 3932913c4d32cbd6e856a96b2e6ad9f251c2f2f6a9067a86ae63d46ef00bb6c8a71c82209350915eed08f265fbfbb9d958c1d22070f9ae948cef530d1f5ca495
7
+ data.tar.gz: 445d173463e3336be2db93a86d8b1d71a06aa9228c0d89e430dbacb3041821481cddb50e2163e51b0b436a84dc3876a7068f6a5606cffba1da53293427f3e05f
data/CHANGELOG.md ADDED
File without changes
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Sebastian Nepote
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # codecov_api
2
+ Unofficial toolset to consume CodeCov's API
3
+
4
+ ## Usage
5
+ ```bash
6
+ export CODECOV_AUTH_TOKEN={CODECOV_AUTH_TOKEN}
7
+ gem install codecov_api
8
+ irb
9
+ ```
10
+ ```Ruby
11
+ 2.2.6 :001 > require 'codecov_api'
12
+ => true
13
+ 2.2.6 :002 > commits = CodecovApi::Api::Commits.new('snepote', 'codecov_api')
14
+ => #<CodecovApi::Api::Commits:0x007fee2043c298 @owner="snepote", @repo="codecov_api">
15
+ 2.2.6 :003 > commits.list
16
+ ```
17
+
18
+ ## CodeCov API
19
+ * [Usage reference](https://docs.codecov.io/reference#usage)
20
+ * See [Authorization](https://docs.codecov.io/reference#authorization) for instructions of how to create a token
21
+
22
+ ## Requirements
23
+ * Ruby version: 2.2.6
@@ -0,0 +1,38 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module CodecovApi
5
+ module Api
6
+ class Base
7
+
8
+ protected
9
+
10
+ def get_request(path)
11
+ get_response(base_url + base_path + path)
12
+ end
13
+
14
+ def base_path
15
+ raise 'base_path method not defined'
16
+ end
17
+
18
+ private
19
+ def auth_token
20
+ raise 'CODECOV_AUTH_TOKEN ENV VAR not defined' if ENV['CODECOV_AUTH_TOKEN'].nil?
21
+ ENV['CODECOV_AUTH_TOKEN']
22
+ end
23
+
24
+ def base_url
25
+ 'https://codecov.io/api/gh'
26
+ end
27
+
28
+ def get_response(url)
29
+ puts "GET #{url}"
30
+ RestClient::Request.new(
31
+ method: :get,
32
+ url: url,
33
+ headers: { :Authorization => 'token ' + auth_token }
34
+ ).execute
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'base.rb'
2
+
3
+ module CodecovApi
4
+ module Api
5
+ class Branches < Base
6
+ def initialize(owner, repo)
7
+ @owner = owner
8
+ @repo = repo
9
+ end
10
+
11
+ def list
12
+ get_request('/branches')
13
+ end
14
+
15
+ def get(branch)
16
+ get_request("/branch/#{branch}")
17
+ end
18
+
19
+ def delete(branch)
20
+ raise 'delete method not implemented'
21
+ end
22
+
23
+ protected
24
+
25
+ def base_path
26
+ "/#{@owner}/#{@repo}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'base.rb'
2
+
3
+ module CodecovApi
4
+ module Api
5
+ class Commits < Base
6
+ def initialize(owner, repo)
7
+ @owner = owner
8
+ @repo = repo
9
+ end
10
+
11
+ def list(from = nil, to = nil)
12
+ # todo: add from and to parameters
13
+ get_request('/commits')
14
+ end
15
+
16
+ def get(sha)
17
+ get_request("/commit/#{sha}")
18
+ end
19
+
20
+ def folder_totals(path, branch = 'master')
21
+ get_request("/tree/#{branch}/#{path}")
22
+ end
23
+
24
+ protected
25
+
26
+ def base_path
27
+ "/#{@owner}/#{@repo}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'base.rb'
2
+
3
+ module CodecovApi
4
+ module Objects
5
+ class Author < Base
6
+ protected
7
+
8
+ def valid_methods
9
+ [:service, :name, :email, :username, :service_id]
10
+ end
11
+
12
+ def root_element
13
+ @data['author']
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ module CodecovApi
4
+ module Objects
5
+ class Base
6
+ def initialize(json)
7
+ @data = JSON.parse(json.to_s)
8
+ end
9
+
10
+ protected
11
+
12
+ def valid_methods
13
+ raise 'valid_methods method not declared'
14
+ end
15
+
16
+ def root_element
17
+ raise 'root_element method not declared'
18
+ end
19
+
20
+ private
21
+
22
+ def method_missing(method, *args, &block)
23
+ super unless valid_methods.include? method
24
+ root_element[method.to_s]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'base.rb'
2
+
3
+ module CodecovApi
4
+ module Objects
5
+ class FolderTotals < Base
6
+ protected
7
+
8
+ def valid_methods
9
+ [:files, :lines, :hits, :misses, :coverage]
10
+ end
11
+
12
+ def root_element
13
+ @data['commit']['folder_totals']
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module CodecovApi
3
+ VERSION = '0.0.0'
4
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'codecov_api/api/commits'
3
+ require_relative 'codecov_api/api/branches'
4
+ require_relative 'codecov_api/objects/author'
5
+ require_relative 'codecov_api/objects/folder_totals'
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codecov_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Nepote
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Unofficial toolset to consume CodeCov's API
14
+ email: snepote@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - LICENSE.md
21
+ - README.md
22
+ - lib/codecov_api.rb
23
+ - lib/codecov_api/api/base.rb
24
+ - lib/codecov_api/api/branches.rb
25
+ - lib/codecov_api/api/commits.rb
26
+ - lib/codecov_api/objects/author.rb
27
+ - lib/codecov_api/objects/base.rb
28
+ - lib/codecov_api/objects/folder_totals.rb
29
+ - lib/codecov_api/version.rb
30
+ homepage: https://github.com/snepote/codecov_api
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.8
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Codecov API
54
+ test_files: []