Skip to content

Commit

Permalink
fixed bad refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lueFlake committed Oct 9, 2024
1 parent 78edb9e commit 0c3602e
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions steps/discover-repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,60 +83,56 @@ def mock_reps(page, size, licenses)
end

def process_repo(i, found, licenses, opts)
{
return if found.key?(i[:full_name])
no_license = i[:license].nil? || !licenses.include?(i[:license][:key])
puts "Repo #{i[:full_name]} doesn't contain required license. Skipping" if no_license
return if no_license
found[i[:full_name]] = {
full_name: i[:full_name],
default_branch: i[:default_branch],
stars: i[:stargazers_count],
forks: i[:forks_count],
created_at: i[:created_at].iso8601,
size: i[:size],
open_issues_count: i[:open_issues_count],
description: "\"#{i[:description]}\"",
topics: Array(i[:topics]).join(' ')
}
puts "Found #{i[:full_name].inspect} GitHub repo ##{found.count} \
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars) with license: #{i[:license][:key]}"
return if found.key?(i[:full_name])
no_license = i[:license].nil? || !licenses.include?(i[:license][:key])
puts "Repo #{i[:full_name]} doesn't contain required license. Skipping" if no_license
return if no_license
found[i[:full_name]] = {
full_name: i[:full_name],
default_branch: i[:default_branch],
stars: i[:stargazers_count],
forks: i[:forks_count],
created_at: i[:created_at].iso8601,
size: i[:size],
open_issues_count: i[:open_issues_count],
description: "\"#{i[:description]}\"",
topics: Array(i[:topics]).join(' ')
}
puts "Found #{i[:full_name].inspect} GitHub repo ##{found.count} \
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars) with license: #{i[:license][:key]}"
end

def process_year(year, github, found, opts, size, licenses)
{
page = 0
query = [
"stars:#{opts['min-stars']}..#{opts['max-stars']}",
"size:>=#{opts['min-size']}",
'language:java',
"created:#{year}-01-01..#{year}-12-31",
'is:public',
'mirror:false',
'archived:false',
'template:false',
'NOT',
'android'
].join(' ')
puts "Querying for repositories created in #{year}..."
loop do
break if found.count >= opts[:total]
json = if opts[:dry]
mock_reps(page, size, licenses)
else
github.search_repositories(query, per_page: size, page: page)
end
break if json[:items].empty?

json[:items].each do |i|
process_repo(i, found, licenses, opts)
end
page += 1
cooldown(opts, found)
page = 0
query = [
"stars:#{opts['min-stars']}..#{opts['max-stars']}",
"size:>=#{opts['min-size']}",
'language:java',
"created:#{year}-01-01..#{year}-12-31",
'is:public',
'mirror:false',
'archived:false',
'template:false',
'NOT',
'android'
].join(' ')
puts "Querying for repositories created in #{year}..."
loop do
break if found.count >= opts[:total]
json = if opts[:dry]
mock_reps(page, size, licenses)
else
github.search_repositories(query, per_page: size, page: page)
end
puts "Completed querying for year #{year}. Found #{found.count} repositories so far."
}
break if json[:items].empty?

json[:items].each do |i|
process_repo(i, found, licenses, opts)
end
page += 1
cooldown(opts, found)
end
puts "Completed querying for year #{year}. Found #{found.count} repositories so far."
end

current_year = opts[:start_year]
Expand Down

0 comments on commit 0c3602e

Please sign in to comment.