Skip to content

Commit 4000e07

Browse files
Removing the Tag if it's for ArtifactContentType.
1 parent 4d77522 commit 4000e07

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public async Task ProcessCatalogYamlAsync_ShouldAddTagsFromRepository_WhenTagsAr
168168
var yamlContent = "id: testId\nshort_description: test description";
169169
mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists
170170
mockFileSystem.Setup(fs => fs.File.ReadAllText(catalogFilePath)).Returns(yamlContent);
171-
mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List<string> { "newTag" });
171+
mockGitHubService.Setup(s => s.GetRepositoryTopicsAsync()).ReturnsAsync(new List<string> { "automationscript", "newTag" });
172172

173173
// Act
174174
await catalogManager.ProcessCatalogYamlAsync(repoName);

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task ProcessCatalogYamlAsync(string repoName, string catalogIdentif
7070

7171
CleanTitle parsedRepoName = CheckTitle(repoName, catalogYaml);
7272

73-
// Perform this after CheckTags
73+
// Perform this after CheckTags.
7474
CheckType(catalogYaml, parsedRepoName);
7575

7676
string outputPath = filePath ?? fs.Path.Combine(workspace, "catalog.yml");
@@ -185,6 +185,8 @@ private async Task CheckTags(CatalogYaml catalogYaml)
185185
if (topics is { Count: > 0 })
186186
{
187187
catalogYaml.Tags.AddRange(topics);
188+
189+
// Remove duplicates
188190
catalogYaml.Tags = catalogYaml.Tags.Distinct().ToList();
189191
logger.LogDebug("Distinct GitHub Topics found and applied.");
190192
}
@@ -231,15 +233,16 @@ private void CheckType(CatalogYaml catalogYaml, CleanTitle parsedRepoName)
231233
logger.LogDebug($"Item Type could be inferred from repository name {catalogYaml.Type}.");
232234
}
233235

234-
// If we still don't have a type, check topics for matching ArtifactContentType
235-
if (String.IsNullOrWhiteSpace(catalogYaml.Type) && catalogYaml.Tags != null)
236+
// Always check the tags
237+
if (catalogYaml.Tags != null)
236238
{
237239
foreach (var topic in catalogYaml.Tags)
238240
{
239241
var inferredType = InferArtifactContentType(topic);
240242
if (!String.IsNullOrWhiteSpace(inferredType))
241243
{
242244
catalogYaml.Type = inferredType;
245+
catalogYaml.Tags.Remove(topic);
243246
logger.LogDebug($"Item Type could be inferred from repository topics {catalogYaml.Type}.");
244247
break;
245248
}

0 commit comments

Comments
 (0)