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