Skip to content

[on hold] Feature: Add config discovery command [PLUTO-1429] #134

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

Closed
wants to merge 6 commits into from

Conversation

andrzej-janczak
Copy link
Contributor

@andrzej-janczak andrzej-janczak commented May 28, 2025

Breaking Changes
⚠️
Breaking changes is going be for local mode when not all tools will be added to codacy config file by default.
From now for local mode only relevant tools will be added.
⚠️

This pull request introduces significant enhancements to the Codacy CLI, focusing on language detection, dynamic tool configuration, and test improvements. The most notable changes include the addition of a language detection feature, dynamic enabling of tools based on detected languages, and updates to test cases to validate these new functionalities.

Language Detection and Dynamic Tool Configuration:

  • Language detection implementation: Added a new LanguageDetector class in utils/language_detector.go to scan project directories for programming languages based on file extensions and .gitignore rules. This enables dynamic configuration of tools based on detected languages.
  • Dynamic tool enabling: Updated cmd/init.go to dynamically enable tools based on detected languages, ensuring that relevant tools are configured for the project. Added support for always enabling Trivy and conditionally enabling Lizard for complexity analysis. [1] [2]
  • Tool configuration updates: Modified domain/tool.go to include a Languages field for tools, allowing tools to specify supported languages. Updated buildDefaultConfigurationFiles in cmd/init.go to create configuration files only for enabled tools. [1] [2]

Copy link

codacy-production bot commented May 28, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+5.44% 83.15%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3e978a2) 4541 1430 31.49%
Head commit (c3c235a) 4717 (+176) 1742 (+312) 36.93% (+5.44%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#134) 184 153 83.15%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@andrzej-janczak andrzej-janczak changed the title Feature: Local init files discovery Feature: Add config discovery command [PLUTO-1429] Jun 4, 2025
@andrzej-janczak andrzej-janczak changed the title Feature: Add config discovery command [PLUTO-1429] [on hold] Feature: Add config discovery command [PLUTO-1429] Jun 4, 2025
@alerizzo alerizzo requested a review from Copilot June 5, 2025 12:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Codacy CLI by adding automatic language detection and dynamic tool configuration for local mode, and updates related tests.

  • Introduces LanguageDetector to scan project files (respecting .gitignore) and map them to languages
  • Refactors init command to enable tools dynamically based on detected languages and always include security/complexity tools
  • Adds a Languages field to the Tool domain and updates default-config file generation and tests

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
utils/language_detector.go New LanguageDetector implementation with language & extension mappings
utils/language_detector_test.go Tests for initializing detector and verifying detection behavior
domain/tool.go Adds Languages []string field to Tool struct
cmd/init.go Refactors init command to detect languages and select tools
cmd/init_test.go Updates tests for local-mode init, covering language-based configs
go.mod Adds github.com/sabhiram/go-gitignore dependency
.cursor/rules/cursor.mdc Minor guideline updates in documentation
Comments suppressed due to low confidence (1)

.cursor/rules/cursor.mdc:14

  • Typo in 'permissons'; it should be 'permissions'.
 - look for constants like file permissons in `constants` folder 

Files: make([]string, 0),
}
for _, ext := range extensions {
d.extensionMap[ext] = name
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensions are stored without normalizing case, causing files like Dockerfile to be missed. Consider using strings.ToLower(ext) when populating and looking up extensionMap to ensure case-insensitive matching.

Suggested change
d.extensionMap[ext] = name
d.extensionMap[strings.ToLower(ext)] = name

Copilot uses AI. Check for mistakes.

Comment on lines +169 to +190
// toolNameFromUUID returns the short name for a tool UUID
func toolNameFromUUID(uuid string) string {
switch uuid {
case ESLint:
return "eslint"
case Trivy:
return "trivy"
case PyLint:
return "pylint"
case PMD:
return "pmd"
case DartAnalyzer:
return "dartanalyzer"
case Semgrep:
return "semgrep"
case Lizard:
return "lizard"
default:
return "unknown"
}
}

Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The toolNameFromUUID function is never called and can be removed to reduce dead code.

Suggested change
// toolNameFromUUID returns the short name for a tool UUID
func toolNameFromUUID(uuid string) string {
switch uuid {
case ESLint:
return "eslint"
case Trivy:
return "trivy"
case PyLint:
return "pylint"
case PMD:
return "pmd"
case DartAnalyzer:
return "dartanalyzer"
case Semgrep:
return "semgrep"
case Lizard:
return "lizard"
default:
return "unknown"
}
}

Copilot uses AI. Check for mistakes.

@@ -12,6 +12,7 @@ alwaysApply: true
- run go build after each code modification to see if app compiles
- remove dead unused code
- look for constants like file permissons in `constants` folder
- run go tests if you modified tests files
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Grammar issue: change 'tests files' to 'test files' for clarity.

Suggested change
- run go tests if you modified tests files
- run go tests if you modified test files

Copilot uses AI. Check for mistakes.

@andrzej-janczak
Copy link
Contributor Author

Discovery is implemented in #142

Running discovery during init is breaking changes and will be introduced in another PR

@andrzej-janczak andrzej-janczak deleted the local-init-discover branch June 6, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant