Skip to content

Commit

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

if package_node.patches.len() != 0 {
let mut commits: Vec<Commit> = vec![];
for patch in &package_node.patches {
let mut commit = CommitBuilder::default();
commit.url(patch.get_url().unwrap());
// TODO we could also populate the uid, which is the commit SHA
commits.push(commit.build().unwrap())
}
component_builder.pedigree(
ComponentPedigreeBuilder::default()
.commits(commits)
.build()
.unwrap(),
);
let commits = get_commits(&package_node.patches);
if commits.len() != 0 {
let mut pedigree_builder = ComponentPedigreeBuilder::default();
pedigree_builder.commits(commits);
component_builder.pedigree(pedigree_builder.build().unwrap());
}

let licenses = get_licenses(&package_node.package.meta.get_licenses());
Expand All @@ -126,6 +117,19 @@ pub fn dump_derivation(derivation_path: &str, package_node: &crate::nix::Package

Some(component_builder.build().unwrap())
}
fn get_commits(patches: &Vec<crate::nix::Derivation>) -> Vec<Commit> {
let mut response: Vec<Commit> = vec![];
if patches.len() != 0 {
let mut commits: Vec<Commit> = vec![];
for patch in patches {
let mut commit = CommitBuilder::default();
commit.url(patch.get_url().unwrap());
// TODO we could also populate the uid, which is the commit SHA
commits.push(commit.build().unwrap())
}
}
response
}

fn get_licenses(licenses: &Vec<crate::nix::PackageLicense>) -> Vec<LicenseChoice> {
let mut response: Vec<LicenseChoice> = vec![];
Expand Down

0 comments on commit 5176a4f

Please sign in to comment.