Skip to content

Commit ceade58

Browse files
committed
Create cli configuration file PLUTO-1377
Also drops support for codacy.yml, as we control and create that file we pick the extension .yaml for our yaml files
1 parent 5b319ed commit ceade58

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

.codacy/cli-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mode: local

cmd/init.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ var initCmd = &cobra.Command{
3232

3333
config.Config.CreateLocalCodacyDir()
3434

35-
if len(codacyRepositoryToken) == 0 {
35+
cliLocalMode := len(codacyRepositoryToken) == 0
36+
37+
if cliLocalMode {
3638
fmt.Println()
3739
fmt.Println("ℹ️ No project token was specified, skipping fetch configurations")
3840
noTools := []tools.Tool{}
39-
err := createConfigurationFile(noTools)
41+
err := createConfigurationFiles(noTools, cliLocalMode)
4042
if err != nil {
4143
log.Fatal(err)
4244
}
@@ -45,7 +47,7 @@ var initCmd = &cobra.Command{
4547
if err != nil {
4648
log.Fatal(err)
4749
}
48-
err = createConfigurationFile(apiTools)
50+
err = createConfigurationFiles(apiTools, cliLocalMode)
4951
if err != nil {
5052
log.Fatal(err)
5153
}
@@ -64,7 +66,7 @@ var initCmd = &cobra.Command{
6466
},
6567
}
6668

67-
func createConfigurationFile(tools []tools.Tool) error {
69+
func createConfigurationFiles(tools []tools.Tool, cliLocalMode bool) error {
6870
configFile, err := os.Create(config.Config.ProjectConfigFile())
6971
defer configFile.Close()
7072
if err != nil {
@@ -76,6 +78,17 @@ func createConfigurationFile(tools []tools.Tool) error {
7678
log.Fatal(err)
7779
}
7880

81+
cliConfigFile, err := os.Create(config.Config.CliConfigFile())
82+
defer cliConfigFile.Close()
83+
if err != nil {
84+
log.Fatal(err)
85+
}
86+
87+
_, err = cliConfigFile.WriteString(cliConfigFileTemplate(cliLocalMode))
88+
if err != nil {
89+
log.Fatal(err)
90+
}
91+
7992
return nil
8093
}
8194

@@ -113,9 +126,21 @@ tools:
113126
`, eslintVersion, trivyVersion, pylintVersion, pmdVersion)
114127
}
115128

129+
func cliConfigFileTemplate(cliLocalMode bool) string {
130+
var cliModeString string
131+
132+
if cliLocalMode {
133+
cliModeString = "local"
134+
} else {
135+
cliModeString = "remote"
136+
}
137+
138+
return fmt.Sprintf(`mode: %s`, cliModeString)
139+
}
140+
116141
func buildRepositoryConfigurationFiles(token string) error {
117-
fmt.Println("Building project configuration files ...")
118-
fmt.Println("Fetching project configuration from codacy ...")
142+
fmt.Println("Building repository configuration files ...")
143+
fmt.Println("Fetching repository configuration from codacy ...")
119144

120145
// API call to fetch settings
121146
url := CodacyApiBase + "/2.0/project/analysis/configuration"

config/config.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ConfigType struct {
1616
toolsDirectory string
1717
localCodacyDirectory string
1818
projectConfigFile string
19+
cliConfigFile string
1920

2021
runtimes map[string]*plugins.RuntimeInfo
2122
tools map[string]*plugins.ToolInfo
@@ -45,6 +46,10 @@ func (c *ConfigType) ProjectConfigFile() string {
4546
return c.projectConfigFile
4647
}
4748

49+
func (c *ConfigType) CliConfigFile() string {
50+
return c.cliConfigFile
51+
}
52+
4853
func (c *ConfigType) Runtimes() map[string]*plugins.RuntimeInfo {
4954
return c.runtimes
5055
}
@@ -89,14 +94,8 @@ func (c *ConfigType) setupCodacyPaths() {
8994
c.toolsDirectory = filepath.Join(c.globalCacheDirectory, "tools")
9095
c.localCodacyDirectory = ".codacy"
9196

92-
yamlPath := filepath.Join(c.localCodacyDirectory, "codacy.yaml")
93-
ymlPath := filepath.Join(c.localCodacyDirectory, "codacy.yml")
94-
95-
if _, err := os.Stat(ymlPath); err == nil {
96-
c.projectConfigFile = ymlPath
97-
} else {
98-
c.projectConfigFile = yamlPath
99-
}
97+
c.projectConfigFile = filepath.Join(c.localCodacyDirectory, "codacy.yaml")
98+
c.cliConfigFile = filepath.Join(c.localCodacyDirectory, "cli-config.yaml")
10099
}
101100

102101
func (c *ConfigType) CreateCodacyDirs() error {

0 commit comments

Comments
 (0)