Skip to content

feat: add per-project config file support for unsafe branches#36

Open
ericanderson wants to merge 9 commits intomainfrom
feat/17-per-project-config-file-support
Open

feat: add per-project config file support for unsafe branches#36
ericanderson wants to merge 9 commits intomainfrom
feat/17-per-project-config-file-support

Conversation

@ericanderson
Copy link
Copy Markdown
Owner

Summary

Implements per-project configuration file support for customizing branch safety rules, resolving issue #17.

Key Features

  • Custom Protected Branches: Override default protected branch lists
  • Additional Protected Patterns: Add regex patterns to protect specific branch naming conventions
  • Configurable Safety Rules: Control unpushed commit handling and merged PR requirements
  • Custom Safety Rules: Define project-specific protection rules with custom error messages

Configuration File Discovery

Searches for configuration files in order of precedence:

  1. Environment variable: GHOULS_CONFIG=/path/to/config.json
  2. Repository root: .ghouls.json, .ghoulsrc.json, ghouls.config.json
  3. User home: ~/.config/ghouls/config.json

Implementation Details

  • New Types: SafetyConfig, GhoulsConfig interfaces with comprehensive validation
  • Configuration Loading: Robust file discovery, JSON parsing, and error handling
  • Safety Check Updates: Extended isBranchSafeToDelete() and filterSafeBranches() to support configuration
  • Backward Compatibility: All existing behavior preserved when no config file present
  • Comprehensive Testing: 69 new unit tests covering all configuration scenarios

Example Configuration

{
  "version": "1.0",
  "safety": {
    "protectedBranches": ["main", "develop", "staging", "production"],
    "additionalProtectedPatterns": ["release/.*", "hotfix/.*"],
    "allowUnpushedCommits": false,
    "requireMergedPR": true,
    "customSafetyRules": [
      {
        "name": "temp-branches",
        "pattern": "temp/.*",
        "reason": "temporary experiment branch"
      }
    ]
  }
}

Test Plan

  • [✅] All existing tests pass (backward compatibility verified)
  • [✅] 69 new unit tests covering configuration functionality
  • [✅] TypeScript compilation passes without errors
  • [✅] Configuration validation with error handling
  • [✅] File discovery and loading edge cases
  • [✅] Integration with existing safety check logic

🤖 Generated with Claude Code

- Add SafetyConfig interface with support for:
  - Custom protected branch lists
  - Additional protected patterns (regex)
  - Allow/disallow unpushed commits
  - Require/skip merged PR validation
  - Custom safety rules with regex patterns

- Implement configuration file discovery:
  - Environment variable: GHOULS_CONFIG
  - Repository root: .ghouls.json, .ghoulsrc.json, ghouls.config.json
  - User home: ~/.config/ghouls/config.json

- Update branch safety checks to use configuration
- Add comprehensive unit tests (69 new tests)
- Add detailed documentation with examples
- Maintain backward compatibility with existing behavior

Resolves #17

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ericanderson
Copy link
Copy Markdown
Owner Author

config file in repo should be .config/ghouls.json

ericanderson added a commit that referenced this pull request Aug 7, 2025
- Changed repository-level config file path from multiple options
  (.ghouls.json, .ghoulsrc.json, ghouls.config.json) to single
  standardized path: .config/ghouls.json
- Updated all tests to reflect the new config file location
- Updated README documentation to show the new path structure
- Maintains existing functionality for environment variable and
  user home config locations

Addresses feedback on PR #36 to use .config/ghouls.json as the
repository config file location.
- Changed repository-level config file path from multiple options
  (.ghouls.json, .ghoulsrc.json, ghouls.config.json) to single
  standardized path: .config/ghouls.json
- Updated all tests to reflect the new config file location
- Updated README documentation to show the new path structure
- Maintains existing functionality for environment variable and
  user home config locations

Addresses feedback on PR #36 to use .config/ghouls.json as the
repository config file location.
@ericanderson ericanderson force-pushed the feat/17-per-project-config-file-support branch from 039d7a4 to 86b6c1b Compare August 19, 2025 22:38
- Changed repository-level config file path from multiple options
  (.ghouls.json, .ghoulsrc.json, ghouls.config.json) to single
  standardized path: .config/ghouls.json
- Updated all tests to reflect the new config file location
- Updated README documentation to show the new path structure
- Maintains existing functionality for environment variable and
  user home config locations

Addresses feedback on PR #36 to use .config/ghouls.json as the
repository config file location.
…onfig-file-support

* origin/main:
  feat: add dprint code formatter with husky integration (#38)
  fix: add release and hotfix branch protection to local pruning (#31)
- Replace hardcoded regex patterns with configurable glob patterns using micromatch
- Add release/* release-* hotfix/* patterns to default protected branches
- Unify all branch protection logic into single micromatch.isMatch() call
- Add comprehensive test coverage for glob pattern functionality
- Maintain backward compatibility with exact string matching
- Remove 13 lines of special-cased release/hotfix regex code

This makes branch protection rules fully configurable through the config file
while simplifying the codebase and improving maintainability.
- Implement $GHOULS_DEFAULT placeholder similar to Turborepo's $TURBO_DEFAULT$
- Allow users to extend default protected branches instead of replacing them
- Add expandDefaultPlaceholder() function with smart deduplication
- Support flexible positioning of placeholder anywhere in the array
- Add 17 comprehensive test cases covering all usage patterns
- Update README.md with detailed documentation and examples
- Maintain full backward compatibility with existing configurations

Usage example:
{
  "protectedBranches": ["$GHOULS_DEFAULT", "custom-branch", "feature-*"]
}

This enables users to safely extend defaults while automatically receiving
new default patterns in future versions.
- Remove custom validateConfigWithZod wrapper function
- Use Zod's native safeParse with formatZodErrors utility
- Reorganize config types from src/types/ to src/config/
- Split GhoulsConfig schema and effective config logic
- Maintain all existing error formatting and validation
- All tests pass with improved error messages

Resolves TODO to use Zod's error customization features.
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.

1 participant