@@ -141,10 +141,11 @@ func configFileTemplate(tools []tools.Tool) string {
141141
142142 // Default versions
143143 defaultVersions := map [string ]string {
144- ESLint : "9.3.0" ,
145- Trivy : "0.59.1" ,
146- PyLint : "3.3.6" ,
147- PMD : "6.55.0" ,
144+ ESLint : "9.3.0" ,
145+ Trivy : "0.59.1" ,
146+ PyLint : "3.3.6" ,
147+ PMD : "6.55.0" ,
148+ Semgrep : "1.78.0" ,
148149 }
149150
150151 // Build map of enabled tools with their versions
@@ -188,10 +189,11 @@ func configFileTemplate(tools []tools.Tool) string {
188189 if len (tools ) > 0 {
189190 // Add only the tools that are in the API response (enabled tools)
190191 uuidToName := map [string ]string {
191- ESLint : "eslint" ,
192- Trivy : "trivy" ,
193- PyLint : "pylint" ,
194- PMD : "pmd" ,
192+ ESLint : "eslint" ,
193+ Trivy : "trivy" ,
194+ PyLint : "pylint" ,
195+ PMD : "pmd" ,
196+ Semgrep : "semgrep" ,
195197 }
196198
197199 for uuid , name := range uuidToName {
@@ -205,6 +207,7 @@ func configFileTemplate(tools []tools.Tool) string {
205207 sb .WriteString (fmt .Sprintf (" - trivy@%s\n " , defaultVersions [Trivy ]))
206208 sb .WriteString (fmt .Sprintf (" - pylint@%s\n " , defaultVersions [PyLint ]))
207209 sb .WriteString (fmt .Sprintf (" - pmd@%s\n " , defaultVersions [PMD ]))
210+ sb .WriteString (fmt .Sprintf (" - semgrep@%s\n " , defaultVersions [Semgrep ]))
208211 }
209212
210213 return sb .String ()
@@ -257,7 +260,8 @@ func buildRepositoryConfigurationFiles(token string) error {
257260
258261 // Only generate config files for tools not using their own config file
259262 for _ , tool := range configuredToolsWithUI {
260- url := fmt .Sprintf ("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools/%s/patterns?enabled=true" ,
263+
264+ url := fmt .Sprintf ("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools/%s/patterns?enabled=true&limit=1000" ,
261265 CodacyApiBase ,
262266 initFlags .provider ,
263267 initFlags .organization ,
@@ -380,6 +384,17 @@ func createToolFileConfigurations(tool tools.Tool, patternConfiguration []domain
380384 }
381385 }
382386 fmt .Println ("Pylint configuration created based on Codacy settings" )
387+ case Semgrep :
388+ if len (patternConfiguration ) > 0 {
389+ err := createSemgrepConfigFile (patternConfiguration , toolsConfigDir )
390+ if err != nil {
391+ return fmt .Errorf ("failed to create Semgrep config: %v" , err )
392+ }
393+ fmt .Println ("Semgrep configuration created based on Codacy settings" )
394+ } else {
395+ // In case of no patterns, we run semgrep with default config
396+ return nil
397+ }
383398 }
384399 return nil
385400}
@@ -434,6 +449,24 @@ func createDefaultEslintConfigFile(toolsConfigDir string) error {
434449 return os .WriteFile (filepath .Join (toolsConfigDir , "eslint.config.mjs" ), []byte (content ), utils .DefaultFilePerms )
435450}
436451
452+ // SemgrepRulesFile represents the structure of the rules.yaml file
453+ type SemgrepRulesFile struct {
454+ Rules []map [string ]interface {} `yaml:"rules"`
455+ }
456+
457+ // createSemgrepConfigFile creates a semgrep.yaml configuration file based on the API configuration
458+ func createSemgrepConfigFile (config []domain.PatternConfiguration , toolsConfigDir string ) error {
459+ // Use the refactored function from tools package
460+ configData , err := tools .GetSemgrepConfig (config )
461+
462+ if err != nil {
463+ return fmt .Errorf ("failed to create Semgrep config: %v" , err )
464+ }
465+
466+ // Write to file
467+ return os .WriteFile (filepath .Join (toolsConfigDir , "semgrep.yaml" ), configData , utils .DefaultFilePerms )
468+ }
469+
437470// cleanConfigDirectory removes all previous configuration files in the tools-configs directory
438471func cleanConfigDirectory (toolsConfigDir string ) error {
439472 // Check if directory exists
@@ -462,8 +495,9 @@ func cleanConfigDirectory(toolsConfigDir string) error {
462495}
463496
464497const (
465- ESLint string = "f8b29663-2cb2-498d-b923-a10c6a8c05cd"
466- Trivy string = "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb"
467- PMD string = "9ed24812-b6ee-4a58-9004-0ed183c45b8f"
468- PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
498+ ESLint string = "f8b29663-2cb2-498d-b923-a10c6a8c05cd"
499+ Trivy string = "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb"
500+ PMD string = "9ed24812-b6ee-4a58-9004-0ed183c45b8f"
501+ PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
502+ Semgrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
469503)
0 commit comments