class CircleCIBuildReport
Constants
- PAGINATION_LIMIT
- VERSION
Public Class Methods
check_opts()
click to toggle source
# File lib/circleci_build_report.rb, line 70 def self.check_opts if !config[:org] raise ArgumentError.new("Please specify organization name with --org") end if !config[:project] raise ArgumentError.new("Please specify project name with --project") end if !config[:branch] raise ArgumentError.new("Please specify branch name with --branch") end if !config[:token] raise ArgumentError.new("Please specify CircleCI token with --token") end end
config()
click to toggle source
# File lib/circleci_build_report.rb, line 85 def self.config @config ||= { branch: 'master', out: 'out.csv' } end
parse_opts()
click to toggle source
# File lib/circleci_build_report.rb, line 45 def self.parse_opts OptionParser.new do |opts| opts.banner = 'Usage: fir [options]' opts.on('-v', '--version', 'Show version') do |v| config[:version] = v end opts.on('-g', '--org ARG', 'The name of the organization on Github/CircleCI') do |org| config[:org] = org end opts.on('-p', '--project ARG', 'The name of the project') do |project| config[:project] = project end opts.on('-b', '--branch ARG', 'The name of the branch. By default runs master') do |branch| config[:branch] = branch end opts.on('-o', '--out ARG', 'The name of the file to save the results to. Default is out.csv') do |out| config[:out] = out end opts.on('-t', '--token ARG', 'The CircleCI token') do |token| config[:token] = token end end.parse! process_immediate_opts(config) end
process_immediate_opts(opts)
click to toggle source
# File lib/circleci_build_report.rb, line 92 def self.process_immediate_opts(opts) return unless opts[:version] puts(VERSION) exit(0) end
start()
click to toggle source
# File lib/circleci_build_report.rb, line 13 def self.start parse_opts check_opts earliest_seen = Date.today since = Date.today - 30 offset = 0 builds = [['build_num', 'start_date', 'status']] end_of_builds_reached = false while((since < earliest_seen) || end_of_builds_reached) request = CircleAPIRequest.new( config[:org], config[:project], config[:branch], config[:token], offset ) response = request.perform response_json = JSON.parse(response.body) end_of_builds_reached = true if response_json == [] response_json.each do |build_json| available_date = build_json['start_date'] || build_json['author_date'] || build_json['usage_queued_at'] build_date = Date.parse(available_date) earliest_seen = build_date if build_date < earliest_seen builds << [build_json['build_num'], available_date, build_json['status']] end offset += PAGINATION_LIMIT end File.open(config[:out], 'w') { |file| file.write(builds.map { |build| build.join(', ') }.join("\n")) } end