Skip to content

Commit 7f5c327

Browse files
fixing tests and adding logs
1 parent ab92926 commit 7f5c327

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

cmd/analyze.go

Lines changed: 20 additions & 3 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
)
@@ -281,6 +283,7 @@ func validateToolName(toolName string) error {
281283
return nil
282284
}
283285

286+
// checkIfConfigExistsAndIsNeeded validates if a tool has config file and creates one if needed
284287
func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
285288
configFileName := constants.ToolConfigFileNames[toolName]
286289
if configFileName == "" {
@@ -294,19 +297,33 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
294297

295298
// Check if the config file exists
296299
if _, err := os.Stat(toolConfigPath); os.IsNotExist(err) {
297-
// Only show error if we're in remote mode and need the config file
300+
// Config file does not exist - create it if we have the means to do so
298301
if (!cliLocalMode && initFlags.ApiToken != "") || cliLocalMode {
299302
fmt.Printf("Creating new config file for tool %s\n", toolName)
300303
if err := configsetup.CreateToolConfigurationFile(toolName, initFlags); err != nil {
301304
return fmt.Errorf("failed to create config file for tool %s: %w", toolName, err)
302305
}
306+
307+
// Ensure .gitignore exists FIRST to prevent config files from being analyzed
308+
if err := configsetup.CreateGitIgnoreFile(); err != nil {
309+
logger.Warn("Failed to create .gitignore file", logrus.Fields{
310+
"error": err,
311+
})
312+
}
303313
} else {
304-
fmt.Printf("Config file not found for tool %s: %s and no API token provided\n", toolName, toolConfigPath)
314+
logger.Debug("Config file not found for tool, using tool defaults", logrus.Fields{
315+
"tool": toolName,
316+
"toolConfigPath": toolConfigPath,
317+
"message": "No API token provided",
318+
})
305319
}
306320
} else if err != nil {
307321
return fmt.Errorf("error checking config file for tool %s: %w", toolName, err)
308322
} else {
309-
fmt.Printf("Config file found for %s: %s\n", toolName, toolConfigPath)
323+
logger.Info("Config file found for tool", logrus.Fields{
324+
"tool": toolName,
325+
"toolConfigPath": toolConfigPath,
326+
})
310327
}
311328
return nil
312329
}

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

tools/eslintRunner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory
3838
//When writing to file, use the output file option
3939
cmd.Args = append(cmd.Args, "-o", outputFile)
4040
}
41+
4142
if len(pathsToCheck) > 0 {
4243
cmd.Args = append(cmd.Args, pathsToCheck...)
4344
} else {

0 commit comments

Comments
 (0)