Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Orillio committed Apr 18, 2024
1 parent b81918e commit 530e221
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions steps/discover-repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
raise 'Can only retrieve up to 1000 repos' if opts[:total] > max

size = [opts[:page_size], opts[:total]].min
licenses_to_filter = ['mit', '0bsd', 'apache-2.0']
licenses_to_filter = [
{ key: 'mit', name: 'MIT License' },
{ key: 'apache-2.0', name: 'Apache License 2.0' },
{ key: '0bsd', name: 'BSD Zero Clause License' }
]

github = Octokit::Client.new
unless opts[:token].empty?
Expand All @@ -70,19 +74,34 @@
'NOT',
'android'
].join(' ')
loop do
if page * size > max
puts "Can't go to page ##{page}, since it will be over #{max}"
break

def mock_array(size, licenses_to_filter)
Array.new(size) do
{
full_name: "foo/#{Random.hex(5)}",
created_at: Time.now,
license: licenses_to_filter.sample(1)[0]
}
end
json = if opts[:dry]
{ items: page > 100 ? [] : Array.new(size) { { full_name: "foo/#{Random.hex(5)}", created_at: Time.now } } }
end

def mock_reps(page, size, licenses_to_filter)
{
items: if page > 100 then []
else
mock_array(size, licenses_to_filter)
end
}
end

loop do
break if page * size > max
json = if opts[:dry] then mock_reps(page, size, licenses_to_filter)
else
github.search_repositories(query, per_page: size, page: page)
end
json[:items].each do |i|
license = i[:license]
next if license.nil? || !licenses_to_filter.include?(license[:key])
next if i[:license].nil? || !licenses_to_filter.include?({ key: i[:license][:key], name: i[:license][:name] })
found[i[:full_name]] = {
full_name: i[:full_name],
default_branch: i[:default_branch],
Expand All @@ -95,9 +114,9 @@
topics: i[:topics]
}
puts "Found #{i[:full_name].inspect} GitHub repo ##{found.count} \
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars) with license: #{license[:name]}"
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars) with license: #{i[:license][:name]}"
end
puts "Found #{json[:items].count} repositories in page ##{page}"
puts "Found #{found.count} repositories in page ##{page}"
break if found.count >= opts[:total]
puts "Let's sleep for #{opts[:pause]} seconds to cool off GitHub API \
(already found #{found.count} repos, need #{opts[:total]})..."
Expand Down

0 comments on commit 530e221

Please sign in to comment.