-
Notifications
You must be signed in to change notification settings - Fork 433
/
issues.rake
74 lines (56 loc) · 2.14 KB
/
issues.rake
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
require 'net/http'
namespace :statistics do
namespace :github do
desc 'Export the number of issues merged per week to a file'
task issues: :environment do
# GITHUB login required in order to avoid rate limiting on http requests
GITHUB_USERNAME = ''
GITHUB_PASSWORD = ''
if GITHUB_USERNAME.empty? || GITHUB_PASSWORD.empty?
raise StandardError, "Please set your github username/password in lines 8&9 of this file:\nlib/tasks/statistics/github/issues.rake"
end
issues = []
on_last_page = false
page = 1
while on_last_page == false
issues_current, links_current = get_merged_issues(page)
issues += issues_current
on_last_page = on_last_page?(links_current)
page += 1
end
issues_grouped_by_week =
issues
.map { |issue| Date.parse(issue['created_at']) }
.group_by { |date| (date - date.wday).strftime('%Y-%m-%d') }
output = {}
issues_grouped_by_week.each do |week, issues_in_week|
output[week] = issues_in_week.count
end
write_issues_to_file(output)
end
def get_merged_issues(page)
puts "Requesting issues page #{page}..."
uri = URI("https://api.github.com/repos/openSUSE/open-build-service/issues?filter=all&state=all&page=#{page}")
response =
Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new uri.request_uri
request.basic_auth GITHUB_USERNAME, GITHUB_PASSWORD
http.request(request)
end
raise StandardError, response.body if response.code != '200'
issues = JSON.parse(response.body)
link_header = response.get_fields('Link').first
links = link_header.split(', ')
[issues, links]
end
def write_issues_to_file(dates_and_issues)
File.open('issues.csv', 'w') do |file|
file.write("week, number_issues_created\n")
dates_and_issues.each do |week, number_issues|
file.write("#{week}, #{number_issues}\n")
end
puts 'Statistics written to issues.csv'
end
end
end
end