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

refactor: imodels PackageInfo refactor to use functions #1482

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

another-rex
Copy link
Collaborator

@another-rex another-rex commented Jan 9, 2025

This PR refactors PackageInfo to be accessed via methods, which will perform necessary transformations on the underlying inventory as needed.

This also adds the ecosystemmock extractor which allows you set the return value of the Ecosystem() function.

TODO: Add tests for imodels. I will add tests in a followup PR once we are confident we are sticking with this approach and it works with the other refactors.

@another-rex another-rex marked this pull request as draft January 9, 2025 02:28
@another-rex another-rex marked this pull request as ready for review January 9, 2025 02:29
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 70.42254% with 42 lines in your changes missing coverage. Please review.

Project coverage is 66.86%. Comparing base (61a3731) to head (20b4ff3).

Files with missing lines Patch % Lines
internal/imodels/imodels.go 69.01% 18 Missing and 4 partials ⚠️
internal/scalibrextract/ecosystemmock/extractor.go 25.00% 9 Missing ⚠️
pkg/osv/osv.go 0.00% 4 Missing ⚠️
pkg/osvscanner/scan.go 0.00% 4 Missing ⚠️
...al/clients/clientimpl/localmatcher/localmatcher.go 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1482      +/-   ##
==========================================
- Coverage   66.91%   66.86%   -0.06%     
==========================================
  Files         197      198       +1     
  Lines       18619    18650      +31     
==========================================
+ Hits        12459    12470      +11     
- Misses       5474     5496      +22     
+ Partials      686      684       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

nice!


AdditionalLocations []string // Contains Inventory.Locations[1..]
if metadata, ok := pkg.Inventory.Metadata.(*dpkg.Metadata); ok {
// Debian uses source name on osv.dev
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to add a TODO for any other distros?

Copy link
Collaborator Author

@another-rex another-rex Jan 9, 2025

Choose a reason for hiding this comment

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

I don't think so, at least not for any of the distros we currently support (redhat, alpine, and derivatives of those), SourceName is not in either of those metadatas.

return pkg.Inventory.Version
}

func (pkg *PackageInfo) SetVersion() string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it's unnecessary? It's not realy setting any values and hte contents are the same as Verison().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah must have been a copy and paste error, removed it now.

@another-rex another-rex merged commit 7acec29 into google:main Jan 9, 2025
13 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.

3 participants