Skip to content

Commit

Permalink
Remove redundant log
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Oct 7, 2024
1 parent ba8bebc commit 3691e30
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions artifactory/utils/commandsummary/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func (bis *BuildInfoSummary) createArtifactsTree(module *buildInfo.Module) strin
}
artifactTreePath := path.Join(artifact.OriginalDeploymentRepo, artifact.Path)
artifactsTree.AddFile(artifactTreePath, artifactUrlInArtifactory)
if artifactsTree.IsTreeExceedsMax() {
log.Info("Exceeded maximum number of files in tree")
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
24 changes: 10 additions & 14 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,14 +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 {
if !ft.exceedsMax {
// Log only once
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 @@ -42,11 +33,16 @@ func (ft *FileTree) AddFile(path, uploadedFileUrl string) {
}
}

func (ft *FileTree) IsTreeExceedsMax() bool {
if ft.size >= maxFilesInTree {
log.Info(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

0 comments on commit 3691e30

Please sign in to comment.