From b555bdfb5f57cc551fafb891323f39a5cc477662 Mon Sep 17 00:00:00 2001 From: andreas hilti <69210561+andreas-hilti@users.noreply.github.com> Date: Sat, 9 Aug 2025 16:49:45 +0200 Subject: [PATCH] add timestamp in merge command Signed-off-by: andreas hilti <69210561+andreas-hilti@users.noreply.github.com> --- src/cyclonedx/Commands/MergeCommand.cs | 8 ++++++++ tests/cyclonedx.tests/MergeTests.cs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/cyclonedx/Commands/MergeCommand.cs b/src/cyclonedx/Commands/MergeCommand.cs index 34287ff..f76565a 100644 --- a/src/cyclonedx/Commands/MergeCommand.cs +++ b/src/cyclonedx/Commands/MergeCommand.cs @@ -107,6 +107,14 @@ public static async Task Merge(MergeCommandOptions options) outputBom.Version = 1; outputBom.SerialNumber = "urn:uuid:" + System.Guid.NewGuid().ToString(); + if (outputBom.Metadata == null) + { + outputBom.Metadata = new Metadata(); + } + if (outputBom.Metadata.Timestamp == null) + { + outputBom.Metadata.Timestamp = DateTime.Now; + } if (!outputToConsole) { diff --git a/tests/cyclonedx.tests/MergeTests.cs b/tests/cyclonedx.tests/MergeTests.cs index e9b60dc..56b9c62 100644 --- a/tests/cyclonedx.tests/MergeTests.cs +++ b/tests/cyclonedx.tests/MergeTests.cs @@ -77,6 +77,8 @@ public async Task Merge( var bom = File.ReadAllText(fullOutputPath); bom = Regex.Replace(bom, @"\s*""serialNumber"": "".*?"",\r?\n", ""); // json bom = Regex.Replace(bom, @"\s+serialNumber="".*?""", ""); // xml + bom = Regex.Replace(bom, @"\s*""timestamp"": "".*?"",\r?\n", ""); // json + bom = Regex.Replace(bom, @"\s+.*?", ""); // xml Snapshot.Match(bom, SnapshotNameExtension.Create(hierarchical ? "Hierarchical" : "Flat", snapshotInputFilenames, inputFormat, outputFilename, outputFormat, outputVersion)); } }