diff --git a/CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs b/CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs index 512ee6d..bd94ce6 100644 --- a/CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs +++ b/CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs @@ -178,6 +178,23 @@ public async Task ProcessCatalogYamlAsync_ShouldAddTagsFromRepository_WhenTagsAr mockFileSystem.Verify(fs => fs.File.WriteAllText(catalogFilePath, It.Is(s => Regex.IsMatch(s, @"tags:\s*(?:-\s*\S+\s*)*-\s*newTag", RegexOptions.Multiline))), Times.Once); } + [TestMethod] + public async Task ProcessCatalogYamlAsync_ShouldFilterTagsThatMatchTypes() + { + // Arrange + var repoName = "SLC-AS-testRepo"; + var yamlContent = "id: testId\nshort_description: test description"; + mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists + mockFileSystem.Setup(fs => fs.File.ReadAllText(catalogFilePath)).Returns(yamlContent); + mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List { "dataminer-automation-script", "newTag","dataminer","otherTag", "dataminer-connector" }); + + // Act + await catalogManager.ProcessCatalogYamlAsync(repoName); + + // Assert + mockFileSystem.Verify(fs => fs.File.WriteAllText(catalogFilePath, It.Is(s => Regex.IsMatch(s, @"tags:\s*\n\s*-\s*newTag\s*\n\s*-\s*otherTag\s*(\n\s*#.*|\s*)*$", RegexOptions.Multiline))), Times.Once); + } + [TestMethod] public async Task ProcessCatalogYamlAsync_ShouldUseRepositoryNameAsTitle_WhenTitleIsMissing() { diff --git a/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs b/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs index 10862ad..54ae7ef 100644 --- a/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs +++ b/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs @@ -184,7 +184,7 @@ private async Task CheckTags(CatalogYaml catalogYaml) catalogYaml.Tags = new List(); } - if(catalogYaml.Tags.Count >= 5) + if (catalogYaml.Tags.Count >= 5) { logger.LogDebug("Catalog YAML has the max amount of tags already. Skipping the adding GitHub topics step."); return; @@ -245,17 +245,22 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName) // Always check the tags if (catalogYaml.Tags != null) { + List filteredTopics = new List(); foreach (var topic in catalogYaml.Tags) { var inferredType = InferArtifactContentType(topic); if (!String.IsNullOrWhiteSpace(inferredType)) { catalogYaml.Type = inferredType; - catalogYaml.Tags.Remove(topic); logger.LogDebug($"Item Type could be inferred from repository topics {catalogYaml.Type}."); - break; + } + else + { + filteredTopics.Add(topic); } } + + catalogYaml.Tags = filteredTopics; } if (String.IsNullOrWhiteSpace(catalogYaml.Type)) diff --git a/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/Constants.cs b/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/Constants.cs index 10b450e..e0f37e4 100644 --- a/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/Constants.cs +++ b/Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/Constants.cs @@ -8,35 +8,29 @@ internal static class Constants { public static readonly List ArtifactTypeMap = new List() { - { new ArtifactType(new[] { "AS" }, "Automation", "Automation Script", "automationscript") }, - { new ArtifactType(new[] { "C" }, "Connector", "Connector", "connector")}, - { new ArtifactType(new[] { "CF" }, "Custom Solution", "Companion File", "companionfile")}, - { new ArtifactType(new[] { "CHATOPS" }, "ChatOps Extension", "ChatOps Extension", "chatopsextension")}, - { new ArtifactType(new[] { "D" }, "Dashboard", "Dashboard", "dashboard")}, - { new ArtifactType(new[] { "DOC" }, "Custom Solution", "Documentation", "documentation")}, - { new ArtifactType(new[] { "F" }, "Custom Solution", "Function Definition", "functiondefinition")}, - { new ArtifactType(new[] { "GQIDS" }, "Ad Hoc Data Source", "gqidatasource", "Ad Hoc Data Source", "adhocdatasource")}, - { new ArtifactType(new[] { "GQIO" }, "Data Transformer", "GQI Operator", "gqioperator")}, - { new ArtifactType(new[] { "LSO" }, "Automation", "Live Cycle Service Orchestration", "lifecycleserviceorchestration")}, - { new ArtifactType(new[] { "PA" }, "Automation", "Process Automation", "processautomation") }, - { new ArtifactType(new[] { "PLS" }, "Automation", "Profile Load Script", "profileloadscript") }, - { new ArtifactType(new[] { "S" }, "Custom Solution", "Solution", "solution") }, - { new ArtifactType(new[] { "SC" }, "Scripted Connector", "Scripted Connector", "scriptedconnector") }, - { new ArtifactType(new[] { "T" }, "Custom Solution", "Testing Solution", "testingsolution") }, - { new ArtifactType(new[] { "UDAPI" }, "User-Defined API", "User Defined API", "userdefinedapi") }, - { new ArtifactType(new[] { "V" }, "Visual Overview", "Visio", "visio") }, - { new ArtifactType(new[] { "LCA" }, "Custom Solution", "Low-Code App", "lowcodeapp") } + { new ArtifactType(new[] { "AS" }, "Automation", "Automation Script", "automationscript", "dataminer-automation-script") }, + { new ArtifactType(new[] { "C" }, "Connector", "Connector", "connector","dataminer-connector")}, + { new ArtifactType(new[] { "CF" }, "Custom Solution", "Companion File", "companionfile","dataminer-companion-file")}, + { new ArtifactType(new[] { "CHATOPS" }, "ChatOps Extension", "ChatOps Extension", "chatopsextension", "dataminer-bot", "dataminer-chatops")}, + { new ArtifactType(new[] { "D" }, "Dashboard", "Dashboard", "dashboard", "dataminer-dashboard")}, + { new ArtifactType(new[] { "DOC" }, "Custom Solution", "Documentation", "documentation", "dataminer-doc")}, + { new ArtifactType(new[] { "F" }, "Custom Solution", "Function Definition", "functiondefinition", "dataminer-function")}, + { new ArtifactType(new[] { "GQIDS" }, "Ad Hoc Data Source", "gqidatasource", "Ad Hoc Data Source", "adhocdatasource", "dataminer-gqi-data-source")}, + { new ArtifactType(new[] { "GQIO" }, "Data Transformer", "GQI Operator", "gqioperator", "dataminer-gqi-operator")}, + { new ArtifactType(new[] { "LSO" }, "Automation", "Live Cycle Service Orchestration", "lifecycleserviceorchestration", "dataminer-life-service-orchestration")}, + { new ArtifactType(new[] { "PA" }, "Automation", "Process Automation", "processautomation", "dataminer-process-automation-script") }, + { new ArtifactType(new[] { "PLS" }, "Automation", "Profile Load Script", "profileloadscript", "dataminer-profile-load-script") }, + { new ArtifactType(new[] { "S" }, "Custom Solution", "Solution", "solution", "dataminer","dataminer-solution", "dataminer-dis-macro", "dataminer-nuget") }, + { new ArtifactType(new[] { "SC" }, "Scripted Connector", "Scripted Connector", "scriptedconnector","dataminer-scripted-connector") }, + { new ArtifactType(new[] { "T" }, "Custom Solution", "Testing Solution", "testingsolution", "dataminer-regression-test", "dataminer-UI-test") }, + { new ArtifactType(new[] { "UDAPI" }, "User-Defined API", "User Defined API", "userdefinedapi", "dataminer-user-defined-api") }, + { new ArtifactType(new[] { "V" }, "Visual Overview", "Visio", "visio","dataminer-visio") }, + { new ArtifactType(new[] { "LCA" }, "Custom Solution", "Low-Code App", "lowcodeapp", "dataminer-low-code-app") } }; } internal class ArtifactType { - public string[] GitHubNames { get; set; } - - public string[] GitHubAbbreviations { get; set; } - - public string CatalogName { get; set; } - public ArtifactType(string[] abbreviations, string catalogName, params string[] githubNames) { GitHubAbbreviations = abbreviations; @@ -46,6 +40,12 @@ public ArtifactType(string[] abbreviations, string catalogName, params string[] CatalogName = catalogName; } + public string CatalogName { get; set; } + + public string[] GitHubAbbreviations { get; set; } + + public string[] GitHubNames { get; set; } + public bool IsMatch(string searchTerm) { if (searchTerm.Equals(CatalogName, StringComparison.OrdinalIgnoreCase) || @@ -58,5 +58,4 @@ public bool IsMatch(string searchTerm) return false; } } - -} +} \ No newline at end of file