Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codacy/codacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tools:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ codacy-cli

#Ignore cursor AI rules
.cursor/rules/codacy.mdc

#Macos
.DS_Store
11 changes: 11 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ func runDartAnalyzer(workDirectory string, pathsToCheck []string, outputFile str
return tools.RunDartAnalyzer(workDirectory, dartanalyzer.InstallDir, dartanalyzer.Binaries["dart"], pathsToCheck, outputFile, outputFormat)
}

func runSemgrepAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error {
semgrep := config.Config.Tools()["semgrep"]
if semgrep == nil {
log.Fatal("Semgrep tool configuration not found")
}

return tools.RunSemgrep(workDirectory, semgrep, pathsToCheck, outputFile, outputFormat)
}

var analyzeCmd = &cobra.Command{
Use: "analyze",
Short: "Runs all configured linters.",
Expand Down Expand Up @@ -312,6 +321,8 @@ func runTool(workDirectory string, toolName string, args []string, outputFile st
return runPmdAnalysis(workDirectory, args, outputFile, outputFormat)
case "pylint":
return runPylintAnalysis(workDirectory, args, outputFile, outputFormat)
case "semgrep":
return runSemgrepAnalysis(workDirectory, args, outputFile, outputFormat)
case "dartanalyzer":
return runDartAnalyzer(workDirectory, args, outputFile, outputFormat)
default:
Expand Down
32 changes: 31 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func configFileTemplate(tools []tools.Tool) string {
PyLint: "3.3.6",
PMD: "6.55.0",
DartAnalyzer: "3.7.2",
Semgrep: "1.78.0",
}

// Build map of enabled tools with their versions
Expand Down Expand Up @@ -200,6 +201,7 @@ func configFileTemplate(tools []tools.Tool) string {
PyLint: "pylint",
PMD: "pmd",
DartAnalyzer: "dartanalyzer",
Semgrep: "semgrep",
}

for uuid, name := range uuidToName {
Expand All @@ -214,6 +216,7 @@ func configFileTemplate(tools []tools.Tool) string {
sb.WriteString(fmt.Sprintf(" - pylint@%s\n", defaultVersions[PyLint]))
sb.WriteString(fmt.Sprintf(" - pmd@%s\n", defaultVersions[PMD]))
sb.WriteString(fmt.Sprintf(" - dartanalyzer@%s\n", defaultVersions[DartAnalyzer]))
sb.WriteString(fmt.Sprintf(" - semgrep@%s\n", defaultVersions[Semgrep]))
}

return sb.String()
Expand Down Expand Up @@ -266,7 +269,8 @@ func buildRepositoryConfigurationFiles(token string) error {

// Only generate config files for tools not using their own config file
for _, tool := range configuredToolsWithUI {
url := fmt.Sprintf("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools/%s/patterns?enabled=true",

url := fmt.Sprintf("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools/%s/patterns?enabled=true&limit=1000",
CodacyApiBase,
initFlags.provider,
initFlags.organization,
Expand Down Expand Up @@ -396,6 +400,13 @@ func createToolFileConfigurations(tool tools.Tool, patternConfiguration []domain
return fmt.Errorf("failed to create Dart Analyzer config: %v", err)
}
}
case Semgrep:
if len(patternConfiguration) > 0 {
err := createSemgrepConfigFile(patternConfiguration, toolsConfigDir)
if err != nil {
return fmt.Errorf("failed to create Semgrep config: %v", err)
}
}
}
return nil
}
Expand Down Expand Up @@ -456,6 +467,24 @@ func createDefaultEslintConfigFile(toolsConfigDir string) error {
return os.WriteFile(filepath.Join(toolsConfigDir, "eslint.config.mjs"), []byte(content), utils.DefaultFilePerms)
}

// SemgrepRulesFile represents the structure of the rules.yaml file
type SemgrepRulesFile struct {
Rules []map[string]interface{} `yaml:"rules"`
}

// createSemgrepConfigFile creates a semgrep.yaml configuration file based on the API configuration
func createSemgrepConfigFile(config []domain.PatternConfiguration, toolsConfigDir string) error {
// Use the refactored function from tools package
configData, err := tools.GetSemgrepConfig(config)

if err != nil {
return fmt.Errorf("failed to create Semgrep config: %v", err)
}

// Write to file
return os.WriteFile(filepath.Join(toolsConfigDir, "semgrep.yaml"), configData, utils.DefaultFilePerms)
}

// cleanConfigDirectory removes all previous configuration files in the tools-configs directory
func cleanConfigDirectory(toolsConfigDir string) error {
// Check if directory exists
Expand Down Expand Up @@ -489,4 +518,5 @@ const (
PMD string = "9ed24812-b6ee-4a58-9004-0ed183c45b8f"
PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
DartAnalyzer string = "d203d615-6cf1-41f9-be5f-e2f660f7850f"
Semgrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
)
16 changes: 13 additions & 3 deletions domain/patternConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ type ParameterConfiguration struct {
}

type PatternDefinition struct {
Id string `json:"id"`
Category string `json:"category"`
Level string `json:"level"`
Id string `json:"id"`
Category string `json:"category"`
Level string `json:"level"`
SeverityLevel string `json:"severityLevel"`
Enabled bool `json:"enabled"`
Parameters []ParameterConfiguration `json:"parameters"`
Title string `json:"title"`
Description string `json:"description"`
Explanation string `json:"explanation"`
Languages []string `json:"languages"`
TimeToFix int `json:"timeToFix"`
}

type PatternConfiguration struct {
PatternDefinition PatternDefinition `json:"patternDefinition"`
Parameters []ParameterConfiguration
Enabled bool `json:"enabled"`
IsCustom bool `json:"isCustom"`
}
1 change: 1 addition & 0 deletions plugins/tool-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func TestGetSupportedTools(t *testing.T) {
"pylint",
"trivy",
"dartanalyzer",
"semgrep",
},
expectedError: false,
},
Expand Down
16 changes: 16 additions & 0 deletions plugins/tools/semgrep/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: semgrep
description: Static Analysis Security Testing (SAST) tool
runtime: python
runtime_binaries:
package_manager: python3
execution: python3
binaries:
- name: python
path: "venv/bin/python3"
formatters:
- name: json
flag: "--json"
output_options:
file_flag: "--output"
analysis_options:
default_path: "."
Loading
Loading