Skip to content

fix: consider other common license files present in projects #275

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

Merged
merged 2 commits into from
Mar 23, 2025

Conversation

brmassa
Copy link
Contributor

@brmassa brmassa commented Mar 21, 2025

/License
/License.md
/License.txt

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}'

@@ -832,7 +832,11 @@ fn find_readme_file(items []File) ?File {
}

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']
Copy link
Member

Choose a reason for hiding this comment

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

this should be a global const to avoid extra allocations on each request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

@@ -418,9 +418,9 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br

license_file := find_license_file(items) or { File{} }
mut license_file_path := ''

println(license_file)
Copy link
Member

Choose a reason for hiding this comment

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

print

@medvednikov medvednikov merged commit ce730d0 into vlang:master Mar 23, 2025
0 of 4 checks passed
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