Files
gh-action-readme/internal/helpers/common.go
Ismo Vuorinen ce02d36929 feat: add comprehensive security scanning and EditorConfig integration
- Add govulncheck, Snyk, and Trivy vulnerability scanning
- Create security workflow for automated scanning on push/PR/schedule
- Add gitleaks for secrets detection and prevention
- Implement EditorConfig linting with eclint and editorconfig-checker
- Update Makefile with security and formatting targets
- Create SECURITY.md with vulnerability reporting guidelines
- Configure Dependabot for automated dependency updates
- Fix all EditorConfig violations across codebase
- Update Go version to 1.23.10 to address stdlib vulnerabilities
- Add tests for internal/helpers package (80% coverage)
- Remove deprecated functions and migrate to error-returning patterns
- Fix YAML indentation in test fixtures to resolve test failures
2025-08-03 20:12:18 +03:00

57 lines
1.5 KiB
Go

// Package helpers provides helper functions used across the application.
package helpers
import (
"fmt"
"os"
"github.com/ivuorinen/gh-action-readme/internal"
"github.com/ivuorinen/gh-action-readme/internal/git"
)
// GetCurrentDir gets current working directory with standardized error handling.
func GetCurrentDir() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("error getting current directory: %w", err)
}
return currentDir, nil
}
// SetupGeneratorContext creates a generator with proper setup and current directory.
func SetupGeneratorContext(config *internal.AppConfig) (*internal.Generator, string, error) {
generator := internal.NewGenerator(config)
output := generator.Output
if config.Verbose {
output.Info("Using config: %+v", config)
}
currentDir, err := GetCurrentDir()
if err != nil {
return nil, "", err
}
return generator, currentDir, nil
}
// FindGitRepoRoot finds git repository root with standardized error handling.
func FindGitRepoRoot(currentDir string) string {
repoRoot, _ := git.FindRepositoryRoot(currentDir)
return repoRoot
}
// GetGitRepoRootAndInfo gets git repository root and info with error handling.
func GetGitRepoRootAndInfo(startPath string) (string, *git.RepoInfo, error) {
repoRoot, err := git.FindRepositoryRoot(startPath)
if err != nil {
return "", nil, err
}
gitInfo, err := git.DetectRepository(repoRoot)
if err != nil {
return repoRoot, nil, err
}
return repoRoot, gitInfo, nil
}