Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/fixtopic filter bug #22

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ public async Task ProcessCatalogYamlAsync_ShouldAddTagsFromRepository_WhenTagsAr
mockFileSystem.Verify(fs => fs.File.WriteAllText(catalogFilePath, It.Is<string>(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<string> { "dataminer-automation-script", "newTag","dataminer","otherTag", "dataminer-connector" });

// Act
await catalogManager.ProcessCatalogYamlAsync(repoName);

// Assert
mockFileSystem.Verify(fs => fs.File.WriteAllText(catalogFilePath, It.Is<string>(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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private async Task CheckTags(CatalogYaml catalogYaml)
catalogYaml.Tags = new List<string>();
}

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;
Expand Down Expand Up @@ -245,17 +245,22 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
// Always check the tags
if (catalogYaml.Tags != null)
{
List<string> filteredTopics = new List<string>();
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))
Expand Down
51 changes: 25 additions & 26 deletions Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,29 @@ internal static class Constants
{
public static readonly List<ArtifactType> ArtifactTypeMap = new List<ArtifactType>()
{
{ 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;
Expand All @@ -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) ||
Expand All @@ -58,5 +58,4 @@ public bool IsMatch(string searchTerm)
return false;
}
}

}
}