diff --git a/CICD.Tools.CatalogUpload.Lib/CatalogMetaDataFactory.cs b/CICD.Tools.CatalogUpload.Lib/CatalogMetaDataFactory.cs index 32e7cdc..579db38 100644 --- a/CICD.Tools.CatalogUpload.Lib/CatalogMetaDataFactory.cs +++ b/CICD.Tools.CatalogUpload.Lib/CatalogMetaDataFactory.cs @@ -1,12 +1,9 @@ namespace Skyline.DataMiner.CICD.Tools.CatalogUpload.Lib { using System; - using System.Collections.Generic; - using System.IO.Compression; using System.IO; + using System.IO.Compression; using System.Linq; - using System.Text; - using System.Threading.Tasks; using System.Xml.Linq; using Skyline.DataMiner.CICD.FileSystem; @@ -18,12 +15,12 @@ public class CatalogMetaDataFactory : ICatalogMetaDataFactory { /// - /// Creates a partial CataLogMetaData using any information it can from the artifact itself. Check the items for null and complete. + /// Creates a partial using any information it can from the artifact itself. Check the items for null and complete. /// /// Path to the artifact. - /// - /// - /// An instance of .> + /// Optional. The path to the README file. If null, the method will attempt to locate the README. + /// Optional. The path to the images directory. If null, no images path will be set. + /// An instance of . /// Provided path should not be null /// Expected data was not present in the Artifact. public CatalogMetaData FromArtifact(string pathToArtifact, string pathToReadme = null, string pathToImages = null) @@ -37,11 +34,11 @@ public CatalogMetaData FromArtifact(string pathToArtifact, string pathToReadme = if (pathToArtifact.EndsWith(".dmapp", StringComparison.InvariantCultureIgnoreCase)) { - meta = CatalogMetaDataFactory.FromDmapp(pathToArtifact); + meta = FromDmapp(pathToArtifact); } else if (pathToArtifact.EndsWith(".dmprotocol", StringComparison.InvariantCultureIgnoreCase)) { - meta = CatalogMetaDataFactory.FromDmprotocol(pathToArtifact); + meta = FromDmprotocol(pathToArtifact); } else { @@ -165,8 +162,8 @@ private static CatalogMetaData FromDmapp(string pathToDmapp) var buildNumber = appInfo.Element("Build")?.Value; var minimumDmaVersion = appInfo.Element("MinDmaVersion")?.Value; - // cleanup first line from descriptionFromPackage if it contains version. We dont want that hardcoded version when the version might change later. - if (!string.IsNullOrEmpty(description)) + // Cleanup first line from descriptionFromPackage if it contains version. We don't want that hardcoded version when the version might change later. + if (!String.IsNullOrEmpty(description)) { // Split the string by newlines to work with the first line string[] lines = description.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); @@ -175,13 +172,13 @@ private static CatalogMetaData FromDmapp(string pathToDmapp) if (lines[0].Contains("version:", StringComparison.OrdinalIgnoreCase)) { // Remove the first line and join the remaining lines back into a single string - description = string.Join(Environment.NewLine, lines.Skip(1)); + description = String.Join(Environment.NewLine, lines.Skip(1)); } } if (!String.IsNullOrWhiteSpace(minimumDmaVersion)) { - description = ($"Minimum DataMiner Version: {minimumDmaVersion}\r\n{description ?? ""}"); + description = $"Minimum DataMiner Version: {minimumDmaVersion}\r\n{description ?? ""}"; } if (!String.IsNullOrWhiteSpace(buildNumber)) @@ -210,8 +207,6 @@ private static CatalogMetaData FromDmapp(string pathToDmapp) } if (description.Length > 500) description = description.Substring(0, 497) + "..."; - - meta.Version.VersionDescription = description; meta.ContentType = contentType; return meta; @@ -299,13 +294,10 @@ private static CatalogMetaData FromDmprotocol(string pathToDmprotocol) var majorXml = systemXml?.Element(ns + "MajorVersions")?.Elements().FirstOrDefault(p => p.Attribute("id")?.Value == major); var minorXml = majorXml?.Element(ns + "MinorVersions")?.Elements().FirstOrDefault(p => p.Attribute("id")?.Value == minor); - if (minorXml != null) + var allChanges = minorXml?.Element(ns + "Changes")?.Elements().ToList(); + if (allChanges != null && allChanges.Any()) { - var allChanges = minorXml.Element(ns + "Changes")?.Elements(); - if (allChanges != null && allChanges.Any()) - { - versionDescription = string.Join(Environment.NewLine, allChanges.Select(change => $"{change.Name.LocalName}: {change.Value.Trim()}")); - } + versionDescription = String.Join(Environment.NewLine, allChanges.Select(change => $"{change.Name.LocalName}: {change.Value.Trim()}")); } } } diff --git a/CICD.Tools.CatalogUpload.Lib/ICatalogMetaDataFactory.cs b/CICD.Tools.CatalogUpload.Lib/ICatalogMetaDataFactory.cs index 03126e9..57f0874 100644 --- a/CICD.Tools.CatalogUpload.Lib/ICatalogMetaDataFactory.cs +++ b/CICD.Tools.CatalogUpload.Lib/ICatalogMetaDataFactory.cs @@ -10,13 +10,13 @@ public interface ICatalogMetaDataFactory { /// - /// Creates a partial CataLogMetaData using any information it can from the artifact itself. Check the items for null and complete. + /// Creates a partial using any information it can from the artifact itself. Check the items for null and complete. /// /// Path to the artifact. - /// - /// - /// An instance of .> - /// Provided path should not be null + /// Optional. The path to the README file. If null, the method will attempt to locate the README. + /// Optional. The path to the images directory. If null, no images path will be set. + /// An instance of . + /// Provided path should not be null. /// Expected data was not present in the Artifact. public CatalogMetaData FromArtifact(string pathToArtifact, string pathToReadme = null, string pathToImages = null); diff --git a/CICD.Tools.CatalogUpload/OptionalRegistrationArguments.cs b/CICD.Tools.CatalogUpload/OptionalRegistrationArguments.cs index 84870dc..c69a1fe 100644 --- a/CICD.Tools.CatalogUpload/OptionalRegistrationArguments.cs +++ b/CICD.Tools.CatalogUpload/OptionalRegistrationArguments.cs @@ -44,8 +44,6 @@ internal class OptionalRegistrationArgumentsBinder : BinderBase uriSourceCode; private readonly Option overrideVersion; - - private readonly Option branch; private readonly Option committerMail; private readonly Option releaseUri; @@ -64,7 +62,6 @@ public OptionalRegistrationArgumentsBinder(Option uriSourceCode, Option< this.catalogIdentifier = catalogIdentifier; } - /// /// Retrieves the bound value of from the . /// @@ -86,6 +83,5 @@ protected override OptionalRegistrationArguments GetBoundValue(BindingContext bi CatalogIdentifier = bindingContext.ParseResult.GetValueForOption(catalogIdentifier), }; } - } } \ No newline at end of file diff --git a/CICD.Tools.CatalogUpload/Program.cs b/CICD.Tools.CatalogUpload/Program.cs index 849daf1..ba85ef3 100644 --- a/CICD.Tools.CatalogUpload/Program.cs +++ b/CICD.Tools.CatalogUpload/Program.cs @@ -1,29 +1,16 @@ namespace Skyline.DataMiner.CICD.Tools.CatalogUpload { - using System; using System.CommandLine; - using System.CommandLine.Binding; - using System.Diagnostics; using System.Threading.Tasks; - using System.Xml.XPath; - - using CICD.Tools.CatalogUpload; using global::CICD.Tools.CatalogUpload; using Microsoft.Extensions.Logging; - using Microsoft.Extensions.Options; using Serilog; - using Serilog.Core; using Skyline.DataMiner.CICD.FileSystem; using Skyline.DataMiner.CICD.Tools.CatalogUpload.Lib; - using Skyline.DataMiner.CICD.Tools.Reporter; - - using YamlDotNet.Core; - - using static System.Net.Mime.MediaTypeNames; /// /// Uploads artifacts to the Skyline DataMiner catalog (https://catalog.dataminer.services). diff --git a/CICD.Tools.CatalogUpload/Uploader.cs b/CICD.Tools.CatalogUpload/Uploader.cs index 2fb71ae..fb6f3b8 100644 --- a/CICD.Tools.CatalogUpload/Uploader.cs +++ b/CICD.Tools.CatalogUpload/Uploader.cs @@ -256,7 +256,6 @@ private void ApplyOptionalArguments(OptionalRegistrationArguments optionalArgume metaData.Version.ReleaseUri = optionalArguments.ReleaseUri; } - if (optionalArguments.CatalogIdentifier != null) { logger.LogDebug($"Overriding CatalogIdentifier from '{metaData.CatalogIdentifier}' to '{optionalArguments.CatalogIdentifier}'");