-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
68 lines (61 loc) · 1.8 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
require 'dotenv'
require 'html-proofer'
require 'json'
require 'octokit'
require 'yaml'
Dotenv.load
@config = YAML.load_file '_config.yml'
@baseurl = ENV['BASEURL'] || @config.dig('baseurl')
task :test do
Rake::Task["reset"].invoke
sh "bundle exec jekyll build -b '#{@baseurl}' -d '_site#{@baseurl}'"
opts = {
disable_external: true,
ignore_urls: [/elasticlunr/]
}
HTMLProofer.check_directory('./_site', opts).run
end
task :reset do
sh "rm -rf _site .jekyll*"
end
task :build do
Rake::Task["octokit"].invoke
sh "bundle exec jekyll build -b '#{@baseurl}'"
end
task :octokit do
@file = './src/_data/contributors.json'
@client = ENV['TOKEN'].nil? ?
Octokit::Client.new :
Octokit::Client.new(access_token: ENV['TOKEN'])
@users = {}
@repos = @client.org_repos('minicomp').map(&:full_name)
@repos.each do |repo|
@client.contribs(repo).each do |user|
next if user.type == 'Bot' or user.login == 'gitter-badger'
if @users.key? user.login
@users[user.login][:contributions] ||= 0
@users[user.login][:contributions] += user.contributions
else
@users[user.login] = {
contributions: user.contributions,
avatar_url: user.avatar_url
}
end
end
issues = @client.list_issues(repo, state: 'all').group_by { |i| i.user.login }
issues.each do |user, user_issues|
next if user.include? '[bot]'
if @users.key? user
@users[user][:issues] ||= 0
@users[user][:issues] += user_issues.length
else
@users[user] = {
issues: user_issues.length,
avatar_url: user_issues.first.user.avatar_url
}
end
end
end
@data = @users.sort_by { |_k, v| -v.fetch(:contributions, 0) }.to_h
File.open(@file, 'w') { |f| f.write JSON.pretty_generate(@data) }
end