mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-02-08 20:47:16 +00:00
chore: even more linting, test fixes (#24)
* chore(lint): funcorder * chore(lint): yamlfmt, ignored broken test yaml files * chore(tests): tests do not output garbage, add coverage * chore(lint): fix editorconfig violations * chore(lint): move from eclint to editorconfig-checker * chore(lint): add pre-commit, run and fix * chore(ci): we use renovate to manage updates
This commit is contained in:
@@ -55,6 +55,32 @@ func (e *ConfigExporter) ExportConfig(config *internal.AppConfig, format ExportF
|
||||
}
|
||||
}
|
||||
|
||||
// GetSupportedFormats returns the list of supported export formats.
|
||||
func (e *ConfigExporter) GetSupportedFormats() []ExportFormat {
|
||||
return []ExportFormat{FormatYAML, FormatJSON, FormatTOML}
|
||||
}
|
||||
|
||||
// GetDefaultOutputPath returns the default output path for a given format.
|
||||
func (e *ConfigExporter) GetDefaultOutputPath(format ExportFormat) (string, error) {
|
||||
configPath, err := internal.GetConfigPath()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get config directory: %w", err)
|
||||
}
|
||||
|
||||
dir := filepath.Dir(configPath)
|
||||
|
||||
switch format {
|
||||
case FormatYAML:
|
||||
return filepath.Join(dir, "config.yaml"), nil
|
||||
case FormatJSON:
|
||||
return filepath.Join(dir, "config.json"), nil
|
||||
case FormatTOML:
|
||||
return filepath.Join(dir, "config.toml"), nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported format: %s", format)
|
||||
}
|
||||
}
|
||||
|
||||
// exportYAML exports configuration as YAML.
|
||||
func (e *ConfigExporter) exportYAML(config *internal.AppConfig, outputPath string) error {
|
||||
// Create a clean config without sensitive data for export
|
||||
@@ -260,29 +286,3 @@ func (e *ConfigExporter) writeVariablesSection(file *os.File, config *internal.A
|
||||
_, _ = fmt.Fprintf(file, "%s = %q\n", key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// GetSupportedFormats returns the list of supported export formats.
|
||||
func (e *ConfigExporter) GetSupportedFormats() []ExportFormat {
|
||||
return []ExportFormat{FormatYAML, FormatJSON, FormatTOML}
|
||||
}
|
||||
|
||||
// GetDefaultOutputPath returns the default output path for a given format.
|
||||
func (e *ConfigExporter) GetDefaultOutputPath(format ExportFormat) (string, error) {
|
||||
configPath, err := internal.GetConfigPath()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get config directory: %w", err)
|
||||
}
|
||||
|
||||
dir := filepath.Dir(configPath)
|
||||
|
||||
switch format {
|
||||
case FormatYAML:
|
||||
return filepath.Join(dir, "config.yaml"), nil
|
||||
case FormatJSON:
|
||||
return filepath.Join(dir, "config.json"), nil
|
||||
case FormatTOML:
|
||||
return filepath.Join(dir, "config.toml"), nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported format: %s", format)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,33 @@ func (v *ConfigValidator) ValidateField(fieldName, value string) *ValidationResu
|
||||
return result
|
||||
}
|
||||
|
||||
// DisplayValidationResult displays validation results to the user.
|
||||
func (v *ConfigValidator) DisplayValidationResult(result *ValidationResult) {
|
||||
if result.Valid {
|
||||
v.output.Success("✅ Configuration is valid")
|
||||
} else {
|
||||
v.output.Error("❌ Configuration has errors")
|
||||
}
|
||||
|
||||
// Display errors
|
||||
for _, err := range result.Errors {
|
||||
v.output.Error(" • %s: %s (value: %s)", err.Field, err.Message, err.Value)
|
||||
}
|
||||
|
||||
// Display warnings
|
||||
for _, warning := range result.Warnings {
|
||||
v.output.Warning(" ⚠️ %s: %s", warning.Field, warning.Message)
|
||||
}
|
||||
|
||||
// Display suggestions
|
||||
if len(result.Suggestions) > 0 {
|
||||
v.output.Info("\nSuggestions:")
|
||||
for _, suggestion := range result.Suggestions {
|
||||
v.output.Printf(" 💡 %s", suggestion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// validateOrganization validates the organization field.
|
||||
func (v *ConfigValidator) validateOrganization(org string, result *ValidationResult) {
|
||||
if org == "" {
|
||||
@@ -478,30 +505,3 @@ func (v *ConfigValidator) isValidVariableName(name string) bool {
|
||||
|
||||
return matched
|
||||
}
|
||||
|
||||
// DisplayValidationResult displays validation results to the user.
|
||||
func (v *ConfigValidator) DisplayValidationResult(result *ValidationResult) {
|
||||
if result.Valid {
|
||||
v.output.Success("✅ Configuration is valid")
|
||||
} else {
|
||||
v.output.Error("❌ Configuration has errors")
|
||||
}
|
||||
|
||||
// Display errors
|
||||
for _, err := range result.Errors {
|
||||
v.output.Error(" • %s: %s (value: %s)", err.Field, err.Message, err.Value)
|
||||
}
|
||||
|
||||
// Display warnings
|
||||
for _, warning := range result.Warnings {
|
||||
v.output.Warning(" ⚠️ %s: %s", warning.Field, warning.Message)
|
||||
}
|
||||
|
||||
// Display suggestions
|
||||
if len(result.Suggestions) > 0 {
|
||||
v.output.Info("\nSuggestions:")
|
||||
for _, suggestion := range result.Suggestions {
|
||||
v.output.Printf(" 💡 %s", suggestion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user