fix: consider other common license files present in projects#275
Merged
medvednikov merged 2 commits intovlang:masterfrom Mar 23, 2025
Merged
fix: consider other common license files present in projects#275medvednikov merged 2 commits intovlang:masterfrom
medvednikov merged 2 commits intovlang:masterfrom
Conversation
medvednikov
reviewed
Mar 22, 2025
| fn find_license_file(items []File) ?File { | ||
| files := items.filter(it.name.to_lower() == 'license') | ||
| // List of common license file names | ||
| license_common_files := ['license', 'license.md', 'license.txt', 'licence', 'licence.md', 'licence.txt'] |
Member
There was a problem hiding this comment.
this should be a global const to avoid extra allocations on each request
Contributor
Author
There was a problem hiding this comment.
Global? For big instances, with loads of users, a main project page is hit every time. But for small instances (which I believe it's the main use case), it does not occur that often.
Since this check is only done in the main project page and the list being short, I would argue that it would not make any perceived impact.
Member
There was a problem hiding this comment.
It would. Because the same code powers gitly.org.
It's also a good practice in general to have such arrays as global consts, since V doesn't optimize such allocations yet.
medvednikov
reviewed
Mar 22, 2025
src/repo_routes.v
Outdated
| license_file := find_license_file(items) or { File{} } | ||
| mut license_file_path := '' | ||
|
|
||
| println(license_file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
are common paths used in projects. Code now considers any of them.
Also, use the file name to build the URL
license_file_path = '/${username}/${repo_name}/blob/${branch_name}/${license_file.name}'