Skip to content

Commit

Permalink
Merge pull request #131 from secufoe/src-url-deserializer
Browse files Browse the repository at this point in the history
transformer: handle null in src.url during deserialization
  • Loading branch information
nikstur authored Sep 9, 2024
2 parents bd09302 + fcadf9b commit d5a20d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions rust/transformer/src/cyclonedx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ impl CycloneDXComponent {
let mut external_references = Vec::new();

if let Some(src) = derivation.src {
external_references.push(convert_src(&src));
if src.url.is_some() {
external_references.push(convert_src(&src));
}
}
if let Some(meta) = derivation.meta {
component.licenses = convert_licenses(&meta);
Expand Down Expand Up @@ -194,9 +196,13 @@ fn convert_licenses(meta: &Meta) -> Option<Licenses> {
}

fn convert_src(src: &Src) -> ExternalReference {
assert!(
src.url.is_some(),
"src.url must be Some to generate ExternalReference",
);
ExternalReference {
external_reference_type: ExternalReferenceType::Vcs,
url: string_to_url(&src.url),
url: string_to_url(&src.url.clone().unwrap_or_default()),
comment: None,
hashes: src.hash.clone().and_then(|s| convert_hash(&s)),
}
Expand Down
2 changes: 1 addition & 1 deletion rust/transformer/src/derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ pub struct License {

#[derive(Deserialize, Clone, Debug)]
pub struct Src {
pub url: String,
pub url: Option<String>,
pub hash: Option<String>,
}

0 comments on commit d5a20d0

Please sign in to comment.