-
Notifications
You must be signed in to change notification settings - Fork 3
[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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e1ef85
wip: some test fails
andrzej-janczak faa791f
wip 2
andrzej-janczak 4962c8b
fix test
andrzej-janczak 91e0038
refactor: update initialization logic to use API for tool versions an…
andrzej-janczak 3a1f536
add files for it test
andrzej-janczak c3c235a
remove test for uuid map
andrzej-janczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,22 +47,97 @@ | |||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if cliLocalMode { | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println() | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println("ℹ️ No project token was specified, fetching codacy default configurations") | ||||||||||||||||||||||||||||||||||||||||||||
noTools := []domain.Tool{} | ||||||||||||||||||||||||||||||||||||||||||||
err := createConfigurationFiles(noTools, cliLocalMode) | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println("ℹ️ No project token was specified, detecting languages and configuring tools...") | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Create language detector and scan the project | ||||||||||||||||||||||||||||||||||||||||||||
detector := utils.NewLanguageDetector() | ||||||||||||||||||||||||||||||||||||||||||||
languages, err := detector.DetectLanguages(".") | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
log.Fatalf("Failed to detect languages: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Get all available tools from the API | ||||||||||||||||||||||||||||||||||||||||||||
availableTools, err := codacyclient.GetToolsVersions() | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
log.Fatalf("Failed to get tools versions: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Map tools by name for easier lookup | ||||||||||||||||||||||||||||||||||||||||||||
toolsByName := make(map[string]domain.Tool) | ||||||||||||||||||||||||||||||||||||||||||||
for _, tool := range availableTools { | ||||||||||||||||||||||||||||||||||||||||||||
toolsByName[strings.ToLower(tool.Name)] = tool | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Enable tools based on detected languages | ||||||||||||||||||||||||||||||||||||||||||||
var enabledTools []domain.Tool | ||||||||||||||||||||||||||||||||||||||||||||
toolsEnabled := make(map[string]bool) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Always enable Trivy for security scanning | ||||||||||||||||||||||||||||||||||||||||||||
if trivyTool, ok := toolsByName["trivy"]; ok { | ||||||||||||||||||||||||||||||||||||||||||||
enabledTools = append(enabledTools, trivyTool) | ||||||||||||||||||||||||||||||||||||||||||||
toolsEnabled[trivyTool.Uuid] = true | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Enable tools based on detected languages | ||||||||||||||||||||||||||||||||||||||||||||
for langName := range languages { | ||||||||||||||||||||||||||||||||||||||||||||
for _, tool := range availableTools { | ||||||||||||||||||||||||||||||||||||||||||||
if !toolsEnabled[tool.Uuid] { | ||||||||||||||||||||||||||||||||||||||||||||
for _, supportedLang := range tool.Languages { | ||||||||||||||||||||||||||||||||||||||||||||
if strings.EqualFold(langName, supportedLang) { | ||||||||||||||||||||||||||||||||||||||||||||
enabledTools = append(enabledTools, tool) | ||||||||||||||||||||||||||||||||||||||||||||
toolsEnabled[tool.Uuid] = true | ||||||||||||||||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Always enable Lizard for complexity analysis if any supported language is detected | ||||||||||||||||||||||||||||||||||||||||||||
if shouldEnableLizard(languages) { | ||||||||||||||||||||||||||||||||||||||||||||
if lizardTool, ok := toolsByName["lizard"]; ok && !toolsEnabled[lizardTool.Uuid] { | ||||||||||||||||||||||||||||||||||||||||||||
enabledTools = append(enabledTools, lizardTool) | ||||||||||||||||||||||||||||||||||||||||||||
toolsEnabled[lizardTool.Uuid] = true | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Create configuration files | ||||||||||||||||||||||||||||||||||||||||||||
err = createConfigurationFiles(enabledTools, cliLocalMode) | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
log.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
// Create default configuration files | ||||||||||||||||||||||||||||||||||||||||||||
if err := buildDefaultConfigurationFiles(toolsConfigDir); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Create default configuration files for enabled tools | ||||||||||||||||||||||||||||||||||||||||||||
if err := buildDefaultConfigurationFiles(toolsConfigDir, enabledTools); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
log.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Print summary of detected languages and enabled tools | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println("\nDetected languages:") | ||||||||||||||||||||||||||||||||||||||||||||
for langName, info := range languages { | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Printf(" - %s (%d files)\n", langName, len(info.Files)) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
fmt.Println("\nEnabled tools:") | ||||||||||||||||||||||||||||||||||||||||||||
// Create a map of supported tool UUIDs for quick lookup | ||||||||||||||||||||||||||||||||||||||||||||
supportedTools := make(map[string]bool) | ||||||||||||||||||||||||||||||||||||||||||||
for _, uuid := range AvailableTools { | ||||||||||||||||||||||||||||||||||||||||||||
supportedTools[uuid] = true | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// Only show tools that are both enabled and supported by the CLI | ||||||||||||||||||||||||||||||||||||||||||||
for _, tool := range enabledTools { | ||||||||||||||||||||||||||||||||||||||||||||
if supportedTools[tool.Uuid] { | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Printf(" - %s@%s\n", tool.Name, tool.Version) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||
err := buildRepositoryConfigurationFiles(initFlags.ApiToken) | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
log.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
createGitIgnoreFile() | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println() | ||||||||||||||||||||||||||||||||||||||||||||
fmt.Println("✅ Successfully initialized Codacy configuration!") | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -74,6 +149,45 @@ | |||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// shouldEnableLizard checks if Lizard should be enabled based on detected languages | ||||||||||||||||||||||||||||||||||||||||||||
func shouldEnableLizard(languages map[string]*utils.LanguageInfo) bool { | ||||||||||||||||||||||||||||||||||||||||||||
lizardSupportedLangs := map[string]bool{ | ||||||||||||||||||||||||||||||||||||||||||||
"C": true, "C++": true, "Java": true, "C#": true, | ||||||||||||||||||||||||||||||||||||||||||||
"JavaScript": true, "TypeScript": true, "Python": true, | ||||||||||||||||||||||||||||||||||||||||||||
"Ruby": true, "PHP": true, "Scala": true, "Go": true, | ||||||||||||||||||||||||||||||||||||||||||||
"Rust": true, "Kotlin": true, "Swift": true, | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
for lang := range languages { | ||||||||||||||||||||||||||||||||||||||||||||
if lizardSupportedLangs[lang] { | ||||||||||||||||||||||||||||||||||||||||||||
return true | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
return false | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// 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" | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+169
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||
func createGitIgnoreFile() error { | ||||||||||||||||||||||||||||||||||||||||||||
gitIgnorePath := filepath.Join(config.Config.LocalCodacyDirectory(), ".gitignore") | ||||||||||||||||||||||||||||||||||||||||||||
gitIgnoreFile, err := os.Create(gitIgnorePath) | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -427,14 +541,14 @@ | |||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// buildDefaultConfigurationFiles creates default configuration files for all tools | ||||||||||||||||||||||||||||||||||||||||||||
func buildDefaultConfigurationFiles(toolsConfigDir string) error { | ||||||||||||||||||||||||||||||||||||||||||||
for _, tool := range AvailableTools { | ||||||||||||||||||||||||||||||||||||||||||||
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(initFlags, tool) | ||||||||||||||||||||||||||||||||||||||||||||
// buildDefaultConfigurationFiles creates default configuration files for enabled tools | ||||||||||||||||||||||||||||||||||||||||||||
func buildDefaultConfigurationFiles(toolsConfigDir string, enabledTools []domain.Tool) error { | ||||||||||||||||||||||||||||||||||||||||||||
for _, tool := range enabledTools { | ||||||||||||||||||||||||||||||||||||||||||||
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(initFlags, tool.Uuid) | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to get default tool patterns config: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
switch tool { | ||||||||||||||||||||||||||||||||||||||||||||
switch tool.Uuid { | ||||||||||||||||||||||||||||||||||||||||||||
case ESLint: | ||||||||||||||||||||||||||||||||||||||||||||
if err := tools.CreateEslintConfig(toolsConfigDir, patternsConfig); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to create eslint config file: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.