-
Notifications
You must be signed in to change notification settings - Fork 2
/
dependabot_statistics.rb
72 lines (62 loc) · 1.86 KB
/
dependabot_statistics.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
require "octokit"
FROM = /(?<=from )\d+\.\d+\.\d+/
TO = /(?<=to )\d+\.\d+\.\d+/
def client
@client ||=
Octokit::Client.new(
access_token: ENV.fetch("GITHUB_TOKEN"),
auto_paginate: true
)
end
def govuk_repos
@govuk_repos ||=
client
.search_repos("org:alphagov topic:govuk")
.items
.reject!(&:archived)
.map { |repo| repo.full_name }
end
def dependabot_preview_prs
@dependabot_preview_prs ||=
client
.search_issues("is:pr is:closed user:alphagov author:app/dependabot-preview")
.items
end
def dependabot_prs
@dependabot_prs ||=
client
.search_issues("is:pr is:closed user:alphagov author:app/dependabot")
.items
end
def govuk_prs
@govuk_prs ||=
[dependabot_preview_prs, dependabot_prs].flatten.select do |pr|
govuk_repos.any? { |repo| pr.repository_url.include?(repo) }
end
end
def actionable_govuk_prs
@actionable_govuk_prs ||=
govuk_prs.map(&:to_h)
.select { |e| e[:title].match?(FROM) && e[:title].match?(TO) }
# If the title doesn't have the "from x.x.x to x.x.x" format,
# it's not useful for what we need to do, so we reject it.
end
def processed_govuk_prs
@processed_govuk_prs ||=
actionable_govuk_prs.map do |pr|
major_minor_patch = {
major: [pr[:title].match(FROM)[0].split(".")[0], pr[:title].match(TO)[0].split(".")[0]],
minor: [pr[:title].match(FROM)[0].split(".")[1], pr[:title].match(TO)[0].split(".")[1]],
patch: [pr[:title].match(FROM)[0].split(".")[2], pr[:title].match(TO)[0].split(".")[2]],
}
pr[:changed_version] = major_minor_patch.map { |k,v| k if v[0] != v[1] }.compact.sort.first
pr
end
end
def major_minor_patch_count
@major_minor_patch_count ||=
processed_govuk_prs
.group_by{ |e| e[:changed_version] }
.transform_values(&:count)
end
puts major_minor_patch_count