Skip to content

Commit 0aaef40

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 58327d1 commit 0aaef40

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

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

6971
configFile, err := os.Create(config.Config.ProjectConfigFile())
7072
defer configFile.Close()
@@ -77,6 +79,17 @@ func createConfigurationFile(tools []tools.Tool) error {
7779
log.Fatal(err)
7880
}
7981

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

@@ -110,10 +123,22 @@ tools:
110123
`, eslintVersion, trivyVersion, pylintVersion, pmdVersion)
111124
}
112125

126+
func cliConfigFileTemplate(cliLocalMode bool) string {
127+
var cliModeString string
128+
129+
if cliLocalMode {
130+
cliModeString = "local"
131+
} else {
132+
cliModeString = "remote"
133+
}
134+
135+
return fmt.Sprintf(`mode: %s`, cliModeString)
136+
}
137+
113138
func buildRepositoryConfigurationFiles(token string) error {
114139

115-
fmt.Println("Building project configuration files ...")
116-
fmt.Println("Fetching project configuration from codacy ...")
140+
fmt.Println("Building repository configuration files ...")
141+
fmt.Println("Fetching repository configuration from codacy ...")
117142

118143
// API call to fetch settings
119144
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)