Skip to content

Commit

Permalink
Make command summary util available (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Sep 4, 2024
1 parent fbb08c4 commit 5e23772
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions artifactory/utils/commandsummary/commandsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ func (cs *CommandSummary) RecordWithIndex(data any, summaryIndex Index, args ...
}

// Retrieve all the indexed data files in the current command directory.
func (cs *CommandSummary) GetIndexedDataFilesPaths() (indexedFilePathsMap IndexedFilesMap, err error) {
func GetIndexedDataFilesPaths() (indexedFilePathsMap IndexedFilesMap, err error) {
basePath := filepath.Join(os.Getenv(coreutils.SummaryOutputDirPathEnv), OutputDirName)
return cs.getIndexedFileRecursively(basePath, true)
exists, err := fileutils.IsDirExists(basePath, false)
if err != nil || !exists {
return
}
return getIndexedFileRecursively(basePath, true)
}

func (cs *CommandSummary) GetDataFilesPaths() ([]string, error) {
Expand Down Expand Up @@ -178,7 +182,7 @@ func (cs *CommandSummary) saveMarkdownFile(markdown string) (err error) {
}

// Retrieve all the indexed data files paths in the given directory
func (cs *CommandSummary) getIndexedFileRecursively(dirPath string, isRoot bool) (nestedFilesMap IndexedFilesMap, err error) {
func getIndexedFileRecursively(dirPath string, isRoot bool) (nestedFilesMap IndexedFilesMap, err error) {
entries, err := os.ReadDir(dirPath)
if err != nil {
return nil, errorutils.CheckError(err)
Expand All @@ -190,7 +194,7 @@ func (cs *CommandSummary) getIndexedFileRecursively(dirPath string, isRoot bool)
// Check if the directory is in the allowedDirs list
_, allowed := allowedDirs[entry.Name()]
if isRoot || allowed {
subNestedFilesMap, err := cs.getIndexedFileRecursively(fullPath, false)
subNestedFilesMap, err := getIndexedFileRecursively(fullPath, false)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/utils/commandsummary/commandsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestIndexedRecord(t *testing.T) {
assert.NoError(t, err)

// Verify file has been saved
indexedFilesMap, err := cs.GetIndexedDataFilesPaths()
indexedFilesMap, err := GetIndexedDataFilesPaths()
assert.NoError(t, err)

// Verify nested files
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestSarifMultipleReports(t *testing.T) {
err = cs.RecordWithIndex(tc.originalData, tc.summaryIndex)
assert.NoError(t, err)
// Verify file has been saved
indexedFilesMap, err := cs.GetIndexedDataFilesPaths()
indexedFilesMap, err := GetIndexedDataFilesPaths()
assert.NoError(t, err)
assert.Equal(t, 2, len(indexedFilesMap[SarifReport]))
})
Expand Down

0 comments on commit 5e23772

Please sign in to comment.