Skip to content
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

Merged
merged 5 commits into from
Apr 21, 2024

Conversation

Orillio
Copy link
Contributor

@Orillio Orillio commented Apr 18, 2024

Implemented filtration for repositories with licenses (MIT, Apache 2.0, BSD) as proposed in #275.

As room for improvement:

  1. Remove hardcoded licenses and let user choose desired licenses to be filtered
  2. Add license field to "found" object and export csv/tex files along with license column

@@ -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 = [
Copy link
Owner

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.

Copy link
Contributor Author

@Orillio Orillio Apr 19, 2024

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.

  1. Remove hardcoded licenses and let user choose desired licenses to be filtered

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.

licenses_to_filter = [
{ key: 'mit', name: 'MIT License' },
{ key: 'apache-2.0', name: 'Apache License 2.0' },
{ key: '0bsd', name: 'BSD Zero Clause License' }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Orillio why do we need their names? I believe, just key will be enough.

Copy link
Contributor Author

@Orillio Orillio Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 In case someone wanted to include license names inside the exported files (csv/tex), they may become handy.
I will remove them, if it causes issues.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Orillio it looks like information duplication at the moment

@yegor256
Copy link
Owner

@Orillio please, read this: https://www.yegor256.com/2024/04/01/ping-me-please.html

@Orillio
Copy link
Contributor Author

Orillio commented Apr 19, 2024

@yegor256 can you please check CI. Something strange is happening there

@@ -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 = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Orillio
Copy link
Contributor Author

Orillio commented Apr 20, 2024

@yegor256 please check new commit

end
puts "Found #{json[:items].count} repositories in page ##{page}"
puts "Found #{found.count} repositories in page ##{page}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Orillio now, we will print:

10 repositories in page #1 
20 repositories in page #2 
30 repositories in page #2 
40 repositories in page #2 
...

which is obviously wrong.

@@ -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]}"
Copy link
Owner

Choose a reason for hiding this comment

The 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 :key and ignore the name

else
github.search_repositories(query, per_page: size, page: page)
end
json[:items].each do |i|
next if i[:license].nil? || !licenses.include?(i[:license][:key])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Orillio I suggest to print a log line, when this happens

Copy link
Contributor Author

@Orillio Orillio Apr 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 I wanted to add this logic, but loop block is reached its maximum line length of 30.

I could have carry out this chunk of code to another function, but it wont allow me, because CI linter allows functions with length no more than 10 lines, which is highly unreasonable in my opinion.

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: i[:topics]
}

At this point, i dont know how to add new lines here without fully refactoring the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 I somehow managed to overcome the issue. Please check the commit.

@yegor256 yegor256 merged commit 4750c3f into yegor256:master Apr 21, 2024
8 of 9 checks passed
@yegor256
Copy link
Owner

@Orillio thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants