Skip to content

Commit

Permalink
refactor: extract get_licenses function
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Aug 24, 2023
1 parent 52b89d2 commit 7d98dd5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/cyclone_dx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@ pub fn dump_derivation(derivation_path: &str, package_node: &crate::nix::Package
);
}

let mut licenses: Vec<LicenseChoice> = vec![];
for license in &package_node.package.meta.get_licenses() {
let licenses = get_licenses(&package_node.package.meta.get_licenses());
if licenses.len() != 0 {
component_builder.licenses(licenses);
}

Some(component_builder.build().unwrap())
}

fn get_licenses(licenses: &Vec<crate::nix::PackageLicense>) -> Vec<LicenseChoice> {
let mut response: Vec<LicenseChoice> = vec![];
for license in licenses {
match license {
crate::nix::PackageLicense::Name(n) => {
licenses.push(LicenseChoice {
response.push(LicenseChoice {
expression: Some(n.to_string()),
license: None,
});
Expand All @@ -137,16 +146,12 @@ pub fn dump_derivation(derivation_path: &str, package_node: &crate::nix::Package
if let Some(full_name) = &license_details.full_name {
license_builder.name(full_name);
}
licenses.push(LicenseChoice {
response.push(LicenseChoice {
expression: None,
license: Some(license_builder.build().unwrap()),
});
}
}
}
if licenses.len() != 0 {
component_builder.licenses(licenses);
}

Some(component_builder.build().unwrap())
response
}

0 comments on commit 7d98dd5

Please sign in to comment.