/
change_log.rb
154 lines (127 loc) · 4.32 KB
/
change_log.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require 'github_api'
require 'date'
require 'yaml'
require 'optparse'
require 'optparse/date'
require 'pp'
# Instructions:
# Install github_api gem, `gem install github_api`
# Get a token from github's settings (https://github.com/settings/tokens)
#
# Example:
# ruby change_log.rb -t abcdefghijklmnopqrstuvwxyz -s 2017-09-06
#
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: change_log.rb [options]'
# defaults, go back 90 days
options[:start_date] = Date.today - 90
options[:end_date] = Date.today
opts.on('-s', '--start-date [DATE]', Date, 'Start of data (e.g. 2017-09-06)') do |v|
options[:start_date] = v
end
opts.on('-e', '--end-date [DATE]', Date, 'End of data (e.g. 2017-09-13)') do |v|
options[:end_date] = v
end
opts.on('-t', '--token [String]', String, 'Github API Token') do |v|
options[:token] = v
end
end.parse!
# Convert dates to time objects
options[:start_date] = Time.parse(options[:start_date].to_s)
options[:end_date] = Time.parse(options[:end_date].to_s)
puts options
### Repository options
repo_owner = 'BuildingSync'
repo = 'schema'
github = Github.new
if options[:token]
puts 'Using github token'
token = options[:token]
github = Github.new oauth_token: token
end
total_open_issues = []
total_open_pull_requests = []
new_issues = []
closed_issues = []
accepted_pull_requests = []
def get_num(issue)
issue.html_url.split('/')[-1].to_i
end
def get_issue_num(issue)
"\##{get_num(issue)}"
end
def get_html_url(issue)
issue.html_url
end
def get_title(issue)
issue.title
end
def print_issue(issue)
is_feature = false
issue.labels.each {|label| is_feature = true if label.name == 'Feature Request'}
if is_feature
"- Improved [#{get_issue_num(issue)}]( #{get_html_url(issue)} ), #{get_title(issue)}"
else
"- Merged [#{get_issue_num(issue)}]( #{get_html_url(issue)} ), #{get_title(issue)}"
end
end
# Process Open Issues
results = -1
page = 1
while results != 0
resp = github.issues.list user: repo_owner, repo: repo, sort: 'created', direction: 'asc',
state: 'open', per_page: 100, page: page
results = resp.length
resp.env[:body].each do |issue, _index|
created = Time.parse(issue.created_at)
if !issue.key?(:pull_request)
total_open_issues << issue
if created >= options[:start_date] && created <= options[:end_date]
new_issues << issue
end
else
total_open_pull_requests << issue
end
end
page += 1
end
# Process Closed Issues
results = -1
page = 1
while results != 0
# TODO: this needs to be a pull_request. For now have to manually check if the PR was closed, or merged.
resp = github.issues.list user: repo_owner, repo: repo, sort: 'created', direction: 'asc',
state: 'closed', per_page: 100, page: page
results = resp.length
resp.env[:body].each do |issue, _index|
# check if the issue is to be ignored
next if issue.labels.to_s =~ /ignore/
created = Time.parse(issue.created_at)
closed = Time.parse(issue.closed_at)
if !issue.key?(:pull_request)
if created >= options[:start_date] && created <= options[:end_date]
new_issues << issue
end
if closed >= options[:start_date] && closed <= options[:end_date]
closed_issues << issue
end
elsif closed >= options[:start_date] && closed <= options[:end_date]
accepted_pull_requests << issue
end
end
page += 1
end
closed_issues.sort! {|x, y| get_num(x) <=> get_num(y)}
new_issues.sort! {|x, y| get_num(x) <=> get_num(y)}
accepted_pull_requests.sort! {|x, y| get_num(x) <=> get_num(y)}
total_open_pull_requests.sort! {|x, y| get_num(x) <=> get_num(y)}
puts "Total Open Issues: #{total_open_issues.length}"
puts "Total Open Pull Requests: #{total_open_pull_requests.length}"
puts "\nDate Range: #{options[:start_date].strftime('%m/%d/%y')} - #{options[:end_date].strftime('%m/%d/%y')}:"
puts "\nNew Issues: #{new_issues.length} (" + new_issues.map {|issue| get_issue_num(issue)}.join(', ') + ')'
puts "\nClosed Issues: #{closed_issues.length}"
closed_issues.each {|issue| puts print_issue(issue)}
puts "\nAccepted Pull Requests: #{accepted_pull_requests.length}"
accepted_pull_requests.each {|issue| puts print_issue(issue)}
puts "\nAll Open Issues: #{total_open_issues.length} (" + total_open_issues.map {|issue| get_issue_num(issue)}.join(', ') + ')'