Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/plugins"
"codacy/cli-v2/tools"
Expand Down Expand Up @@ -464,7 +465,7 @@ var analyzeCmd = &cobra.Command{

if outputFile != "" {
// Write filtered SARIF to output file
os.WriteFile(outputFile, filteredData, utils.DefaultFilePerms)
os.WriteFile(outputFile, filteredData, constants.DefaultFilePerms)
} else {
// Print the filtered SARIF output
fmt.Println(string(filteredData))
Expand Down
12 changes: 6 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"codacy/cli-v2/cmd/configsetup"
codacyclient "codacy/cli-v2/codacy-client"
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/plugins"
"codacy/cli-v2/tools"
"codacy/cli-v2/utils"
"codacy/cli-v2/utils/logger"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -101,7 +101,7 @@ func runConfigResetLogic(cmd *cobra.Command, args []string, flags domain.InitFla

// Create .codacy/tools-configs directory
toolsConfigDir := config.Config.ToolsConfigDirectory()
if err := os.MkdirAll(toolsConfigDir, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms); err != nil {
log.Fatalf("Failed to create tools-configs directory: %v", err)
}

Expand Down Expand Up @@ -267,10 +267,10 @@ func updateLanguagesConfigForTools(detectedTools map[string]struct{}, toolsConfi
if err != nil {
return fmt.Errorf("failed to marshal languages-config.yaml: %w", err)
}
if err := os.MkdirAll(toolsConfigDir, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create tools-configs directory: %w", err)
}
return os.WriteFile(langConfigPath, data, utils.DefaultFilePerms)
return os.WriteFile(langConfigPath, data, constants.DefaultFilePerms)
}

// updateCodacyYAMLForTools updates the codacy.yaml file with detected tools.
Expand Down Expand Up @@ -430,11 +430,11 @@ func updateCodacyYAMLForTools(detectedTools map[string]struct{}, codacyYAMLPath
return fmt.Errorf("error marshaling %s: %w", codacyYAMLPath, err)
}
// Ensure directory exists
if err := os.MkdirAll(filepath.Dir(codacyYAMLPath), utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(filepath.Dir(codacyYAMLPath), constants.DefaultDirPerms); err != nil {
return fmt.Errorf("error creating .codacy directory: %w", err)
}

return os.WriteFile(codacyYAMLPath, yamlData, utils.DefaultFilePerms)
return os.WriteFile(codacyYAMLPath, yamlData, constants.DefaultFilePerms)
}

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"path/filepath"
"testing"

"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/utils"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestUpdateCodacyYAMLForTools_NewFile(t *testing.T) {
}
yamlData, err := yaml.Marshal(initialConfig)
assert.NoError(t, err)
err = os.WriteFile(codacyYAMLPath, yamlData, utils.DefaultFilePerms)
err = os.WriteFile(codacyYAMLPath, yamlData, constants.DefaultFilePerms)
assert.NoError(t, err)

// Mock detected tools
Expand Down
3 changes: 1 addition & 2 deletions cmd/configsetup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"codacy/cli-v2/tools/lizard"
"codacy/cli-v2/tools/pylint"
reviveTool "codacy/cli-v2/tools/revive"
"codacy/cli-v2/utils"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -524,7 +523,7 @@ func CleanConfigDirectory(toolsConfigDir string) error {

func createReviveConfigFile(config []domain.PatternConfiguration, toolsConfigDir string) error {
reviveConfigurationString := reviveTool.GenerateReviveConfig(config)
return os.WriteFile(filepath.Join(toolsConfigDir, "revive.toml"), []byte(reviveConfigurationString), utils.DefaultFilePerms)
return os.WriteFile(filepath.Join(toolsConfigDir, "revive.toml"), []byte(reviveConfigurationString), constants.DefaultFilePerms)
}

// BuildDefaultConfigurationFiles creates default configuration files for all tools
Expand Down
6 changes: 3 additions & 3 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"codacy/cli-v2/cmd/configsetup"
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/utils"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestCleanConfigDirectory(t *testing.T) {

for _, file := range testFiles {
filePath := filepath.Join(tempDir, file)
err := os.WriteFile(filePath, []byte("test content"), utils.DefaultFilePerms)
err := os.WriteFile(filePath, []byte("test content"), constants.DefaultFilePerms)
assert.NoError(t, err, "Failed to create test file: %s", filePath)
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestInitCommand_NoToken(t *testing.T) {
}

toolsConfigDir := config.Config.ToolsConfigDirectory()
if err := os.MkdirAll(toolsConfigDir, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms); err != nil {
t.Fatalf("Failed to create tools-configs directory: %v", err)
}

Expand Down
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"path/filepath"
"strings"

"codacy/cli-v2/constants"
"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"

"gopkg.in/yaml.v3" // Added import for YAML parsing
)
Expand Down Expand Up @@ -115,11 +115,11 @@ func (c *ConfigType) writeConfig(codacyPath string, config map[string]interface{
}

// Ensure directory exists
if err := os.MkdirAll(filepath.Dir(codacyPath), utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(filepath.Dir(codacyPath), constants.DefaultDirPerms); err != nil {
return fmt.Errorf("error creating .codacy directory: %w", err)
}

if err := os.WriteFile(codacyPath, yamlData, utils.DefaultFilePerms); err != nil {
if err := os.WriteFile(codacyPath, yamlData, constants.DefaultFilePerms); err != nil {
return fmt.Errorf("error writing codacy.yaml: %w", err)
}

Expand Down Expand Up @@ -325,22 +325,22 @@ func setupGlobalConfig(repositoryDirectory string, repositoryCache string, globa
}

func (c *ConfigType) CreateCodacyDirs() error {
if err := os.MkdirAll(c.globalCacheDirectory, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(c.globalCacheDirectory, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create codacy directory: %w", err)
}

if err := os.MkdirAll(c.runtimesDirectory, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(c.runtimesDirectory, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create runtimes directory: %w", err)
}

if err := os.MkdirAll(c.toolsDirectory, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(c.toolsDirectory, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create tools directory: %w", err)
}
return nil
}

func (c *ConfigType) CreateLocalCodacyDir() error {
if err := os.MkdirAll(c.localCodacyDirectory, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(c.localCodacyDirectory, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create local codacy directory: %w", err)
}
return nil
Expand Down
5 changes: 3 additions & 2 deletions config/runtimes-installer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"codacy/cli-v2/constants"
"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"
"codacy/cli-v2/utils/logger"
Expand Down Expand Up @@ -78,7 +79,7 @@ func InstallRuntime(name string, runtimeInfo *plugins.RuntimeInfo) error {
func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
// Ensure the runtimes directory exists
runtimesDir := Config.RuntimesDirectory()
if err := os.MkdirAll(runtimesDir, utils.DefaultDirPerms); err != nil {
if err := os.MkdirAll(runtimesDir, constants.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create runtimes directory: %w", err)
}

Expand Down Expand Up @@ -137,7 +138,7 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {

// Ensure binaries have executable permissions
for binaryName, fullPath := range runtimeInfo.Binaries {
if err := os.Chmod(fullPath, utils.DefaultDirPerms); err != nil {
if err := os.Chmod(fullPath, constants.DefaultDirPerms); err != nil {
logger.Debug("Failed to set binary permissions", logrus.Fields{
"binary": binaryName,
"path": fullPath,
Expand Down
4 changes: 2 additions & 2 deletions config/runtimes-installer_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

import (
"codacy/cli-v2/constants"
"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"
"os"
"path/filepath"
"testing"
Expand All @@ -27,7 +27,7 @@ func TestIsRuntimeInstalled(t *testing.T) {
assert.False(t, Config.IsRuntimeInstalled("test-runtime", runtimeInfoNoBinaries))

// Create the install directory
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, utils.DefaultDirPerms)
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, constants.DefaultDirPerms)
assert.NoError(t, err)

// Test when the install directory exists
Expand Down
7 changes: 4 additions & 3 deletions config/tools-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"bytes"
"codacy/cli-v2/constants"
"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"
"codacy/cli-v2/utils/logger"
Expand Down Expand Up @@ -102,7 +103,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
}

// Make sure the installation directory exists
err := os.MkdirAll(toolInfo.InstallDir, 0755)
err := os.MkdirAll(toolInfo.InstallDir, constants.DefaultDirPerms)
if err != nil {
return fmt.Errorf("failed to create installation directory: %w", err)
}
Expand Down Expand Up @@ -291,7 +292,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
defer file.Close()

// Create the installation directory
err = os.MkdirAll(toolInfo.InstallDir, 0755)
err = os.MkdirAll(toolInfo.InstallDir, constants.DefaultDirPerms)
if err != nil {
return fmt.Errorf("failed to create installation directory: %w", err)
}
Expand All @@ -316,7 +317,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {

// Make sure all binaries are executable
for _, binaryPath := range toolInfo.Binaries {
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), 0755)
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), constants.DefaultDirPerms)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to make binary executable: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion tools/dartanalyzerRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tools
import (
"bufio"
"bytes"
"codacy/cli-v2/constants"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -121,7 +122,7 @@ func RunDartAnalyzer(workDirectory string, installationDirectory string, binary
// Write SARIF output to file if specified
if outputFile != "" {
sarifJson, _ := json.MarshalIndent(sarif, "", " ")
err := os.WriteFile(outputFile, sarifJson, 0644)
err := os.WriteFile(outputFile, sarifJson, constants.DefaultFilePerms)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing SARIF output: %v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions tools/language_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

codacyclient "codacy/cli-v2/codacy-client"
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/utils"
"codacy/cli-v2/utils/logger"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -191,7 +191,7 @@ func CreateLanguagesConfigFile(apiTools []domain.Tool, toolsConfigDir string, to

// Write the file
configPath := filepath.Join(toolsConfigDir, "languages-config.yaml")
if err := os.WriteFile(configPath, data, utils.DefaultFilePerms); err != nil {
if err := os.WriteFile(configPath, data, constants.DefaultFilePerms); err != nil {
return fmt.Errorf("failed to write languages config file: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions tools/lizard/lizardConfigCreator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package lizard

import (
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/utils"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -50,7 +50,7 @@ func CreateLizardConfig(toolsConfigDir string, patterns []domain.PatternDefiniti
return fmt.Errorf("failed to marshal YAML: %w", err)
}

return os.WriteFile(filepath.Join(toolsConfigDir, "lizard.yaml"), yamlData, utils.DefaultFilePerms)
return os.WriteFile(filepath.Join(toolsConfigDir, "lizard.yaml"), yamlData, constants.DefaultFilePerms)
}

// getThresholdFromParams extracts the threshold value from the parameters
Expand Down
3 changes: 2 additions & 1 deletion tools/lizard/lizardRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lizard
import (
"bytes"
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/domain"
"codacy/cli-v2/tools"
"encoding/json"
Expand Down Expand Up @@ -84,7 +85,7 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s

// Write SARIF output to file if specified, else stdout
if outputFile != "" {
err = os.WriteFile(outputFile, sarifData, 0644)
err = os.WriteFile(outputFile, sarifData, constants.DefaultFilePerms)
if err != nil {
return fmt.Errorf("failed to write SARIF output: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion tools/pylintRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tools

import (
"codacy/cli-v2/config"
"codacy/cli-v2/constants"
"codacy/cli-v2/utils"
"fmt"
"os"
Expand Down Expand Up @@ -69,7 +70,7 @@ func RunPylint(workDirectory string, binary string, files []string, outputFile s
sarifOutput := utils.ConvertPylintToSarif(jsonOutput)

if outputFile != "" {
err = os.WriteFile(outputFile, sarifOutput, 0644)
err = os.WriteFile(outputFile, sarifOutput, constants.DefaultFilePerms)
if err != nil {
return fmt.Errorf("failed to write SARIF output: %w", err)
}
Expand Down
26 changes: 0 additions & 26 deletions utils/files.go

This file was deleted.