@@ -7,7 +7,10 @@ use std::str::FromStr;
7
7
use anyhow:: { Context , Result } ;
8
8
use cyclonedx_bom:: external_models:: normalized_string:: NormalizedString ;
9
9
use cyclonedx_bom:: external_models:: uri:: { Purl , Uri } ;
10
+ use cyclonedx_bom:: models:: attached_text:: AttachedText ;
10
11
use cyclonedx_bom:: models:: bom:: { Bom , UrnUuid } ;
12
+ use cyclonedx_bom:: models:: code:: { Diff , Patch , PatchClassification , Patches } ;
13
+ use cyclonedx_bom:: models:: component:: Pedigree ;
11
14
use cyclonedx_bom:: models:: component:: { Classification , Component , Components , Scope } ;
12
15
use cyclonedx_bom:: models:: external_reference:: {
13
16
self , ExternalReference , ExternalReferenceType , ExternalReferences ,
@@ -170,6 +173,17 @@ impl CycloneDXComponent {
170
173
component. external_references = Some ( ExternalReferences ( external_references) ) ;
171
174
}
172
175
176
+ if !derivation. patches . is_empty ( ) {
177
+ component. pedigree = Some ( Pedigree {
178
+ ancestors : None ,
179
+ descendants : None ,
180
+ variants : None ,
181
+ commits : None ,
182
+ patches : Some ( convert_patches ( & derivation. patches ) ) ,
183
+ notes : None ,
184
+ } ) ;
185
+ }
186
+
173
187
Self ( component)
174
188
}
175
189
}
@@ -277,3 +291,25 @@ fn metadata_tools() -> Tools {
277
291
components : Some ( Components ( vec ! [ component] ) ) ,
278
292
}
279
293
}
294
+
295
+ fn convert_patches ( patches : & [ String ] ) -> Patches {
296
+ let cyclonedx_patches = patches
297
+ . iter ( )
298
+ . filter_map ( |patch| fs:: read_to_string ( patch) . ok ( ) )
299
+ . map ( |diff| Patch {
300
+ // As we know nothing about the patch at this level, the safest is to assume that it's
301
+ // unofficial
302
+ patch_type : PatchClassification :: Unofficial ,
303
+ diff : Some ( Diff {
304
+ text : Some ( AttachedText {
305
+ content_type : Some ( NormalizedString :: new ( "text/plain" ) ) ,
306
+ encoding : None ,
307
+ content : diff,
308
+ } ) ,
309
+ url : None ,
310
+ } ) ,
311
+ resolves : None ,
312
+ } )
313
+ . collect :: < Vec < _ > > ( ) ;
314
+ Patches ( cyclonedx_patches)
315
+ }
0 commit comments