Class: CircleCiWrapper
- Inherits:
-
Object
- Object
- CircleCiWrapper
- Defined in:
- lib/circle_ci_wrapper.rb,
lib/circle_ci_wrapper/version.rb
Overview
Wrapper around circle ci api
Constant Summary collapse
- CIRCLE_CI_API_URL =
'https://circleci.com/api/v1.1/project/github'- VERSION =
'0.0.4'
Class Method Summary collapse
- .base_url ⇒ Object
- .latest_build(url, build_name) ⇒ Object
- .report_url(url, branch_name = nil) ⇒ Object
- .report_urls_by_branch(branch_name, build_name = 'build') ⇒ Object
Class Method Details
.base_url ⇒ Object
37 38 39 |
# File 'lib/circle_ci_wrapper.rb', line 37 def self.base_url "#{CIRCLE_CI_API_URL}/#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}" end |
.latest_build(url, build_name) ⇒ Object
41 42 43 44 45 |
# File 'lib/circle_ci_wrapper.rb', line 41 def self.latest_build(url, build_name) JSON.parse(URI.parse(url).read).select do |build| build&.[]('build_parameters')&.[]('CIRCLE_JOB') == build_name end&.first&.[]('build_num') end |
.report_url(url, branch_name = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/circle_ci_wrapper.rb', line 25 def self.report_url(url, branch_name = nil) return nil if Net::HTTP.get_response(URI.parse(url)).code != '200' artifacts = JSON.parse(URI.parse(url).read).map { |a| a['url'] } coverage_url = artifacts.find { |artifact| artifact&.end_with?('coverage/coverage.json') } return nil unless coverage_url "#{coverage_url}?circle-token=#{ENV['CIRCLE_TOKEN']}&branch=#{branch_name}" end |
.report_urls_by_branch(branch_name, build_name = 'build') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/circle_ci_wrapper.rb', line 10 def self.report_urls_by_branch(branch_name, build_name = 'build') url = "#{base_url}/tree/#{branch_name}?circle-token=#{ENV['CIRCLE_TOKEN']}&limit=6&filter=completed" return nil if Net::HTTP.get_response(URI.parse(url)).code != '200' latest_build_num = latest_build(url, build_name) return nil unless latest_build_num [ report_url("#{base_url}/#{ENV['CIRCLE_BUILD_NUM']}/artifacts?circle-token=#{ENV['CIRCLE_TOKEN']}"), report_url("#{base_url}/#{latest_build_num}/artifacts?circle-token=#{ENV['CIRCLE_TOKEN']}", branch_name) ] end |