Skip to content

Commit

Permalink
Display workspace content for debugging (#4839)
Browse files Browse the repository at this point in the history
* display workspace content for debugging

* adding verbose check

* renaming function
  • Loading branch information
vijayanjay authored Feb 22, 2024
1 parent 54426d1 commit 06e81ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ func detectExecuteScan(config detectExecuteScanOptions, _ *telemetry.CustomData,
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}

// Log config for debug purpose
logConfigInVerboseMode(config)
// Log config and workspace content for debug purpose
if log.IsVerbose() {
logConfigInVerboseMode(config)
logWorkspaceContent()
}

if config.PrivateModules != "" && config.PrivateModulesGitToken != "" {
//configuring go private packages
Expand Down
20 changes: 20 additions & 0 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package cmd

import (
"os"
"path/filepath"

"github.com/SAP/jenkins-library/pkg/log"
)

// Deprecated: Please use piperutils.Files{} instead
Expand All @@ -12,3 +15,20 @@ func fileExists(filename string) bool {
}
return !info.IsDir()
}

func logWorkspaceContent() {
currentDir, err := os.Getwd()
if err != nil {
log.Entry().Errorf("Error getting current directory: %v", err)
}
log.Entry().Debugf("Contents of Workspace:")
filepath.Walk(currentDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Entry().Errorf("Error parsing current directory: %v", err)
}
mode := info.Mode()
log.Entry().Debugf(" %s (%s)", path, mode)
return nil
})

}
3 changes: 3 additions & 0 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func whitesourceExecuteScan(config ScanOptions, _ *telemetry.CustomData, commonP
if err != nil {
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}
if log.IsVerbose() {
logWorkspaceContent()
}
utils := newWhitesourceUtils(&config, client)
scan := newWhitesourceScan(&config)
sys := ws.NewSystem(config.ServiceURL, config.OrgToken, config.UserToken, time.Duration(config.Timeout)*time.Second)
Expand Down
5 changes: 5 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func SetVerbose(verbose bool) {
}
}

// IsVerbose returns true if DegbuLevel is enabled.
func IsVerbose() bool {
return logrus.GetLevel() == logrus.DebugLevel
}

// SetFormatter specifies the log format to use for piper's output
func SetFormatter(logFormat string) {
Entry().Logger.SetFormatter(&PiperLogFormatter{logFormat: logFormat})
Expand Down

0 comments on commit 06e81ea

Please sign in to comment.