Skip to content

Commit 98e2af6

Browse files
Dev/fixtopic filter bug (#22)
* Added topics from github guidelines SLC. * Fixing the Topic Filtering bug.
1 parent 6f01afd commit 98e2af6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ public async Task ProcessCatalogYamlAsync_ShouldAddTagsFromRepository_WhenTagsAr
178178
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);
179179
}
180180

181+
[TestMethod]
182+
public async Task ProcessCatalogYamlAsync_ShouldFilterTagsThatMatchTypes()
183+
{
184+
// Arrange
185+
var repoName = "SLC-AS-testRepo";
186+
var yamlContent = "id: testId\nshort_description: test description";
187+
mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists
188+
mockFileSystem.Setup(fs => fs.File.ReadAllText(catalogFilePath)).Returns(yamlContent);
189+
mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List<string> { "dataminer-automation-script", "newTag","dataminer","otherTag", "dataminer-connector" });
190+
191+
// Act
192+
await catalogManager.ProcessCatalogYamlAsync(repoName);
193+
194+
// Assert
195+
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);
196+
}
197+
181198
[TestMethod]
182199
public async Task ProcessCatalogYamlAsync_ShouldUseRepositoryNameAsTitle_WhenTitleIsMissing()
183200
{

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private async Task CheckTags(CatalogYaml catalogYaml)
184184
catalogYaml.Tags = new List<string>();
185185
}
186186

187-
if(catalogYaml.Tags.Count >= 5)
187+
if (catalogYaml.Tags.Count >= 5)
188188
{
189189
logger.LogDebug("Catalog YAML has the max amount of tags already. Skipping the adding GitHub topics step.");
190190
return;
@@ -245,17 +245,22 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
245245
// Always check the tags
246246
if (catalogYaml.Tags != null)
247247
{
248+
List<string> filteredTopics = new List<string>();
248249
foreach (var topic in catalogYaml.Tags)
249250
{
250251
var inferredType = InferArtifactContentType(topic);
251252
if (!String.IsNullOrWhiteSpace(inferredType))
252253
{
253254
catalogYaml.Type = inferredType;
254-
catalogYaml.Tags.Remove(topic);
255255
logger.LogDebug($"Item Type could be inferred from repository topics {catalogYaml.Type}.");
256-
break;
256+
}
257+
else
258+
{
259+
filteredTopics.Add(topic);
257260
}
258261
}
262+
263+
catalogYaml.Tags = filteredTopics;
259264
}
260265

261266
if (String.IsNullOrWhiteSpace(catalogYaml.Type))

0 commit comments

Comments
 (0)