forked from pbyrne/end-of-year-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
106 lines (88 loc) · 2.87 KB
/
Rakefile
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require "dotenv/tasks"
require "octokit"
namespace :github do
desc "Generate end-of-year statistics. Specify the hear with the YEAR environment variable."
task year: [:dotenv, :setup] do
year = Integer(ENV.fetch("YEAR"))
org = ENV.fetch("ORG")
data = {
prs: 0,
comments: 0,
commits: 0,
issues: 0,
additions: 0,
deletions: 0
}
puts "Generating end-of-year statistics for #{org} in #{year}."
Octokit.org_repos(org).each do |repo|
full_name = "#{org}/#{repo.name}"
start = Date.new(year, 1, 1)
stop = Date.new(year, 12, 31)
puts "Repo: #{full_name}"
prs = Octokit.pull_requests(full_name, state: :closed).select do |pr|
pr.merged_at && pr.merged_at.year == year
end
puts " - PRs: #{prs.size}"
comments = Octokit.issues_comments(full_name, since: Date.new(year, 1, 1)).select do |comment|
comment.created_at.year == year
end
puts " - Comments: #{comments.size}"
issues = Octokit.list_issues(full_name, state: :all).select do |issue|
issue.created_at.year == year
end
puts " - Issues: #{issues.size}"
commits = Octokit.commits_between(full_name, start, stop)
puts " - Commits: #{commits.size}"
additions = 0
deletions = 0
prs.each do |pr|
pull = Octokit.pull_request(full_name, pr.number)
additions += pull.additions
deletions += pull.deletions
end
puts " - Lines Added: #{additions}"
puts " - Lines Deleted: #{deletions}"
data[:prs] += prs.size
data[:comments] += comments.size
data[:commits] += commits.size
data[:issues] += issues.size
data[:additions] += additions
data[:deletions] += deletions
end
puts "TOTAL:"
puts " - PRs: #{data[:prs]}"
puts " - Comments: #{data[:comments]}"
puts " - Commits: #{data[:commits]}"
puts " - Issues: #{data[:issues]}"
puts " - Lines Added: #{data[:additions]}"
puts " - Lines Deleted: #{data[:deletions]}"
end
task year_list: [:dotenv, :setup] do
year = Integer(ENV.fetch("YEAR"))
org = ENV.fetch("ORG")
data = {}
puts "Gathering PRs for #{org} in #{year}."
Octokit.org_repos(org).each do |repo|
full_name = "#{org}/#{repo.name}"
start = Date.new(year, 1, 1)
stop = Date.new(year, 12, 31)
data[full_name] = []
prs = Octokit.pull_requests(full_name, state: :closed).select do |pr|
pr.merged_at && pr.merged_at.year == year
end
prs.each { |pr| data[full_name] << pr.title }
end
data.each do |repo, prs|
puts "List of PRs for #{repo}"
prs.each do |pr|
puts "- #{pr}"
end
end
end
task :setup do
Octokit.configure do |config|
config.access_token = ENV.fetch("GITHUB_TOKEN")
config.auto_paginate = true
end
end
end