@@ -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
284287func 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}
0 commit comments