-
Notifications
You must be signed in to change notification settings - Fork 23
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
fix: fall back to license from package if not present in versioned package #109
Conversation
f69719f
to
5c6f6d5
Compare
I think it would be great if we could document this behaviour, because it is not without risk. There might potentially be the occasional case where we fall back on the wrong license information, if the package data differs from that of a versioned package. Is there a good section in the readme where we could add this? |
0e408c8
to
fa1caed
Compare
bec7d9e
to
284c931
Compare
284c931
to
b88f63d
Compare
Just updated the readme with this info |
2239675
to
9b49285
Compare
9b49285
to
85eb8ad
Compare
lib/ecosystems/enrich_spdx_test.go
Outdated
func parseJson(jsonStr string) map[string]any { | ||
var result map[string]any | ||
|
||
err := json.Unmarshal([]byte(jsonStr), &result) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to parse JSON: %w", err)) | ||
} | ||
|
||
return result | ||
} |
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.
Ideally—as a test helper—this wouldn't panic. Instead it should require the unmarshal to pass:
func parseJson(jsonStr string) map[string]any { | |
var result map[string]any | |
err := json.Unmarshal([]byte(jsonStr), &result) | |
if err != nil { | |
panic(fmt.Errorf("failed to parse JSON: %w", err)) | |
} | |
return result | |
} | |
func parseJson(t *testing.T, jsonStr string) map[string]any { | |
t.Helper() | |
var result map[string]any | |
require.NoError(t, json.Unmarshal([]byte(jsonStr), &result)) | |
return result | |
} |
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.
Makes sense, done!
lib/ecosystems/enrich_spdx_test.go
Outdated
return result | ||
} | ||
|
||
func setupHttpmock(packageVersionsResponse, packageResponse *string) { |
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.
func setupHttpmock(packageVersionsResponse, packageResponse *string) { | |
func setupHttpmock(t *testing.T, packageVersionsResponse, packageResponse *string) { | |
t.Helper() |
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.
Done!
eca7b53
to
a0e16d0
Compare
As discussed here, ecosyste.ms only returns license info from the versioned endpoint if it is available from the package registry, which it often isn't. We want to fall back to using the package data to retrieve the license if it is not available in the versioned data, which this PR implements.