-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependabot_report.rb
84 lines (65 loc) · 2.2 KB
/
dependabot_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
require 'json'
require 'date'
require 'active_support'
require 'active_support/core_ext/numeric/time'
class DependabotReport
STANDARD_LABELS = [
"dependencies",
"javascript",
"Production Dependency",
"Test Dependency",
"Build dependency",
]
def initialize(start_date, end_date)
@start_date = start_date
@end_date = end_date
@open = extract_prs("is:open")
@unmerged = extract_prs("is:closed is:unmerged")
@merged = extract_prs("is:closed is:merged")
@labels = (open + unmerged + merged)
.flat_map { |pr| pr["labels"] }.uniq
.map { |label| label["name"] } - STANDARD_LABELS
end
def generate_report
labels.each do |label|
puts "PRs for #{label}:"
print_report(
filter_prs_by_label(merged, label),
filter_prs_by_label(unmerged, label),
filter_prs_by_label(open, label),
)
puts "\n\n"
end
puts "TOTALS:"
print_report(merged, unmerged, open)
end
private
attr_reader :start_date, :end_date, :merged, :open, :unmerged, :labels
def print_report(merged, unmerged, open)
merged_in_time = merged.select do |pr|
DateTime.parse(pr["closedAt"]) - DateTime.parse(pr["createdAt"]) <= 7.days
end
total_prs = open.count + merged.count
puts "Total PRS: #{total_prs}"
puts "Merged within 7 days: #{merged_in_time.count}"
puts "Closed and not merged: #{unmerged.count}"
puts "Still Open: #{open.count}"
puts "\n"
puts "Percent merged within 7 days: %#{100.0 * merged_in_time.count.to_f / total_prs}"
end
def filter_prs_by_label(prs, label)
prs.select { |pr| pr["labels"].map { |l| l["name"] }.include?(label) }
end
def extract_prs(filter)
JSON.parse(`./dependabot_report "#{query(filter)}"`)
end
def query(filter)
labels = "label:javascript label:dependencies"
"is:pr #{filter} #{labels} created:#{start_date}..#{end_date}"
end
end
start_date = ARGV[0] || (Date.yesterday.beginning_of_month - 7.days).strftime("%Y-%m-%d")
end_date = ARGV[1] || (Date.yesterday.end_of_month - 8.days).strftime("%Y-%m-%d")
puts "Dependabot Report for #{start_date} to #{end_date}"
puts
DependabotReport.new(start_date, end_date).generate_report