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

Fix MetadataType in artifacts #108

Merged
merged 1 commit into from
Apr 10, 2024
Merged

Fix MetadataType in artifacts #108

merged 1 commit into from
Apr 10, 2024

Conversation

dwertent
Copy link

@dwertent dwertent commented Apr 10, 2024

User description

Sorry, we do not accept changes directly against this repository. Please see
CONTRIBUTING.md for information on where and how to contribute instead.


Type

bug_fix, tests


Description

  • Fixed an issue where MetadataType was not being set during the unpacking of SyftPackage.
  • Added tests to ensure SyftPackage unmarshalling correctly sets ID and MetadataType.

Changes walkthrough

Relevant files
Bug fix
syfttypes.go
Set MetadataType in SyftPackage Unpacking                               

pkg/apis/softwarecomposition/syfttypes.go

  • Explicitly set MetadataType based on the determined type.
+1/-0     
syfttypes.go
Set MetadataType in SyftPackage Unpacking for v1beta1       

pkg/apis/softwarecomposition/v1beta1/syfttypes.go

  • Explicitly set MetadataType based on the determined type.
+1/-0     
Tests
syfttypes_test.go
Add Tests for SyftPackage JSON Unmarshalling                         

pkg/apis/softwarecomposition/syfttypes_test.go

  • Added new tests for SyftPackage JSON unmarshalling.
  • Validates MetadataType and ID fields after unmarshalling.
  • +41/-0   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Signed-off-by: David Wertenteil <[email protected]>
    Copy link

    PR Description updated to latest commit (1a921cf)

    Copy link

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific functions, but require understanding of the existing data structures and their usage in the system. The addition of tests helps in validating the changes made.

    🧪 Relevant tests

    Yes

    🔍 Possible issues

    Possible Bug: Ensure that the MetadataType assignment does not override any existing data unintentionally. It seems like MetadataType is now being explicitly set, which is good, but there should be checks to ensure this does not lead to data integrity issues if MetadataType was already set by some other means.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Ensure p.MetadataType is not set to an empty string.

    Consider checking if ty is not an empty string before assigning it to p.MetadataType. This
    ensures that p.MetadataType is not unintentionally set to an empty value, which could lead
    to unexpected behavior or errors in downstream processing.

    pkg/apis/softwarecomposition/syfttypes.go [326]

    -p.MetadataType = ty
    +if ty != "" {
    +    p.MetadataType = ty
    +}
     
    Ensure p.MetadataType is not set to an empty string in v1beta1.

    Similar to the suggestion made for syfttypes.go, consider checking if ty is not an empty
    string before assigning it to p.MetadataType in v1beta1/syfttypes.go. This consistency
    across versions helps in maintaining the integrity of the metadata type assignment.

    pkg/apis/softwarecomposition/v1beta1/syfttypes.go [326]

    -p.MetadataType = ty
    +if ty != "" {
    +    p.MetadataType = ty
    +}
     
    Enhancement
    Add test cases for edge cases in metadataType.

    It's recommended to add a test case where metadataType is an empty string or an unexpected
    value. This will help ensure that your code robustly handles edge cases and maintains
    correct behavior under various inputs.

    pkg/apis/softwarecomposition/syfttypes_test.go [25-30]

     {
    -    name:    "TestUpdateSBOMSyft",
    +    name:    "TestUpdateSBOMSyft with empty metadataType",
         input:   artifact,
    -    args:    args{id: "8a49897e59f569c2", metadataType: "dpkg-db-entry"},
    -    wantErr: false,
    +    args:    args{id: "8a49897e59f569c2", metadataType: ""},
    +    wantErr: true, // Assuming the function should error out on empty metadataType
     }
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @dwertent dwertent merged commit 74572f3 into main Apr 10, 2024
    4 of 5 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants