-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
112 lines (93 loc) · 3.62 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
107
108
109
110
111
112
require 'json'
require 'net/http'
require 'yaml'
task :fetch_metadata do
yamls = Dir['_data/projects/*.yml']
urls = yamls.map { |x| YAML.load(File.read(x))['repos'] }.flatten.map { |x| x['url'] }
config = YAML.load(File.read('config/auth.yml'))
data = {}
users = {}
hh = { 'Authorization' => 'Bearer ' + config['github_token'] }
urls.each do |url|
p url
if url =~ %r{^https://github\.com/([\w\-\.]+)/([\w\-\.]+)}
user, repo = $1, $2
response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}"), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)
data[url] = {
'name' => json['name'],
'description' => json['description'],
'user_login' => json['owner']['login'],
'homepage' => json['homepage'],
'stars' => json['stargazers_count'],
'license' => json['license'] && json['license']['spdx_id']
}
if data[url]['license'] == 'NOASSERTION'
data[url]['license'] = nil
end
response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/releases/latest"), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)
data[url]['last_release'] = {
'tag_name' => json['tag_name'],
'name' => json['name'],
'draft' => json['draft'],
'prerelease' => json['prerelease'],
'created_at' => json['created_at'],
'published_at' => json['published_at']
}
elsif response.code.to_i != 404
puts "Invalid response for #{response.uri}: #{response}"
end
response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/tags"), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)[0]
if json
name = json['name']
response = Net::HTTP.get_response(URI(json['commit']['url']), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)
data[url]['last_tag'] = {
'name' => name,
'author_date' => json['commit']['author']['date'],
'committer_date' => json['commit']['committer']['date']
}
else
puts "Invalid response for #{response.uri}: #{response}"
end
end
elsif response.code.to_i != 404
puts "Invalid response for #{response.uri}: #{response}"
end
response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/commits"), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)[0]
if json
data[url]['last_commit'] = {
'author_date' => json['commit']['author']['date'],
'committer_date' => json['commit']['committer']['date']
}
end
else
puts "Invalid response for #{response.uri}: #{response}"
end
if users[user].nil?
response = Net::HTTP.get_response(URI("https://api.github.com/users/#{user}"), hh)
if response.code.to_i == 200
json = JSON.parse(response.body)
users[user] = json
else
puts "Invalid response for #{response.uri}: #{response}"
end
end
data[url]['user_name'] = users[user] && users[user]['name']
else
puts "Invalid response for #{response.uri}: #{response}"
end
else
puts "Skipping #{url}"
end
end
File.write(File.join(__dir__, '_data', 'github_info.yml'), YAML.dump(data))
end