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

Improved fetching license information for npm packages #672

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tmp/

# Logs
logs
*.log
Expand Down
11 changes: 9 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ export const getNpmMetadata = async function (pkgList) {
body = res.body;
metadata_cache[key] = body;
}
p.description = body.description;
p.license = body.license;
p.description =
body.versions?.[p.version]?.description || body.description;
p.license =
body.versions?.[p.version]?.license ||
body.license ||
(await getRepoLicense(body.repository?.url, undefined));
if (body.repository && body.repository.url) {
p.repository = { url: body.repository.url };
}
Expand Down Expand Up @@ -3095,6 +3099,9 @@ export const getRepoLicense = async function (repoUrl, repoMetadata) {
if (!repoUrl) {
repoUrl = toGitHubUrl(repoMetadata);
}
if (repoUrl.startsWith("git://") && repoUrl.endsWith(".git")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this logic is true only for a handful of providers such as github. There might be other places that do this, so fine for now.
Could we split this into two conditions so that we also handle the case where the URL starts with git+https and doesn't end with .git?

Eg: git+https
https://github.com/CycloneDX/cdxgen/blob/master/package.json#L52

Below is also valid since don't think npm performs any validation.

git+https://github.com/CycloneDX/cdxgen

repoUrl = repoUrl.replace("git://", "https://").slice(0, -4);
}
// Perform github lookups
if (repoUrl.indexOf("github.com") > -1) {
let apiUrl = repoUrl.replace(
Expand Down
Loading