Skip to content

feature: analyze with initFlags and fetch config file if non existent - PLUTO-1423 #153

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

franciscoovazevedo
Copy link
Contributor

@franciscoovazevedo franciscoovazevedo commented Jun 16, 2025

Add API Config Generation Support to Analyze Command

Summary

The analyze command now supports passing initFlags and can automatically generate tool configuration files from the Codacy API when running in remote mode, but only if configuration files do not already exist.

Changes

  • Enhanced analyze command: Now accepts API token and other init flags
  • Automatic config generation: When a tool lacks a config file and the CLI runs in remote mode with an API token, the system automatically fetches and creates the appropriate configuration from Codacy's API
  • Remote mode no longer fails: When running in remote mode, the analyze command will continue execution even when config files are missing, providing helpful guidance instead of failing

Behavior

  • Local mode: Shows helpful message to add config files manually
  • Remote mode without token: Shows config not found message
  • Remote mode with token: Automatically creates config files using Codacy API patterns and settings

Testing

Added comprehensive test coverage for all scenarios including edge cases, with tests properly isolated to avoid creating config files in the project directory.

Related

Jira ticket: PLUTO-1423

Copy link

codacy-production bot commented Jun 16, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.79% 53.85%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (dcd97cf) 5443 1426 26.20%
Head commit (1bb7db6) 5510 (+67) 1487 (+61) 26.99% (+0.79%)

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 (#153) 104 56 53.85%

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

@franciscoovazevedo franciscoovazevedo force-pushed the pluto-1423-init-flags-analyze branch from 47ce922 to 16a52f7 Compare June 16, 2025 17:57
@franciscoovazevedo franciscoovazevedo marked this pull request as ready for review June 16, 2025 18:05
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 analyze command to accept initialization flags, automatically generate missing tool config files from the Codacy API in remote mode, and adds unit and integration tests for the new behavior.

  • Analyze now supports initFlags (e.g. API token) and cloud mode flags.
  • Automatically fetches and writes tool config files when none exist and an API token is provided.
  • Adds coverage for local vs remote mode config checks in both unit and integration tests.

Reviewed Changes

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

Show a summary per file
File Description
tools/eslintConfigCreator.go Handle ESLint rules that don’t accept options by keeping only error level.
cmd/configsetup/setup.go Add CreateToolConfigurationFile and tool-name-to-UUID lookup.
cmd/analyze.go Wire in cloud flags, validate/generate config files, update runTool signature.
cmd/analyze_test.go Unit tests for checkIfConfigExistsAndIsNeeded behavior.
cmd/analyze_integration_test.go Integration tests for config existence and edge cases.
Comments suppressed due to low confidence (2)

cmd/configsetup/setup.go:512

  • [nitpick] Go style recommends capitalizing common acronyms: rename getToolUuidByName to getToolUUIDByName and use toolUUID for variable names.
func getToolUuidByName(toolName string) string {

cmd/analyze_test.go:283

  • There’s no assertion that a config file is actually created when running in remote mode with an API token. Add a test case or assertion after checkIfConfigExistsAndIsNeeded to verify the file exists at toolConfigFileName[toolName].
tests := []struct {

"no-useless-escape": true,
"no-with": true,
"require-yield": true,
}
Copy link
Contributor

@andrzej-janczak andrzej-janczak Jun 17, 2025

Choose a reason for hiding this comment

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

what's this ? 🤔
why moving eslint int this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was a bug on eslint config creation. this is the fix of that bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am definitely missing a context and knowledge here 😄the error was on main branch or where ?
Anyway I don't want to block, please make a fix in new PR next time 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since i was testing this scenario, when i created a new config file from API it generated this error:
Error: Key "rules": Key "no-misleading-character-class": Value [{"allowEscape":false}] should NOT have more than 0 items.
this is a fix for that. i can remove this code and add it in a different PR, but since it is happening in main i thought it could simply go in this one!

Copy link
Contributor

@andrzej-janczak andrzej-janczak Jun 18, 2025

Choose a reason for hiding this comment

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

sure, ok next time like I wrote ;)

@franciscoovazevedo franciscoovazevedo force-pushed the pluto-1423-init-flags-analyze branch from 2db4726 to f04aa4a Compare June 17, 2025 14:37
franciscoovazevedo and others added 2 commits June 17, 2025 16:43
* Refactor: Centralize tool configuration file names into constants

- Introduced a new constants package to store tool configuration file names, reducing duplication across the codebase.
- Updated references in the analyze and config setup files to use the new constants for improved maintainability.
- Adjusted tests to align with the new constants structure, ensuring consistency in tool configuration handling.

* fix test
} else if err != nil {
return fmt.Errorf("Error checking config file for tool %s: %w", toolName, err)
} else {
fmt.Printf("Config file found for %s: %s\n", toolName, toolConfigPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

[imporve]
This is normall situation, why print it for user ?
MAybe just file logger is enough

@andrzej-janczak
Copy link
Contributor

andrzej-janczak commented Jun 18, 2025

Overall ok but for local mode this scenario does not work:

  1. init (no flags)
  2. delete revive config
  3. analyze
  4. Revive config is not created. I just see: Config file not found for tool revive: .codacy/tools-configs/revive.toml. Please add a config file to the tools-configs directory

Expected:
Revice tool config should be created for local mode

Maybe it would be great idea to add it test for it...

@franciscoovazevedo
Copy link
Contributor Author

Overall ok but for local mode this scenario does not work:

  1. init (no flags)
  2. delete revive config
  3. analyze
  4. Revive config is not created. I just see: Config file not found for tool revive: .codacy/tools-configs/revive.toml. Please add a config file to the tools-configs directory

Expected: Revice tool config should be created for local mode

Maybe it would be great idea to add it test for it...

are we also fetching it in local mode? i thought this feature was only to remote. but sure, we can also cover that for local.

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.

2 participants