Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Update faraday #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: 2.1

executors:
custom:
docker:
- image: circleci/ruby:2.4
environment:
- CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
- CIRCLE_TEST_REPORTS: /tmp/circleci-test-results

commands:
setup:
steps:
- checkout
- run: bundle install
report_coverage:
steps:
- run:
name: Run coverage reporter
command: |
bundle exec rake rubycritic
bundle exec yard doc -o $CIRCLE_ARTIFACTS/doc
bundle exec rake circleci:report_coverage

jobs:
tests:
executor: custom
steps:
- setup
- run:
name: Run rspec
command: bundle exec rspec --format progress --require rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
- run:
name: Run rubocop
command: bundle exec rubocop
- report_coverage

workflows:
version: 2
tests:
jobs:
- tests
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require:
- rubocop-performance

AllCops:
TargetRubyVersion: 2.4

Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.5
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ source 'https://rubygems.org'
gemspec

group :development, :test do
gem 'ffaker', '~> 2.5'
gem 'ffaker', '~> 2.5.0'
gem 'rake', '~> 11.0'
gem 'rspec', '~> 3.5'
gem 'rspec_junit_formatter', '~> 0.2', require: false
gem 'rubocop', '~> 0.42'
gem 'rubocop-performance'
gem 'rubycritic', '~> 3.1', require: false
gem 'simplecov', '~> 0.13'
gem 'simplecov', '~> 0.13.0'
gem 'yard', '~> 0.9'
end
11 changes: 0 additions & 11 deletions circle.yml

This file was deleted.

6 changes: 2 additions & 4 deletions circleci-coverage_reporter.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'circleci/coverage_reporter/version'

Expand All @@ -20,6 +18,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'faraday', '~> 0.9'
spec.add_dependency 'faraday', '>= 0.9', '< 2.0.0'
spec.add_development_dependency 'bundler', '~> 1.12'
end
1 change: 1 addition & 0 deletions lib/circleci/coverage_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def self.run
configuration.reporters.select!(&:active?)
configuration.dump
raise NoActiveReporter if configuration.reporters.empty?

Runner.new.tap(&:dump).run
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/circleci/coverage_reporter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class Client
# @see https://circleci.com/docs/api/v1-reference/#build
def single_build(build_number)
return unless build_number

resp = get(single_build_url(build_number))
body = JSON.parse(resp.body)
raise RequestError.new(body['message'], resp) unless resp.success?

create_build(body)
end

Expand All @@ -34,6 +36,7 @@ def artifacts(build_number)
resp = get(artifacts_url(build_number))
body = JSON.parse(resp.body)
raise RequestError.new(body['message'], resp) unless resp.success?

body.map(&method(:create_artifact))
end

Expand Down Expand Up @@ -84,6 +87,7 @@ def recent_builds(branch)
resp = get(recent_builds_url(branch), limit: 100)
body = JSON.parse(resp.body)
raise RequestError.new(body['message'], resp) unless resp.success?

body.map(&method(:create_build))
end

Expand Down
8 changes: 4 additions & 4 deletions lib/circleci/coverage_reporter/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Configuration

attr_accessor :circleci_token, :vcs_token
attr_writer :artifacts_dir, :base_revision, :current_build_number, :current_revision, :previous_build_number,
:reporters, :repository_name, :template, :template_safe_mode, :template_safe_mode, :user_name, :vcs_type
:reporters, :repository_name, :template, :template_safe_mode, :user_name, :vcs_type

# @return [String]
def project
Expand Down Expand Up @@ -53,7 +53,7 @@ def current_revision

# @return [Integer, nil]
def previous_build_number
@previous_build_number ||= ENV['CIRCLE_PREVIOUS_BUILD_NUM'] && ENV['CIRCLE_PREVIOUS_BUILD_NUM'].to_i
@previous_build_number ||= ENV['CIRCLE_PREVIOUS_BUILD_NUM']&.to_i
end

# @return [String]
Expand All @@ -68,7 +68,7 @@ def user_name

# @return [void]
def dump # rubocop:disable AbcSize
puts <<~EOF
puts <<~TEXT
Configuration | Value
----------------------|----------------------------------------------------------------------------
artifacts_dir | #{artifacts_dir.inspect}
Expand All @@ -82,7 +82,7 @@ def dump # rubocop:disable AbcSize
user_name | #{user_name.inspect}
vcs_token | #{vcs_token[-4..-1].rjust(40, '*').inspect}
vcs_type | #{vcs_type.inspect}
EOF
TEXT
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/circleci/coverage_reporter/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,28 @@ def branch_progress
# @return [String, nil]
def pretty_base_diff
return unless base_diff

pretty_diff(base_diff.round(2))
end

# @return [String, nil]
def pretty_branch_diff
return unless branch_diff

pretty_diff(branch_diff.round(2))
end

# @return [Float, nil]
def base_diff
return unless base_result

current_result.coverage - base_result.coverage
end

# @return [Float, nil]
def branch_diff
return unless previous_result

current_result.coverage - previous_result.coverage
end

Expand Down
1 change: 1 addition & 0 deletions lib/circleci/coverage_reporter/reporters/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def configuration
# @return [String, nil]
def extract_artifact_url(build)
return unless build

artifact = build.find_artifact(path)
artifact ? artifact.url : nil
end
Expand Down
5 changes: 3 additions & 2 deletions lib/circleci/coverage_reporter/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def run

# @return [void]
def dump
puts <<~EOF
puts <<~TEXT
Runner | Value
------------------|-----------------------------------------------------------------------------------
base_build | #{base_build.inspect}
base_build_number | #{base_build_number.inspect}
previous_build | #{previous_build.inspect}
EOF
TEXT
end

private
Expand Down Expand Up @@ -70,6 +70,7 @@ def reporters
# @return [Integer, nil]
def base_build_number
return if configuration.base_revision == configuration.current_revision

@base_build_number ||= client.build_number_by_revision(base_revision, branch: 'master')
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/support/sandboxing.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'circleci/coverage_reporter/sandbox'
require 'tmpdir'

RSpec.configure do |c|
c.around do |example|
Expand Down