-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
26 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
runtimes: | ||
- [email protected] | ||
tools: | ||
- eslint@9.3.0 | ||
- eslint@8.57.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,13 @@ import ( | |
"codacy/cli-v2/tools" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// TODO change to prod??? | ||
|
@@ -28,7 +29,12 @@ var initCmd = &cobra.Command{ | |
Short: "Bootstraps project configuration", | ||
Long: "Bootstraps project configuration, creates codacy configuration file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := configurationFileSetup() | ||
apiTools, err := tools.GetTools() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = createConfigurationFile(apiTools) | ||
if len(codacyRepositoryToken) == 0 { | ||
fmt.Println("No project token was specified, skipping fetch configurations ") | ||
} else { | ||
|
@@ -45,45 +51,37 @@ var initCmd = &cobra.Command{ | |
}, | ||
} | ||
|
||
func configurationFileSetup() error { | ||
configFile, err := os.Open(config.Config.ProjectConfigFile()) | ||
defer configFile.Close() | ||
if err != nil { | ||
fmt.Println("Codacy cli configuration file was not found in", config.Config.LocalCodacyDirectory(), "- Creating file now.") | ||
err := createConfigurationFile() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} else { | ||
fmt.Println("Codacy cli configuration file was already present in ", config.Config.LocalCodacyDirectory()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func createConfigurationFile() error { | ||
func createConfigurationFile(tools []tools.Tool) error { | ||
|
||
configFile, err := os.Create(config.Config.ProjectConfigFile()) | ||
defer configFile.Close() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
_, err = configFile.WriteString(configFileTemplate()) | ||
_, err = configFile.WriteString(configFileTemplate(tools)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func configFileTemplate() string { | ||
return `runtimes: | ||
func configFileTemplate(tools []tools.Tool) string { | ||
|
||
var eslintVersion string | ||
|
||
for _, tool := range tools { | ||
if tool.Uuid == "f8b29663-2cb2-498d-b923-a10c6a8c05cd" { | ||
eslintVersion = tool.Version | ||
} | ||
} | ||
|
||
return fmt.Sprintf(`runtimes: | ||
- [email protected] | ||
tools: | ||
- eslint@9.3.0 | ||
` | ||
- eslint@%s | ||
`, eslintVersion) | ||
} | ||
|
||
func buildRepositoryConfigurationFiles(token string) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters