-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add license filter to discover-repos.rb #284
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,11 @@ | |
raise 'Can only retrieve up to 1000 repos' if opts[:total] > max | ||
|
||
size = [opts[:page_size], opts[:total]].min | ||
licenses_to_filter = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'mit', | ||
'apache-2.0', | ||
'0bsd' | ||
] | ||
|
||
github = Octokit::Client.new | ||
unless opts[:token].empty? | ||
|
@@ -69,17 +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: { key: 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| | ||
next if i[:license].nil? || !licenses_to_filter.include?(i[:license][:key]) | ||
found[i[:full_name]] = { | ||
full_name: i[:full_name], | ||
default_branch: i[:default_branch], | ||
|
@@ -92,9 +114,9 @@ | |
topics: i[:topics] | ||
} | ||
puts "Found #{i[:full_name].inspect} GitHub repo ##{found.count} \ | ||
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars)" | ||
(#{i[:forks_count]} forks, #{i[:stargazers_count]} stars) with license: #{i[:license][:name]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Orillio why do we need their "names"? I suggest to rely only on the |
||
end | ||
puts "Found #{json[:items].count} repositories in page ##{page}" | ||
puts "Found #{found.count} repositories in page ##{page}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Orillio now, we will print:
which is obviously wrong. |
||
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]})..." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Orillio we should provide this list from the command line. Now they are hardcoded, which makes it impossible to configure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 I wanted to propose this as the issue for other students.
Since there are not many (easily solvable) issues in this repo right now.
As you said, the course isn't about solving tasks, but about open source collaboration/discussions.