forked from ddnexus/pagy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_top100.rb
More file actions
executable file
Β·32 lines (26 loc) Β· 984 Bytes
/
update_top100.rb
File metadata and controls
executable file
Β·32 lines (26 loc) Β· 984 Bytes
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
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'net/http'
require_relative 'scripty'
USERS_URL_FMT = 'https://api.github.com/repos/ddnexus/pagy/contributors?page=%s'
COMMITS_URL_FMT = 'https://github.com/ddnexus/pagy/commits?author=%s'
IMG_WIDTH = '40'
MAX_COUNT = 100
top100 = +"\n"
count = 0
page = 1
until count >= MAX_COUNT || (users = JSON.parse(Net::HTTP.get(URI(format(USERS_URL_FMT, page))))).empty?
users&.each do |u|
break if count >= MAX_COUNT
next if u['login'] == 'dependabot[bot]'
contribution = u['contributions'] == 1 ? 'contribution' : 'contributions'
top100 << %([<img src="#{u['avatar_url']}" width="#{IMG_WIDTH}" title="@#{
u['login']}: #{u['contributions']} #{contribution}">](#{format(COMMITS_URL_FMT, u['login'])}))
count += 1
end
page += 1
end
top100 << "\n"
Scripty.tagged_file_sub('README.md', 'top100', top100)
puts %("Top 100 Contributors" README section updated! (#{count}/#{MAX_COUNT}))