Skip to content

Commit 9175247

Browse files
Fixes bug where topics dont get filtered if a type is defined in a custom yaml file.
1 parent 98e2af6 commit 9175247

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs

+34
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ public async Task ProcessCatalogYamlAsync_ShouldFilterTagsThatMatchTypes()
195195
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);
196196
}
197197

198+
[TestMethod]
199+
public async Task ProcessCatalogYamlAsync_ShouldFilterTagsThatMatchTypes_NoNameType()
200+
{
201+
// Arrange
202+
var repoName = "SLC-testRepo";
203+
var yamlContent = "id: testId\nshort_description: test description";
204+
mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists
205+
mockFileSystem.Setup(fs => fs.File.ReadAllText(catalogFilePath)).Returns(yamlContent);
206+
mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List<string> { "dataminer-automation-script", "newTag", "dataminer", "otherTag", "dataminer-connector" });
207+
208+
// Act
209+
await catalogManager.ProcessCatalogYamlAsync(repoName);
210+
211+
// Assert
212+
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);
213+
}
214+
215+
[TestMethod]
216+
public async Task ProcessCatalogYamlAsync_ShouldFilterTagsThatMatchTypes_TypeInYaml()
217+
{
218+
// Arrange
219+
var repoName = "SLC-testRepo";
220+
var yamlContent = "type: Automation Script\nid: testId\nshort_description: test description";
221+
mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists
222+
mockFileSystem.Setup(fs => fs.File.ReadAllText(catalogFilePath)).Returns(yamlContent);
223+
mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List<string> { "dataminer-automation-script", "newTag", "dataminer", "otherTag", "dataminer-connector" });
224+
225+
// Act
226+
await catalogManager.ProcessCatalogYamlAsync(repoName);
227+
228+
// Assert
229+
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);
230+
}
231+
198232
[TestMethod]
199233
public async Task ProcessCatalogYamlAsync_ShouldUseRepositoryNameAsTitle_WhenTitleIsMissing()
200234
{

Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs

+22-7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public async Task ProcessCatalogYamlAsync(string repoName, string catalogIdentif
7474
// Perform this after CheckTags.
7575
CheckType(catalogYaml, parsedRepoName);
7676

77+
// Cleanup tags, only after checking type
78+
RemoveTagsThatDealWithType(catalogYaml);
79+
7780
string outputPath = filePath ?? fs.Path.Combine(workspace, "catalog.yml");
7881
string autoGeneratedOutputPath = autoGenFilePath ?? fs.Path.Combine(workspace, ".githubtocatalog", "auto-generated-catalog.yml");
7982

@@ -245,7 +248,6 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
245248
// Always check the tags
246249
if (catalogYaml.Tags != null)
247250
{
248-
List<string> filteredTopics = new List<string>();
249251
foreach (var topic in catalogYaml.Tags)
250252
{
251253
var inferredType = InferArtifactContentType(topic);
@@ -254,13 +256,7 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
254256
catalogYaml.Type = inferredType;
255257
logger.LogDebug($"Item Type could be inferred from repository topics {catalogYaml.Type}.");
256258
}
257-
else
258-
{
259-
filteredTopics.Add(topic);
260-
}
261259
}
262-
263-
catalogYaml.Tags = filteredTopics;
264260
}
265261

266262
if (String.IsNullOrWhiteSpace(catalogYaml.Type))
@@ -270,6 +266,25 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
270266
}
271267
}
272268

269+
private void RemoveTagsThatDealWithType(CatalogYaml catalogYaml)
270+
{
271+
// Always check the tags
272+
if (catalogYaml.Tags != null)
273+
{
274+
List<string> filteredTopics = new List<string>();
275+
foreach (var topic in catalogYaml.Tags)
276+
{
277+
var inferredType = InferArtifactContentType(topic);
278+
if (String.IsNullOrWhiteSpace(inferredType))
279+
{
280+
filteredTopics.Add(topic);
281+
}
282+
}
283+
284+
catalogYaml.Tags = filteredTopics;
285+
}
286+
}
287+
273288
/// <summary>
274289
/// Creates a new catalog YAML object by reading the existing catalog.yml or manifest.yml file in the workspace.
275290
/// If no file is found, it creates an empty catalog YAML object.

0 commit comments

Comments
 (0)