diff --git a/artifactory/utils/commandsummary/buildinfosummary.go b/artifactory/utils/commandsummary/buildinfosummary.go index 9861c723c..07bb7d35b 100644 --- a/artifactory/utils/commandsummary/buildinfosummary.go +++ b/artifactory/utils/commandsummary/buildinfosummary.go @@ -209,6 +209,9 @@ func (bis *BuildInfoSummary) createArtifactsTree(module *buildInfo.Module) strin } artifactTreePath := path.Join(artifact.OriginalDeploymentRepo, artifact.Path) artifactsTree.AddFile(artifactTreePath, artifactUrlInArtifactory) + if artifactsTree.IsTreeExceedsMax() { + return "" + } } return artifactsTree.String() } diff --git a/artifactory/utils/commandsummary/uploadsummary.go b/artifactory/utils/commandsummary/uploadsummary.go index 1aa683c36..cccaca2d8 100644 --- a/artifactory/utils/commandsummary/uploadsummary.go +++ b/artifactory/utils/commandsummary/uploadsummary.go @@ -55,6 +55,9 @@ func (us *UploadSummary) generateFileTreeMarkdown() string { us.uploadTree = utils.NewFileTree() for _, uploadResult := range us.uploadedArtifacts.Results { us.uploadTree.AddFile(uploadResult.TargetPath, us.buildUiUrl(uploadResult.TargetPath)) + if us.uploadTree.IsTreeExceedsMax() { + return "" + } } return us.uploadTree.String() } diff --git a/artifactory/utils/filetree.go b/artifactory/utils/filetree.go index 4b6ae17ff..fafd5c485 100644 --- a/artifactory/utils/filetree.go +++ b/artifactory/utils/filetree.go @@ -12,9 +12,8 @@ var maxFilesInTree = 200 // FileTree is a UI components that displays a file-system tree view in the terminal. type FileTree struct { - repos map[string]*dirNode - size int - exceedsMax bool + repos map[string]*dirNode + size int } func NewFileTree() *FileTree { @@ -25,11 +24,6 @@ func NewFileTree() *FileTree { // UploadedFileUrl - URL to the uploaded file in Artifactory, // if UploadedFileUrl not provided, the file name will be displayed without a link. func (ft *FileTree) AddFile(path, uploadedFileUrl string) { - if ft.size >= maxFilesInTree { - log.Info("Exceeded maximum number of files in tree") - ft.exceedsMax = true - return - } splitPath := strings.Split(path, "/") if _, exist := ft.repos[splitPath[0]]; !exist { ft.repos[splitPath[0]] = &dirNode{name: splitPath[0], prefix: "šŸ“¦ ", subDirNodes: map[string]*dirNode{}, fileNames: map[string]string{}} @@ -39,11 +33,16 @@ func (ft *FileTree) AddFile(path, uploadedFileUrl string) { } } +func (ft *FileTree) IsTreeExceedsMax() bool { + if ft.size >= maxFilesInTree { + log.Debug(fmt.Sprintf("Exceeded maximum number (%d) of files in files tree.", maxFilesInTree)) + return true + } + return false +} + // Returns a string representation of the tree. If the number of files exceeded the maximum, an empty string will be returned. func (ft *FileTree) String() string { - if ft.exceedsMax { - return "" - } treeStr := "" for _, repo := range ft.repos { treeStr += strings.Join(repo.strings(), "\n") + "\n\n" diff --git a/artifactory/utils/filetree_test.go b/artifactory/utils/filetree_test.go index eac646451..2a0e9dc8b 100644 --- a/artifactory/utils/filetree_test.go +++ b/artifactory/utils/filetree_test.go @@ -19,10 +19,8 @@ func TestFileTree(t *testing.T) { result, excpected := fileTree.String(), "šŸ“¦ repoName\nā””ā”€ā”€ šŸ“ path\n ā””ā”€ā”€ šŸ“ to\n ā””ā”€ā”€ šŸ“ first\n ā””ā”€ā”€ šŸ“„ artifact\n\n" assert.Equal(t, excpected, result) - // If maxFileInTree has exceeded, Check String() returns an empty string - fileTree.AddFile("repoName/path/to/second/artifact", "") - result, excpected = fileTree.String(), "" - assert.Equal(t, excpected, result) + // If maxFileInTree has exceeded + assert.True(t, fileTree.IsTreeExceedsMax()) } func TestFileTreeSort(t *testing.T) {