-
Notifications
You must be signed in to change notification settings - Fork 10
Pluto 1382 change tools configs location #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
09f2b7d
32902e5
08979c7
0c06807
3735b88
7c209a5
e0b95d2
6a1ed05
508e333
e0a09c4
ed8f3b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ runtimes: | |
| - [email protected] | ||
| - [email protected] | ||
| tools: | ||
| - eslint@9.3.0 | ||
| - eslint@8.57.0 | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| "log" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
@@ -142,6 +143,13 @@ | |
| fmt.Println("Building repository configuration files ...") | ||
| fmt.Println("Fetching repository configuration from codacy ...") | ||
|
|
||
| toolsConfigDir := config.Config.ToolsConfigDirectory() | ||
|
|
||
| // Create tools-configs directory if it doesn't exist | ||
| if err := os.MkdirAll(toolsConfigDir, 0777); err != nil { | ||
|
Check warning on line 149 in cmd/init.go
|
||
|
||
| return fmt.Errorf("failed to create tools-configs directory: %w", err) | ||
| } | ||
|
|
||
| // API call to fetch settings | ||
| url := CodacyApiBase + "/2.0/project/analysis/configuration" | ||
|
|
||
|
|
@@ -198,7 +206,7 @@ | |
| eslintDomainConfiguration := convertAPIToolConfigurationToDomain(*eslintApiConfiguration) | ||
| eslintConfigurationString := tools.CreateEslintConfig(eslintDomainConfiguration) | ||
|
|
||
| eslintConfigFile, err := os.Create("eslint.config.mjs") | ||
| eslintConfigFile, err := os.Create(filepath.Join(toolsConfigDir, "eslint.config.mjs")) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create eslint config file: %v", err) | ||
| } | ||
|
|
@@ -210,7 +218,7 @@ | |
| } | ||
| fmt.Println("ESLint configuration created based on Codacy settings") | ||
| } else { | ||
| err = createDefaultEslintConfigFile() | ||
| err = createDefaultEslintConfigFile(toolsConfigDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create default ESLint config: %v", err) | ||
| } | ||
|
|
@@ -220,13 +228,13 @@ | |
| // Trivy configuration | ||
| trivyApiConfiguration := extractTrivyConfiguration(apiToolConfigurations) | ||
| if trivyApiConfiguration != nil { | ||
| err = createTrivyConfigFile(*trivyApiConfiguration) | ||
| err = createTrivyConfigFile(*trivyApiConfiguration, toolsConfigDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create Trivy config: %v", err) | ||
| } | ||
| fmt.Println("Trivy configuration created based on Codacy settings") | ||
| } else { | ||
| err = createDefaultTrivyConfigFile() | ||
| err = createDefaultTrivyConfigFile(toolsConfigDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create default Trivy config: %v", err) | ||
| } | ||
|
|
@@ -236,13 +244,13 @@ | |
| // PMD configuration | ||
| pmdApiConfiguration := extractPMDConfiguration(apiToolConfigurations) | ||
| if pmdApiConfiguration != nil { | ||
| err = createPMDConfigFile(*pmdApiConfiguration) | ||
| err = createPMDConfigFile(*pmdApiConfiguration, toolsConfigDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create PMD config: %v", err) | ||
| } | ||
| fmt.Println("PMD configuration created based on Codacy settings") | ||
| } else { | ||
| err = createDefaultPMDConfigFile() | ||
| err = createDefaultPMDConfigFile(toolsConfigDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create default PMD config: %v", err) | ||
| } | ||
|
|
@@ -318,16 +326,16 @@ | |
| return nil | ||
| } | ||
|
|
||
| func createPMDConfigFile(config CodacyToolConfiguration) error { | ||
| func createPMDConfigFile(config CodacyToolConfiguration, toolsConfigDir string) error { | ||
| pmdDomainConfiguration := convertAPIToolConfigurationToDomain(config) | ||
| pmdConfigurationString := tools.CreatePmdConfig(pmdDomainConfiguration) | ||
| return os.WriteFile("pmd-ruleset.xml", []byte(pmdConfigurationString), 0644) | ||
| return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(pmdConfigurationString), 0644) | ||
| } | ||
|
|
||
| func createDefaultPMDConfigFile() error { | ||
| func createDefaultPMDConfigFile(toolsConfigDir string) error { | ||
| emptyConfig := tools.ToolConfiguration{} | ||
| content := tools.CreatePmdConfig(emptyConfig) | ||
| return os.WriteFile("pmd-ruleset.xml", []byte(content), 0644) | ||
| return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(content), 0644) | ||
| } | ||
|
|
||
| type CodacyToolConfiguration struct { | ||
|
|
@@ -347,15 +355,15 @@ | |
| } | ||
|
|
||
| // createTrivyConfigFile creates a trivy.yaml configuration file based on the API configuration | ||
| func createTrivyConfigFile(config CodacyToolConfiguration) error { | ||
| func createTrivyConfigFile(config CodacyToolConfiguration, toolsConfigDir string) error { | ||
| // Convert CodacyToolConfiguration to tools.ToolConfiguration | ||
| trivyDomainConfiguration := convertAPIToolConfigurationForTrivy(config) | ||
|
|
||
| // Use the shared CreateTrivyConfig function to generate the config content | ||
| trivyConfigurationString := tools.CreateTrivyConfig(trivyDomainConfiguration) | ||
|
|
||
| // Write to file | ||
| return os.WriteFile("trivy.yaml", []byte(trivyConfigurationString), 0644) | ||
| return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(trivyConfigurationString), 0644) | ||
| } | ||
|
|
||
| // convertAPIToolConfigurationForTrivy converts API tool configuration to domain model for Trivy | ||
|
|
@@ -399,21 +407,21 @@ | |
| } | ||
|
|
||
| // createDefaultTrivyConfigFile creates a default trivy.yaml configuration file | ||
| func createDefaultTrivyConfigFile() error { | ||
| func createDefaultTrivyConfigFile(toolsConfigDir string) error { | ||
| // Use empty tool configuration to get default settings | ||
| emptyConfig := tools.ToolConfiguration{} | ||
| content := tools.CreateTrivyConfig(emptyConfig) | ||
|
|
||
| // Write to file | ||
| return os.WriteFile("trivy.yaml", []byte(content), 0644) | ||
| return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(content), 0644) | ||
| } | ||
|
|
||
| // createDefaultEslintConfigFile creates a default eslint.config.mjs configuration file | ||
| func createDefaultEslintConfigFile() error { | ||
| func createDefaultEslintConfigFile(toolsConfigDir string) error { | ||
| // Use empty tool configuration to get default settings | ||
| emptyConfig := tools.ToolConfiguration{} | ||
| content := tools.CreateEslintConfig(emptyConfig) | ||
|
|
||
| // Write to file | ||
| return os.WriteFile("eslint.config.mjs", []byte(content), 0644) | ||
| return os.WriteFile(filepath.Join(toolsConfigDir, "eslint.config.mjs"), []byte(content), 0644) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,39 +3,52 @@ | |
| import ( | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| // RunPmd executes PMD static code analyzer with the specified options | ||
| // | ||
| // Parameters: | ||
| // - repositoryToAnalyseDirectory: The root directory of the repository to analyze | ||
| // - pmdBinary: Path to the PMD executable | ||
| // - pathsToCheck: List of specific paths to analyze, if empty analyzes whole repository | ||
| // - outputFile: Path where analysis results should be written | ||
| // - outputFormat: Format for the output (e.g. "sarif") | ||
| // - rulesetFile: Path to custom ruleset XML file, if empty uses default ruleset | ||
| // | ||
| // Returns: | ||
| // - error: nil if analysis succeeds or violations found, error otherwise | ||
| func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck []string, outputFile string, outputFormat string, rulesetFile string) error { | ||
| cmdArgs := []string{"pmd"} | ||
| cmd := exec.Command(pmdBinary, "pmd") | ||
|
Check failure on line 23 in tools/pmdRunner.go
|
||
andrzej-janczak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Add config file from tools-configs directory if not specified | ||
| if rulesetFile == "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that we pass always Meaning, instead of deciding this here, assuming that we were passing some kind of default, is to generate a file with the defaults as needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not always, in test I use a specific file and In this case it's ok. Generally, If in future we want to be able to pass smth like |
||
| configFile := filepath.Join(".codacy", "tools-configs", "pmd-ruleset.xml") | ||
andrzej-janczak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cmd.Args = append(cmd.Args, "-R", configFile) | ||
| } else { | ||
| cmd.Args = append(cmd.Args, "-R", rulesetFile) | ||
| } | ||
|
|
||
| // Add source directories (comma-separated list for PMD) | ||
| if len(pathsToCheck) > 0 { | ||
| dirArg := strings.Join(pathsToCheck, ",") | ||
| cmdArgs = append(cmdArgs, "-d", dirArg) | ||
| cmd.Args = append(cmd.Args, "-d", dirArg) | ||
| } else { | ||
| // Fall back to whole repo if no specific paths given | ||
| cmdArgs = append(cmdArgs, "-d", repositoryToAnalyseDirectory) | ||
| } | ||
|
|
||
| // Add ruleset | ||
| if rulesetFile != "" { | ||
| cmdArgs = append(cmdArgs, "-R", rulesetFile) | ||
| cmd.Args = append(cmd.Args, "-d", repositoryToAnalyseDirectory) | ||
| } | ||
|
|
||
| // Format | ||
| if outputFormat != "" { | ||
| cmdArgs = append(cmdArgs, "-f", outputFormat) | ||
| cmd.Args = append(cmd.Args, "-f", outputFormat) | ||
| } | ||
|
|
||
| // Output file | ||
| if outputFile != "" { | ||
| cmdArgs = append(cmdArgs, "-r", outputFile) | ||
| cmd.Args = append(cmd.Args, "-r", outputFile) | ||
| } | ||
|
|
||
| cmd := exec.Command(pmdBinary, cmdArgs...) | ||
|
|
||
| cmd.Dir = repositoryToAnalyseDirectory | ||
| cmd.Stderr = os.Stderr | ||
| cmd.Stdout = os.Stdout | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.