Skip to content

Commit c25cf44

Browse files
fixing tests and adding logs
1 parent ab92926 commit c25cf44

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cmd/analyze.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"codacy/cli-v2/tools"
1111
"codacy/cli-v2/tools/lizard"
1212
reviveTool "codacy/cli-v2/tools/revive"
13+
"codacy/cli-v2/utils/logger"
1314
"encoding/json"
1415
"fmt"
1516
"log"
@@ -21,6 +22,7 @@ import (
2122

2223
codacyclient "codacy/cli-v2/codacy-client"
2324

25+
"github.com/sirupsen/logrus"
2426
"github.com/spf13/cobra"
2527
"gopkg.in/yaml.v3"
2628
)
@@ -297,16 +299,29 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
297299
// Only show error if we're in remote mode and need the config file
298300
if (!cliLocalMode && initFlags.ApiToken != "") || cliLocalMode {
299301
fmt.Printf("Creating new config file for tool %s\n", toolName)
302+
// Ensure .gitignore exists to prevent config files from being analyzed
303+
if err := configsetup.CreateGitIgnoreFile(); err != nil {
304+
logger.Warn("Failed to create .gitignore file", logrus.Fields{
305+
"error": err,
306+
})
307+
}
300308
if err := configsetup.CreateToolConfigurationFile(toolName, initFlags); err != nil {
301309
return fmt.Errorf("failed to create config file for tool %s: %w", toolName, err)
302310
}
303311
} else {
304-
fmt.Printf("Config file not found for tool %s: %s and no API token provided\n", toolName, toolConfigPath)
312+
logger.Warn("Config file not found for tool", logrus.Fields{
313+
"tool": toolName,
314+
"toolConfigPath": toolConfigPath,
315+
"message": "No API token provided",
316+
})
305317
}
306318
} else if err != nil {
307319
return fmt.Errorf("error checking config file for tool %s: %w", toolName, err)
308320
} else {
309-
fmt.Printf("Config file found for %s: %s\n", toolName, toolConfigPath)
321+
logger.Info("Config file found for tool", logrus.Fields{
322+
"tool": toolName,
323+
"toolConfigPath": toolConfigPath,
324+
})
310325
}
311326
return nil
312327
}

cmd/configsetup/setup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ func createToolFileConfiguration(tool domain.Tool, patternConfiguration []domain
518518
}
519519

520520
toolsConfigDir := config.Config.ToolsConfigDirectory()
521+
522+
// Ensure the tools-configs directory exists
523+
if err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms); err != nil {
524+
return fmt.Errorf("failed to create tools-configs directory: %w", err)
525+
}
526+
521527
return creator.CreateConfig(toolsConfigDir, patternConfiguration)
522528
}
523529

0 commit comments

Comments
 (0)