forked from puppetlabs/community_management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_actions_report.rb
executable file
·89 lines (82 loc) · 2.92 KB
/
github_actions_report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'erb'
require 'json'
require 'rest-client'
require_relative 'octokit_utils'
require_relative 'options'
options = parse_options
parsed = load_url(options)
util = OctokitUtils.new(options[:oauth])
result_hash = []
headers = { Authorization: "token #{options[:oauth]}" }
count = 0
def parse_job(job,module_name)
@general_conclusion = true if job['conclusion'] == 'failure'
matches = job['name'].split(',')
{
"os": matches[0],
"agent": matches[1][1..],
"result": job['conclusion'],
"url": "https://github.com/#{module_name}/runs/#{job['id']}?check_suite_focus=true"
}
end
parsed.each do |_k, v|
util.check_limit_api()
puts "Getting data from Github API for #{v['github']}"
url = "https://api.github.com/repos/#{v['github']}/actions/workflows"
result = RestClient.get(url, headers)
data = JSON.parse(result.body)
runs_array = []
data['workflows'].each do |wf|
url = "https://api.github.com/repos/#{v['github']}/actions/workflows/#{wf['id']}/runs"
next unless wf['name'] == 'nightly'
runs_json = RestClient.get(url, headers)
runs = JSON.parse(runs_json)
runs['workflow_runs'][0..4].each do |run|
@general_conclusion = false
jobs_json = JSON.parse(RestClient.get(run['jobs_url'], headers))
os_agent = jobs_json['jobs'].select { |job| job['name'].include?('puppet') }.map { |job| parse_job(job, v['github']) }
job_failures = os_agent.select { |x| x[:result] == 'failure' }.length
job_successes = os_agent.select { |x| x[:result] == 'success' }.length
util.check_limit_api()
runs_array << {
"run_id": run['id'],
"run_number": run['run_number'],
"html_url": run['html_url'],
"updated_at": run['updated_at'],
"head_branch": run['head_branch'],
"os_agent": os_agent.sort_by { |hash| hash[:agent] },
"general_conclusion": @general_conclusion,
"job_failures": job_failures,
"job_successes": job_successes
}
end
result_hash << {
"url": "https://github.com/#{v['github']}",
"name": v['title'],
"runs": runs_array,
"workflows": data['workflows'],
"total_failures": runs_array.map { |x| x[:job_failures]}.reduce(0) { |sum, num| sum + num },
"total_successes": runs_array.map { |x| x[:job_successes]}.reduce(0) { |sum, num| sum + num }
}
end
rescue StandardError => e
puts "#{v['title']} - Error: #{e}"
result_hash << {
"url": "https://github.com/#{v['github']}",
"name": v['title'],
"workflows": 'Not available',
"runs": 'Not available',
"agent": 'Not available',
"os": 'Not available'
}
end
html = ERB.new(File.read('github_actions_report.html.erb')).result(binding)
File.open('GithubActionsReport.html', 'wb') do |f|
f.puts(html)
end
js = ERB.new(File.read('github_action_report.js.erb')).result(binding)
File.open('github_action_report.js', 'wb') do |f|
f.puts(js)
end