Skip to content

refactor: Replace hardcoded language config with API-based [PLUTO-1430]#155

Merged
andrzej-janczak merged 10 commits intomainfrom
feature/local-default-languages-config-creation-with-api
Jun 30, 2025
Merged

refactor: Replace hardcoded language config with API-based [PLUTO-1430]#155
andrzej-janczak merged 10 commits intomainfrom
feature/local-default-languages-config-creation-with-api

Conversation

@andrzej-janczak
Copy link
Copy Markdown
Contributor

@andrzej-janczak andrzej-janczak commented Jun 24, 2025

Replace hardcoded tool language mappings with API-driven configuration

🎯 Summary

This PR completely replaces hardcoded tool language mappings with dynamic API-driven configuration, ensuring that language configurations are always up-to-date and consistent across all CLI operations.

🔧 Key Changes

1. API-Driven Language Configuration

  • Removed hardcoded DefaultToolLanguageMap with 60+ lines of static mappings
  • Added dynamic API integration using:
    • /api/v3/tools - For tool-to-languages mapping
    • /api/v3/languages/tools - For language-to-extensions mapping
  • Enhanced domain.Tool struct with Languages []string field

2. Clean Remote vs Local Mode Separation

  • Remote Mode: Uses GetRepositoryLanguages as single source of truth
    • Shows only repository-detected languages and their extensions
    • No fallback logic or complex conditionals
  • Local Mode: Uses API data to show all supported tools
    • Comprehensive tool information from live API data
  • Removed special treatment for trivy and codacy-enigma-cli

3. Code Deduplication

  • Extracted shared logic into buildToolLanguageInfoFromAPI()
  • Eliminated ~80 lines of duplicated code between functions
  • Unified API calling patterns across the codebase

4. Enhanced Config Discovery

  • Updated GetDefaultToolLanguageMapping() to use API data
  • Improved tool detection accuracy (e.g., trivy now properly detected)
  • Maintained graceful fallback for API failures

📁 Files Modified

File Changes
tools/language_config.go Core refactoring: API integration, code deduplication
codacy-client/client.go New API endpoints: GetLanguageTools(), enhanced GetRepositoryTools()
cmd/configsetup/setup.go Improved remote mode detection and execution order
domain/tool.go Added Languages field for API response mapping
domain/language.go New domain models for language tools API
Integration test files Updated expected outputs to match API-driven behavior

🧪 Testing

  • Unit tests: All passing (go test ./...)
  • Integration tests: All scenarios pass (./integration-tests/run.sh)
    • init-without-token: Shows all 8 tools with complete API data
    • init-with-token: Shows 6 repository-specific tools with repository languages
    • config-discover: Improved tool detection (now includes trivy)

🎨 Behavior Changes

Before (Hardcoded)

# Remote mode - inconsistent "Multiple" languages
- name: trivy
  languages: [Multiple]
  extensions: []

# Local mode - static hardcoded languages
- name: lizard  
  languages: [C, CPP, Java, C#, ...]  # manually maintained

After (API-Driven)

# Remote mode - actual repository languages
- name: trivy
  languages: [JSON, Java, Javascript, Python]
  extensions: [.java, .js, .json, .py, ...]

# Local mode - live API data
- name: lizard
  languages: [C, CPP, CSharp, Erlang, ...]  # from API, always current

🚀 Benefits

  1. Always Up-to-Date: Language mappings automatically sync with API changes
  2. Repository-Accurate: Extensions based on actual detected languages
  3. Zero Maintenance: No manual updates to hardcoded mappings required
  4. Consistent: All parts of the system use the same API sources
  5. Cleaner Code: Eliminated duplication and complex fallback logic

🔄 Migration Notes

  • No Breaking Changes: All existing functionality preserved
  • API Dependency: Now requires API access for language configuration
  • Fallback: Graceful error handling when API is unavailable
  • Performance: Cached API calls reduce redundant requests

📊 Code Changes Summary


Commit message:

feature: Replace hardcoded tool language mappings with API-driven configuration

  • Remove static DefaultToolLanguageMap with 60+ hardcoded entries
  • Integrate /api/v3/tools and /api/v3/languages/tools APIs
  • Separate remote/local mode logic for cleaner architecture
  • Eliminate code duplication between API functions
  • Enhance repository language detection for remote mode
  • Remove special treatment for trivy and codacy-enigma-cli
  • Update all integration tests to match API-driven behavior

BREAKING: Language configurations now require API access
BENEFIT: Always up-to-date mappings, no manual maintenance needed

Closes: PLUTO-1430

…ading

- Add GetLanguageTools() API client for /api/v3/languages/tools
- Replace embedded YAML with BuildLanguagesConfigFromAPI()
- Clean tool-to-API-language mapping instead of complex switch logic
- Update integration tests with richer API-sourced extensions

Eliminates tech debt and provides dynamic file extension updates.
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Jun 24, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.10% 30.69%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (86a2cb2) 5415 1534 28.33%
Head commit (141c07b) 5541 (+126) 1564 (+30) 28.23% (-0.10%)

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 (#155) 202 62 30.69%

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

- name: lizard
languages: [C, CPP, Java, C#, JavaScript, TypeScript, VueJS, Objective-C, Swift, Python, Ruby, TTCN-3, PHP, Scala, GDScript, Golang, Lua, Rust, Fortran, Kotlin, Solidity, Erlang, Zig, Perl]
extensions: [.c, .cpp, .cc, .h, .hpp, .java, .cs, .js, .jsx, .ts, .tsx, .vue, .m, .swift, .py, .rb, .ttcn, .php, .scala, .gd, .go, .lua, .rs, .f, .f90, .kt, .sol, .erl, .zig, .pl]
languages: [C, CPP, CSharp, Erlang, Fortran, Go, Java, Javascript, Kotlin, Lua, Objective C, PHP, Python, Ruby, Rust, Scala, Solidity, Swift, TypeScript]
Copy link
Copy Markdown
Contributor Author

@andrzej-janczak andrzej-janczak Jun 25, 2025

Choose a reason for hiding this comment

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

Need to sort for it test consistency.
Also It looks better visually btw 😉

Also sorts keys - tool name

- Added support for Trivy in the tool language mapping.
- Updated GetToolLanguageMappingFromAPI to dynamically fetch tool configurations from the public API.
- Improved error handling and logging for API failures.
- Refactored GetDefaultToolLanguageMapping to prioritize API data over hardcoded values.

This update streamlines the configuration process and ensures up-to-date tool language mappings.
@andrzej-janczak andrzej-janczak enabled auto-merge (squash) June 25, 2025 10:58
@andrzej-janczak andrzej-janczak disabled auto-merge June 25, 2025 10:59
@andrzej-janczak andrzej-janczak changed the title refactor: Replace hardcoded language config with API-based refactor: Replace hardcoded language config with API-based [PLUTO-1430] Jun 25, 2025
Copy link
Copy Markdown
Contributor

@franciscoovazevedo franciscoovazevedo left a comment

Choose a reason for hiding this comment

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

LGTM

@andrzej-janczak andrzej-janczak merged commit 66c17c5 into main Jun 30, 2025
10 checks passed
@andrzej-janczak andrzej-janczak deleted the feature/local-default-languages-config-creation-with-api branch June 30, 2025 08:00
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.

3 participants