Skip to content

Commit

Permalink
Upload summery - log 'Exceeded maximum number of files in tree' only …
Browse files Browse the repository at this point in the history
…once (#1279)
  • Loading branch information
sverdlov93 authored Oct 8, 2024
1 parent 8b61ec2 commit c1cfd57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions artifactory/utils/commandsummary/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions artifactory/utils/commandsummary/uploadsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
21 changes: 10 additions & 11 deletions artifactory/utils/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}}
Expand All @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions artifactory/utils/filetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c1cfd57

Please sign in to comment.