Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/collect-gh.rb
1677 views
1
#!/usr/bin/env ruby
2
require 'json'
3
require 'net/http'
4
require 'uri'
5
require 'yaml'
6
7
# Existing known PRs in our database
8
data = YAML.load_file('metadata/github.yml') || {}
9
10
def gh_cli_pr_list(count: 3)
11
d = JSON.parse(`gh pr list --search 'sort:updated-desc is:merged' --limit #{count} --json number`)
12
d.map { |pr| pr['number'] }
13
end
14
15
def gh_cli_pr_info(num, fields)
16
JSON.parse(`gh pr view #{num} --json #{fields.join(',')}`)
17
end
18
19
# Fetch all PRs in the range in order to backfill anything missing. Shouldn't be needed anymore.
20
# todo = data.keys.min..data.keys.max
21
# todo = todo.reject { |pr| data.key?(pr) }
22
23
# The most recently touched 30 merged PRs
24
todo = gh_cli_pr_list(count: 30)
25
26
todo.each do |pull|
27
puts "Fetching PR #{pull}"
28
# We already have this PR.
29
next if data.key?(pull)
30
31
# Fetch data
32
fields = %w[state title author createdAt updatedAt closedAt mergedAt mergedBy
33
labels headRefName headRepository reactionGroups reviews files url]
34
35
begin
36
pr = gh_cli_pr_info(pull, fields)
37
rescue
38
puts "Failed to fetch PR #{pull}. Is it an issue?"
39
next
40
end
41
42
pr['labels'] = pr['labels'].map { |l| l['name'] }
43
pr['reviews'] = pr['reviews'].map { |r| r.slice('author', 'state', 'submittedAt', 'reactionGroups') }
44
45
data[pull] = pr
46
end
47
File.write('metadata/github.yml', data.to_yaml)
48
49