Skip to content

[#364] Added repeatable, comma-separated and regex '--cleanup-pattern' values. - #365

Merged
AlexSkrypnyk merged 2 commits into
mainfrom
feature/364-multi-pattern
Jul 22, 2026
Merged

[#364] Added repeatable, comma-separated and regex '--cleanup-pattern' values.#365
AlexSkrypnyk merged 2 commits into
mainfrom
feature/364-multi-pattern

Conversation

@AlexSkrypnyk

Copy link
Copy Markdown
Member

Closes #364

Summary

The --cleanup-pattern option for stale-branch cleanup is now far more flexible. It is repeatable (InputOption::VALUE_IS_ARRAY), and each value may be a comma-separated list of shell globs (so a single environment variable like feature/*,bugfix/* works) or a single regex literal wrapped in slashes (e.g. /^feature\/[^\/]+$/). A branch is eligible for cleanup when it matches any of the supplied patterns. The change is backward compatible: a single --cleanup-pattern=deployment/* value still works exactly as before.

Changes

Repeatable and comma-separated pattern parsing

  • --cleanup-pattern is now declared with InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY in src/Commands/ArtifactCommand.php, so the flag can be passed multiple times.
  • ArtifactCommand::resolveOptions() normalizes the raw option values: each value is trimmed, split on commas unless it is a regex literal, and empty segments are discarded.
  • Resolved patterns are deduplicated with array_values(array_unique(...)) and stored in a new protected array $cleanupPatterns property, replacing the old protected string $cleanupPattern.

Regex support

  • ArtifactGitRepository::isRegexPattern() treats a value starting with / as a PCRE literal, since a Git branch name can never begin with a slash.
  • ArtifactGitRepository::isValidRegex() compiles a candidate pattern with preg_match() (with a temporary error handler suppressing warnings) to confirm it is usable.
  • Invalid regexes are rejected during option resolution with a RuntimeException, before any Git operations run.

Matching against multiple patterns

  • ArtifactGitRepository::filterStaleBranches() now takes array $patterns instead of a single string $pattern.
  • New protected helpers matchesAnyPattern() and matchesPattern() iterate the pattern list, dispatching to preg_match() for regex literals or the existing matchesGlob() for shell globs.

Reporting

  • showInfo() now lists every resolved pattern, switching between singular and plural labels depending on the count, instead of printing a single pattern string.

Documentation and tests

  • README.md documents the comma-separated and regex forms and updates the --cleanup-pattern row in the options table.
  • tests/Functional/CleanupStaleBranchesTest.php adds coverage for comma-separated globs, multiple --cleanup-pattern flags, regex precision (excluding nested-slash branches), empty-pattern rejection, and invalid-regex rejection.
  • tests/Unit/ArtifactGitRepositoryTest.php adds data-provider cases for multi-pattern matching and glob/regex dedup, plus new unit tests for isRegexPattern() and isValidRegex().
  • tests/Unit/ArtifactCommandTest.php updates the reflection-based property access from cleanupPattern to cleanupPatterns.

Before / After

BEFORE                                    AFTER
+--------------------------------+        +--------------------------------------+
| --cleanup-pattern=deployment/*  |        | --cleanup-pattern=feature/*,bugfix/*  |
|                                  |        | --cleanup-pattern=/^release-\d+$/     |
+--------------------------------+        +--------------------------------------+
  - single value only                        - repeatable (VALUE_IS_ARRAY)
  - shell glob syntax only                   - each value: comma-separated globs
  - one pattern, one match rule                 OR a single /regex/ literal
                                              - branch matches ANY pattern

  string $cleanupPattern                     array $cleanupPatterns

  filterStaleBranches(                       filterStaleBranches(
    array $branches,                           array $branches,
    string $pattern,                           array $patterns,
    ...                                        ...
  )                                          )
        |                                          |
        v                                          v
  matchesGlob($pattern, $branch)             matchesAnyPattern($patterns, $branch)
                                                |
                                                +-- isRegexPattern($p)?
                                                      yes -> preg_match($p, $branch)
                                                      no  -> matchesGlob($p, $branch)

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6543ca62-c8d6-4692-aab0-1efb3cfe525d

📥 Commits

Reviewing files that changed from the base of the PR and between 358e067 and fcf79d9.

📒 Files selected for processing (6)
  • README.md
  • src/Commands/ArtifactCommand.php
  • src/Git/ArtifactGitRepository.php
  • tests/Functional/CleanupStaleBranchesTest.php
  • tests/Unit/ArtifactCommandTest.php
  • tests/Unit/ArtifactGitRepositoryTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/364-multi-pattern

Comment @coderabbitai help to get the list of available commands.

@AlexSkrypnyk AlexSkrypnyk added the Needs review Pull request needs a review from assigned developers label Jul 22, 2026
@AlexSkrypnyk
AlexSkrypnyk merged commit 740bb56 into main Jul 22, 2026
12 checks passed
@AlexSkrypnyk
AlexSkrypnyk deleted the feature/364-multi-pattern branch July 22, 2026 08:23
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (358e067) to head (fcf79d9).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
+ Coverage   97.00%   97.18%   +0.17%     
==========================================
  Files           6        6              
  Lines         501      532      +31     
==========================================
+ Hits          486      517      +31     
  Misses         15       15              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs review Pull request needs a review from assigned developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple --cleanup-pattern values for stale branch cleanup

2 participants