codacy-coverage 2.1.0 → 2.1.4

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
- SHA1:
3
- metadata.gz: 2ef11befe972c081e590d67224d6c20f82a76fdd
4
- data.tar.gz: 83f0a81143e64065dfac22a3e3a08e6928b8e436
2
+ SHA256:
3
+ metadata.gz: 1be5b80740480276200a84a0d55133ca61b44082c1e72e076a67587bc06b3cb0
4
+ data.tar.gz: 0ad0414f542367603e0759863ae412da6bb24740583b7739250dea045b2fa607
5
5
  SHA512:
6
- metadata.gz: 4d6fab0296e7bcb72ecbfe68217ea3a359baafc3c6e5d516c9073b3702c77a8c1fedbdf6b62d6430203fa38d949dfd3bb8c3c4f537bd675dea4a3d9f9724e584
7
- data.tar.gz: 58ce4f05aa1344f663167b4c8a2165ffabaa2eac72d1b36d481bb5b5c54872928e38c51507092b5e5590b9c204f7688c85eb1cad3b82586c3b934075190c3cda
6
+ metadata.gz: 34c7dcc7802a3b863a87bfd29e8cd0e432af8463f86c65a8818187d9dd564cc85eccecd379ff82cce93ae3ca48e89d8c4841831ecbfcd2a1d74a2d6e8bcaa9dc
7
+ data.tar.gz: 026cc0ab653ee84eec81c5c4c254ede2a3e15b06c4c3fd818d89e09bd841450259bc44788ffa2b561ad7c0aa17ceadf4e18e937bc3307b73742b1e91cfedf044
@@ -0,0 +1,105 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ codacy: codacy/base@1.0.0
5
+
6
+ jobs:
7
+ build_and_test:
8
+ parameters:
9
+ ruby_version:
10
+ type: string
11
+ persist_to_workspace:
12
+ type: boolean
13
+ default: false
14
+ docker:
15
+ - image: circleci/ruby:<< parameters.ruby_version >>
16
+ working_directory: ~/workdir
17
+ steps:
18
+ - attach_workspace:
19
+ at: ~/
20
+
21
+ - run: gem install bundler
22
+
23
+ - restore_cache:
24
+ keys:
25
+ - ruby-codacy-coverage-{{ checksum "Gemfile.lock" }}
26
+ - ruby-codacy-coverage-
27
+
28
+ - run: bundle install --path vendor/bundle
29
+
30
+ - save_cache:
31
+ key: ruby-codacy-coverage-{{ checksum "Gemfile.lock" }}
32
+ paths:
33
+ - vendor/bundle
34
+
35
+ - run: bundle exec rspec
36
+ - when:
37
+ condition: << parameters.persist_to_workspace >>
38
+ steps:
39
+ - persist_to_workspace:
40
+ root: ~/
41
+ paths:
42
+ - workdir/*
43
+ publish:
44
+ docker:
45
+ - image: circleci/ruby:2
46
+ working_directory: ~/workdir
47
+ steps:
48
+ - attach_workspace:
49
+ at: ~/
50
+ - run:
51
+ name: Setup Rubygems
52
+ command: bash .circleci/setup-rubygems.sh
53
+ - run:
54
+ name: Publish to Rubygems
55
+ command: |
56
+ export PUBLISH_VERSION=$(cat .version)
57
+ gem build codacy-coverage.gemspec
58
+ gem push codacy-coverage-$(cat .version).gem
59
+
60
+ workflows:
61
+ version: 2
62
+ build_and_publish:
63
+ jobs:
64
+ - codacy/checkout_and_version
65
+ - build_and_test:
66
+ name: build_and_test_2
67
+ ruby_version: "2"
68
+ persist_to_workspace: true
69
+ requires:
70
+ - codacy/checkout_and_version
71
+ - build_and_test:
72
+ name: build_and_test_2.3
73
+ ruby_version: "2.3"
74
+ requires:
75
+ - codacy/checkout_and_version
76
+ - build_and_test:
77
+ name: build_and_test_2.4
78
+ ruby_version: "2.4"
79
+ requires:
80
+ - codacy/checkout_and_version
81
+ - build_and_test:
82
+ name: build_and_test_2.5
83
+ ruby_version: "2.5"
84
+ requires:
85
+ - codacy/checkout_and_version
86
+ - build_and_test:
87
+ name: build_and_test_2.6
88
+ ruby_version: "2.6"
89
+ requires:
90
+ - codacy/checkout_and_version
91
+ - publish:
92
+ requires:
93
+ - build_and_test_2
94
+ - build_and_test_2.3
95
+ - build_and_test_2.4
96
+ - build_and_test_2.5
97
+ - build_and_test_2.6
98
+ filters:
99
+ branches:
100
+ only:
101
+ - master
102
+ - codacy/tag_version:
103
+ name: tag_version
104
+ requires:
105
+ - publish
@@ -0,0 +1,3 @@
1
+ mkdir ~/.gem
2
+ echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
3
+ chmod 0600 /home/circleci/.gem/credentials
@@ -0,0 +1,4 @@
1
+ * @lolgab @ljmf00 @andreaTP @rtfpessoa @bmbferreira @DReigada @pedrocodacy
2
+
3
+ *.yml @h314to @paulopontesm
4
+
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codacy-coverage (1.0.dev)
5
+ simplecov
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ docile (1.3.2)
12
+ json (2.2.0)
13
+ rake (13.0.0)
14
+ rspec (3.9.0)
15
+ rspec-core (~> 3.9.0)
16
+ rspec-expectations (~> 3.9.0)
17
+ rspec-mocks (~> 3.9.0)
18
+ rspec-core (3.9.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-expectations (3.9.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-mocks (3.9.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.0)
27
+ simplecov (0.17.1)
28
+ docile (~> 1.1)
29
+ json (>= 1.8, < 3)
30
+ simplecov-html (~> 0.10.0)
31
+ simplecov-html (0.10.2)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler
38
+ codacy-coverage!
39
+ rake
40
+ rspec
41
+
42
+ BUNDLED WITH
43
+ 2.0.2
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'codacy/client'
3
+
4
+ Codacy::ClientAPI.notify_final
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.license = "MIT"
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
13
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.executables = ["codacy_final_reporter"]
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.name = "codacy-coverage"
16
16
  gem.require_paths = ["lib"]
@@ -1,17 +1,16 @@
1
1
  require 'json'
2
- require "uri"
3
- require "net/https"
2
+ require 'uri'
3
+ require 'net/https'
4
+ require 'codacy/git'
4
5
 
5
6
  module Codacy
6
7
  module ClientAPI
7
- def self.post_results(parsed_result)
8
+ def self.post_results(parsed_result, partial: false)
8
9
  logger.info('Preparing payload...')
9
10
  logger.debug(parsed_result)
10
11
 
11
- project_token = ENV['CODACY_PROJECT_TOKEN']
12
- codacy_base_api = ENV['CODACY_BASE_API_URL'] || 'https://api.codacy.com'
13
- commit = Codacy::Git.commit_id
14
- url = create_url(codacy_base_api, commit)
12
+ project_token, codacy_base_api, commit = get_parameters
13
+ url = create_url(codacy_base_api, commit, partial: partial)
15
14
 
16
15
  result = parsed_result.to_json
17
16
 
@@ -33,7 +32,7 @@ module Codacy
33
32
  def self.send_request(url, content, project_token, redirects = 3)
34
33
  uri = URI.parse(url)
35
34
  http = Net::HTTP.new(uri.host, uri.port)
36
- request = Net::HTTP::Post.new(uri.path)
35
+ request = Net::HTTP::Post.new(uri)
37
36
  http.use_ssl = uri.scheme == "https"
38
37
  request["project_token"] = project_token
39
38
  request["Content-Type"] = "application/json"
@@ -52,9 +51,40 @@ module Codacy
52
51
  Codacy::Configuration.logger
53
52
  end
54
53
 
55
- def self.create_url(codacy_base_api, commit)
54
+ def self.create_url(codacy_base_api, commit, final: false, partial: false)
56
55
  commit = commit.gsub(/[^[:alnum:]]/, "")
57
- codacy_base_api + '/2.0/coverage/' + commit + '/ruby'
56
+ if final
57
+ codacy_base_api + '/2.0/commit/' + commit + '/coverageFinal'
58
+ else
59
+ query_params = partial ? '?partial=true' : ''
60
+ codacy_base_api + '/2.0/coverage/' + commit + '/ruby' + query_params
61
+ end
62
+ end
63
+
64
+ def self.notify_final
65
+ project_token, codacy_base_api, commit = get_parameters
66
+ url = create_url(codacy_base_api, commit, final: true)
67
+
68
+ if project_token.to_s == ''
69
+ puts 'Could not find Codacy API token, make sure you have it configured in your environment.'
70
+ false
71
+ elsif commit.to_s == ''
72
+ puts 'Could not find the current commit, make sure that you are running inside a git project.'
73
+ false
74
+ else
75
+ puts 'Posting Coverage Final Notice to ' + url
76
+ response = send_request(url, '{}', project_token)
77
+
78
+ puts response
79
+ response.to_s.include? 'success'
80
+ end
81
+ end
82
+
83
+ def self.get_parameters
84
+ project_token = ENV['CODACY_PROJECT_TOKEN']
85
+ codacy_base_api = ENV['CODACY_BASE_API_URL'] || 'https://api.codacy.com'
86
+ commit = Codacy::Git.commit_id
87
+ return project_token, codacy_base_api, commit
58
88
  end
59
89
  end
60
90
  end
@@ -4,7 +4,7 @@ module Codacy
4
4
  def format(result)
5
5
  if should_run?
6
6
  parse_result = Codacy::Parser.parse_file(result)
7
- Codacy::ClientAPI.post_results(parse_result)
7
+ Codacy::ClientAPI.post_results(parse_result, partial: partial)
8
8
  else
9
9
  logger.info("Running locally, skipping Codacy coverage")
10
10
  end
@@ -15,6 +15,10 @@ module Codacy
15
15
 
16
16
  private
17
17
 
18
+ def partial
19
+ false
20
+ end
21
+
18
22
  def should_run?
19
23
  ENV["CI"] || ENV["JENKINS_URL"] || ENV['TDDIUM'] || ENV["CODACY_RUN_LOCAL"]
20
24
  end
@@ -24,4 +28,10 @@ module Codacy
24
28
  end
25
29
 
26
30
  end
31
+
32
+ class PartialFormatter < Formatter
33
+ def partial
34
+ true
35
+ end
36
+ end
27
37
  end
@@ -2,9 +2,9 @@ require 'simplecov'
2
2
 
3
3
  module Codacy
4
4
  module Reporter
5
- def self.start
6
- SimpleCov.formatter = Codacy::Formatter
7
- SimpleCov.start
5
+ def self.start(profile = nil, partial = true)
6
+ SimpleCov.formatter = partial ? Codacy::Formatter::Partial : Codacy::Formatter
7
+ SimpleCov.start(profile)
8
8
  end
9
9
  end
10
10
  end
@@ -2,16 +2,41 @@ require "spec_helper"
2
2
 
3
3
  describe Codacy::ClientAPI do
4
4
  describe 'create url' do
5
- it 'checks if the url is correct.' do
6
- codacy_base_api = 'https://api.codacy.com'
7
-
8
- expected_commit_uuid = "9a7d25976a11f2a145f8fee7c4e4ad58b621d560"
9
- expected_url = Codacy::ClientAPI.create_url(codacy_base_api, expected_commit_uuid)
10
-
11
- wrong_commit_uuid = "'9a7d25976a11f2a145f8fee7c4e4ad58b621d560'"
12
- fixed_url = Codacy::ClientAPI.create_url(codacy_base_api, wrong_commit_uuid)
13
-
14
- expect(fixed_url).to eq expected_url
5
+ let(:codacy_base_api) {'https://api.codacy.com'}
6
+
7
+ it 'checks if the url is correct.' do
8
+ expected_commit_uuid = "9a7d25976a11f2a145f8fee7c4e4ad58b621d560"
9
+ expected_url = Codacy::ClientAPI.create_url(codacy_base_api, expected_commit_uuid)
10
+
11
+ wrong_commit_uuid = "'9a7d25976a11f2a145f8fee7c4e4ad58b621d560'"
12
+ fixed_url = Codacy::ClientAPI.create_url(codacy_base_api, wrong_commit_uuid)
13
+
14
+ expect(fixed_url).to eq expected_url
15
+ end
16
+
17
+ it 'generates coverage final url' do
18
+ commit_uuid = "9a7d25976a11f2a145f8fee7c4e4ad58b621d560"
19
+
20
+ url = Codacy::ClientAPI.create_url(codacy_base_api, commit_uuid, final: true)
21
+
22
+ expect(url).to include('coverageFinal')
23
+ end
24
+
25
+ it 'generates url with partial query parameter' do
26
+ commit_uuid = "9a7d25976a11f2a145f8fee7c4e4ad58b621d560"
27
+
28
+ url = Codacy::ClientAPI.create_url(codacy_base_api, commit_uuid, partial: true)
29
+
30
+ expect(url).to include('partial=true')
31
+ end
32
+ end
33
+
34
+ describe '.notify_final' do
35
+ context 'missing project token' do
36
+ it 'returns false' do
37
+ ENV['CODACY_PROJECT_TOKEN'] = ''
38
+ expect(Codacy::ClientAPI.notify_final).to be false
39
+ end
15
40
  end
16
41
  end
17
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codacy-coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nuno Teixeira
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-20 00:00:00.000000000 Z
12
+ date: 2019-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov
@@ -71,16 +71,21 @@ description: Post code coverage results to Codacy.
71
71
  email:
72
72
  - nuno@codacy.com
73
73
  - rodrigo@codacy.com
74
- executables: []
74
+ executables:
75
+ - codacy_final_reporter
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
79
+ - ".circleci/config.yml"
80
+ - ".circleci/setup-rubygems.sh"
81
+ - ".github/CODEOWNERS"
78
82
  - ".github/ISSUE_TEMPLATE.md"
79
83
  - ".gitignore"
80
84
  - Gemfile
85
+ - Gemfile.lock
81
86
  - Gemfile.ruby-19
82
87
  - README.md
83
- - circle.yml
88
+ - bin/codacy_final_reporter
84
89
  - codacy-coverage.gemspec
85
90
  - lib/codacy-coverage.rb
86
91
  - lib/codacy/client.rb
@@ -89,7 +94,6 @@ files:
89
94
  - lib/codacy/git.rb
90
95
  - lib/codacy/parser.rb
91
96
  - lib/codacy/reporter.rb
92
- - scripts/ci.sh
93
97
  - spec/codacy/client_spec.rb
94
98
  - spec/codacy/git_spec.rb
95
99
  - spec/spec_helper.rb
@@ -112,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  - !ruby/object:Gem::Version
113
117
  version: '0'
114
118
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.11
119
+ rubygems_version: 3.0.3
117
120
  signing_key:
118
121
  specification_version: 4
119
122
  summary: Post code coverage results to Codacy.
data/circle.yml DELETED
@@ -1,15 +0,0 @@
1
- dependencies:
2
- pre:
3
- - git config --global user.email "ci@codacy.com"
4
- - git config --global user.name "Codacy CI"
5
- override:
6
- - rvm install 2.0.0-p648
7
- - rvm install 2.1.10
8
- - rvm install 2.2.5
9
- - rvm install 2.3.1
10
- cache_directories:
11
- - "~/.rvm"
12
-
13
- test:
14
- override:
15
- - scripts/ci.sh
@@ -1,23 +0,0 @@
1
- #!/bin/bash --login
2
-
3
- set -e
4
-
5
- rvm use 2.0.0-p648
6
- ruby -v
7
- bundle install
8
- bundle exec rspec
9
-
10
- rvm use 2.1.10
11
- ruby -v
12
- bundle install
13
- bundle exec rspec
14
-
15
- rvm use 2.2.5
16
- ruby -v
17
- bundle install
18
- bundle exec rspec
19
-
20
- rvm use 2.3.1
21
- ruby -v
22
- bundle install
23
- bundle exec rspec