circleci-build-report 0.1.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 +7 -0
- data/LICENSE +25 -0
- data/README.md +12 -0
- data/bin/circleci_build_report +7 -0
- data/lib/circleci_build_report.rb +126 -0
- data/lib/version.rb +3 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b42b006e51a99ed37842af86ab86ee41e79a302d
|
4
|
+
data.tar.gz: 7bfdd9a8fb5467de98134bfbe331c6bebbfcbc1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3edc4a21b7cf13aed10202c7759f9bfe3c04e5af911fdb205c4e8ce2886e06279fbb9b2cf4d5a3daeb2e88772e5a4ec3b9aa8d42fd1e46a436a91629a7e4e796
|
7
|
+
data.tar.gz: dbb346e5b979f6c61d7a972b9ccab6ab0c65804fe4045a85e37de806e11ad05398f3f254d045ab6400f60dfe65c9072e3d2e397e450769d50c7ae5b593d54e24
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
License
|
2
|
+
-------
|
3
|
+
|
4
|
+
(The MIT License)
|
5
|
+
|
6
|
+
Copyright (c) 2018 View The Space (viewthespace)
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
a copy of this software and associated documentation files (the
|
10
|
+
'Software'), to deal in the Software without restriction, including
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be
|
17
|
+
included in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
25
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## CircleCI Build Report
|
2
|
+
This gem is CLI tool for exporting build data for a given CircleCI project and branch in a CSV format. The returned CSV contains only three columns: `build_num`, `start_date`, `status`.
|
3
|
+
|
4
|
+
### Install
|
5
|
+
Install from ruby gems
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install circleci_build_report
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
circleci_build_report --org=<ORG_NAME> --project=<PROJECT_NAME> --branch=<BRANCH_NAME> --token=<CIRCLE_CI_TOKEN> --out=<FILE_TO_WRITE_TO>
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'optparse'
|
7
|
+
require 'json'
|
8
|
+
require_relative 'version'
|
9
|
+
|
10
|
+
class CircleCIBuildReport
|
11
|
+
PAGINATION_LIMIT = 100;
|
12
|
+
|
13
|
+
def self.start
|
14
|
+
parse_opts
|
15
|
+
check_opts
|
16
|
+
|
17
|
+
earliest_seen = Date.today
|
18
|
+
since = Date.today - 30
|
19
|
+
offset = 0
|
20
|
+
builds = [['build_num', 'start_date', 'status']]
|
21
|
+
end_of_builds_reached = false
|
22
|
+
|
23
|
+
while((since < earliest_seen) || end_of_builds_reached)
|
24
|
+
request = CircleAPIRequest.new(
|
25
|
+
config[:org],
|
26
|
+
config[:project],
|
27
|
+
config[:branch],
|
28
|
+
config[:token],
|
29
|
+
offset
|
30
|
+
)
|
31
|
+
response = request.perform
|
32
|
+
response_json = JSON.parse(response.body)
|
33
|
+
end_of_builds_reached = true if response_json == []
|
34
|
+
response_json.each do |build_json|
|
35
|
+
available_date = build_json['start_date'] || build_json['author_date'] || build_json['usage_queued_at']
|
36
|
+
build_date = Date.parse(available_date)
|
37
|
+
earliest_seen = build_date if build_date < earliest_seen
|
38
|
+
builds << [build_json['build_num'], available_date, build_json['status']]
|
39
|
+
end
|
40
|
+
offset += PAGINATION_LIMIT
|
41
|
+
end
|
42
|
+
File.open(config[:out], 'w') { |file| file.write(builds.map { |build| build.join(', ') }.join("\n")) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.parse_opts
|
46
|
+
OptionParser.new do |opts|
|
47
|
+
opts.banner = 'Usage: fir [options]'
|
48
|
+
opts.on('-v', '--version', 'Show version') do |v|
|
49
|
+
config[:version] = v
|
50
|
+
end
|
51
|
+
opts.on('-g', '--org ARG', 'The name of the organization on Github/CircleCI') do |org|
|
52
|
+
config[:org] = org
|
53
|
+
end
|
54
|
+
opts.on('-p', '--project ARG', 'The name of the project') do |project|
|
55
|
+
config[:project] = project
|
56
|
+
end
|
57
|
+
opts.on('-b', '--branch ARG', 'The name of the branch. By default runs master') do |branch|
|
58
|
+
config[:branch] = branch
|
59
|
+
end
|
60
|
+
opts.on('-o', '--out ARG', 'The name of the file to save the results to. Default is out.csv') do |out|
|
61
|
+
config[:out] = out
|
62
|
+
end
|
63
|
+
opts.on('-t', '--token ARG', 'The CircleCI token') do |token|
|
64
|
+
config[:token] = token
|
65
|
+
end
|
66
|
+
end.parse!
|
67
|
+
process_immediate_opts(config)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.check_opts
|
71
|
+
if !config[:org]
|
72
|
+
raise ArgumentError.new("Please specify organization name with --org")
|
73
|
+
end
|
74
|
+
if !config[:project]
|
75
|
+
raise ArgumentError.new("Please specify project name with --project")
|
76
|
+
end
|
77
|
+
if !config[:branch]
|
78
|
+
raise ArgumentError.new("Please specify branch name with --branch")
|
79
|
+
end
|
80
|
+
if !config[:token]
|
81
|
+
raise ArgumentError.new("Please specify CircleCI token with --token")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.config
|
86
|
+
@config ||= {
|
87
|
+
branch: 'master',
|
88
|
+
out: 'out.csv'
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.process_immediate_opts(opts)
|
93
|
+
return unless opts[:version]
|
94
|
+
puts(VERSION)
|
95
|
+
exit(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
class CircleAPIRequest
|
99
|
+
attr_reader :org, :project, :branch, :token, :offset
|
100
|
+
|
101
|
+
def initialize(org, project, branch, token, offset)
|
102
|
+
@org = org
|
103
|
+
@project = project
|
104
|
+
@branch = branch
|
105
|
+
@token = token
|
106
|
+
@offset = offset
|
107
|
+
end
|
108
|
+
|
109
|
+
def perform
|
110
|
+
http.use_ssl = true
|
111
|
+
response = http.get(query_params)
|
112
|
+
end
|
113
|
+
|
114
|
+
def query_params
|
115
|
+
"/api/v1.1/project/github/#{org}/#{project}/tree/#{branch}?circle-token=#{token}&limit=100&offset=#{offset}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def uri
|
119
|
+
@uri ||= URI.parse('https://circleci.com')
|
120
|
+
end
|
121
|
+
|
122
|
+
def http
|
123
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: circleci-build-report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nassredean Nasseri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Export build data for a given project and branch on CircleCI in CSV format
|
14
|
+
email: dean@vts.com
|
15
|
+
executables:
|
16
|
+
- circleci_build_report
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- bin/circleci_build_report
|
23
|
+
- lib/circleci_build_report.rb
|
24
|
+
- lib/version.rb
|
25
|
+
homepage: https://github.com/viewthespace/circleci_build_report
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.6.14
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Export build data for a given project and branch on CircleCI in CSV format
|
49
|
+
test_files: []
|