Skip to content

Commit 2cee52e

Browse files
committed
feat: Fix for already existing config CF-2275
If config does not exist in .codacy/tools-configs it will first check if the root of the project contains any configurations.
1 parent 5d0b1ca commit 2cee52e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cmd/analyze.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ var versionedToolNames = map[string]map[int]string{
272272
}
273273

274274
var simpleToolAliases = map[string]string{
275-
"lizard": "Lizard",
275+
"lizard": "Lizard",
276276
"opengrep": "Opengrep",
277-
"pylint": "pylintpython3",
278-
"trivy": "Trivy",
277+
"pylint": "pylintpython3",
278+
"trivy": "Trivy",
279279
}
280280

281281
func getToolName(toolName string, version string) string {
@@ -328,7 +328,7 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
328328

329329
// Check if the config file exists
330330
if _, err := os.Stat(toolConfigPath); os.IsNotExist(err) {
331-
// Config file does not exist - create it if we have the means to do so
331+
repoConfigPath := filepath.Join(config.Config.RepositoryDirectory(), configFileName)
332332
if (!cliLocalMode && initFlags.ApiToken != "") || cliLocalMode {
333333
if err := configsetup.CreateToolConfigurationFile(toolName, initFlags); err != nil {
334334
return fmt.Errorf("failed to create config file for tool %s: %w", toolName, err)
@@ -340,6 +340,13 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
340340
"error": err,
341341
})
342342
}
343+
} else if _, repoErr := os.Stat(repoConfigPath); repoErr == nil {
344+
// Config not in .codacy/tools-configs/ - check if it exists in the repo root
345+
logger.Info("Config file found in repository root for tool, skipping config creation", logrus.Fields{
346+
"tool": toolName,
347+
"toolConfigPath": repoConfigPath,
348+
})
349+
return nil
343350
} else {
344351
logger.Debug("Config file not found for tool, using tool defaults", logrus.Fields{
345352
"tool": toolName,

0 commit comments

Comments
 (0)