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

Skip modules without artifacts in command summary #1219

Merged
merged 2 commits into from
Aug 5, 2024
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
11 changes: 11 additions & 0 deletions artifactory/commands/commandssummaries/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,28 @@ func (bis *BuildInfoSummary) buildInfoTable(builds []*buildInfo.BuildInfo) strin
func (bis *BuildInfoSummary) buildInfoModules(builds []*buildInfo.BuildInfo) string {
var markdownBuilder strings.Builder
markdownBuilder.WriteString("\n\n ### Modules Published As Part of This Build \n\n")
var shouldGenerate bool
for _, build := range builds {
for _, module := range build.Modules {
if len(module.Artifacts) == 0 {
continue
}

switch module.Type {
case buildInfo.Docker, buildInfo.Maven, buildInfo.Npm, buildInfo.Go, buildInfo.Generic, buildInfo.Terraform:
markdownBuilder.WriteString(bis.generateModuleMarkdown(module))
shouldGenerate = true
default:
// Skip unsupported module types.
continue
}
}
}

// If no supported module with artifacts was found, avoid generating the markdown.
if !shouldGenerate {
return ""
}
return markdownBuilder.String()
}

Expand Down
35 changes: 35 additions & 0 deletions artifactory/commands/commandssummaries/buildinfosummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,41 @@ func TestBuildInfoModules(t *testing.T) {
assert.Equal(t, getTestDataFile(t, "modules.md"), gh.buildInfoModules(builds))
}

// Validate that if no supported module with artifacts was found, we avoid generating the markdown.
func TestBuildInfoModulesEmpty(t *testing.T) {
gh := &BuildInfoSummary{}
var builds = []*buildinfo.BuildInfo{
{
Name: "buildName",
Number: "123",
Started: "2024-05-05T12:47:20.803+0300",
BuildUrl: "http://myJFrogPlatform/builds/buildName/123",
Modules: []buildinfo.Module{
{
Type: buildinfo.Maven,
Artifacts: []buildinfo.Artifact{},
Dependencies: []buildinfo.Dependency{{
Id: "dep1",
},
},
},
{
Type: buildinfo.Gradle,
Artifacts: []buildinfo.Artifact{
{
Name: "gradleArtifact",
Path: "dir/gradleArtifact",
OriginalDeploymentRepo: "gradle-local",
},
},
},
},
},
}

assert.Empty(t, gh.buildInfoModules(builds))
}

func getTestDataFile(t *testing.T, fileName string) string {
modulesPath := filepath.Join(".", "testdata", fileName)
content, err := os.ReadFile(modulesPath)
Expand Down
Loading