Skip to content

Conversation

cfurrow
Copy link

@cfurrow cfurrow commented Oct 3, 2025

Attempting to handle errors more gracefully during this action.

Example error that can cause the entire script to exit suddenly, and not continue:

fatal: ambiguous argument 'origin/package-upgrade-agent-fix-dependabot/npm_and_yarn/ux/ember-power-select-8.11.0': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Summary by CodeRabbit

  • New Features

    • Final summary of deleted and errored branches is printed and exposed at the end of the run.
    • Dry-run now lists branches that would be deleted.
    • Graceful interrupt handling prints the final summary and exits with a clear status.
  • Improvements

    • More robust remote fetch with fallback and continued execution on non-critical failures.
    • Clearer logging and error categorization for missing/inaccessible branches and no-commit scenarios.
    • Safer deletion checks for default, protected, and open-PR branches.
  • Bug Fixes

    • Accurate tracking of successful deletions vs. failures.

@cfurrow cfurrow requested a review from siavashs as a code owner October 3, 2025 15:48
@cfurrow cfurrow marked this pull request as draft October 3, 2025 15:49
Copy link

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds error tracking, consolidated result output, signal traps, refined deletion recording, enhanced fetch with retry, improved branch discovery and SHA retrieval, and differentiated error codes and logging within the delete-old-branches script.

Changes

Cohort / File(s) Summary of Changes
Result collation and signaling
delete-old-branches
Adds error_branches array and output_results function to collate and write results to GITHUB_OUTPUT and console; installs trap for INT/TERM to print final results and exit 130.
Deletion flow updates
delete-old-branches
Updates delete_branch_or_tag: on success add to deleted_branches; on failure add to error_branches and dump debug.log; in dry-run also record in deleted_branches. Replaces unconditional recording with status-based updates (ok vs delete_failed).
Fetch robustness
delete-old-branches
Implements fetch with --unshallow and retry without it; logs and continues when fetch indicates a complete clone.
Branch discovery and SHA handling
delete-old-branches
Verifies origin/ accessibility via git_log_output; records missing/inaccessible branches; if no recent commits, gets SHA via origin/ with explicit handling of no_sha/empty_sha. Skips default/protected/open PR branches as before.
Error typing and logging
delete-old-branches
Introduces structured error codes: missing_or_inaccessible, no_sha, empty_sha, delete_failed; adds explicit logging for branches with/without recent commits.
Output consolidation
delete-old-branches
Removes direct writes of deleted_branches to GITHUB_OUTPUT; centralizes final emission in output_results, invoked at script end.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User/CI
  participant S as delete-old-branches
  participant G as git remote (origin)
  participant O as GITHUB_OUTPUT

  Note over S: Setup
  S->>S: Init deleted_branches[], error_branches[]
  S->>S: set trap INT/TERM → output_results + exit 130

  Note over S,G: Fetch with retry
  S->>G: git fetch --prune --unshallow
  alt fetch fails (shallow/other)
    S->>G: git fetch --prune
    opt complete clone
      S->>S: log fetch error and continue
    end
  end

  Note over S,G: Discover branches
  loop for each candidate branch
    S->>G: git log origin/<branch> (existence/access)
    alt missing/inaccessible
      S->>S: error_branches += missing_or_inaccessible
    else recent commits?
      alt no recent commits
        S->>G: resolve SHA via origin/<branch>
        alt no_sha/empty_sha
          S->>S: error_branches += no_sha | empty_sha
        else got SHA
          S->>S: proceed to deletion checks
        end
      else has commits
        S->>S: proceed to deletion checks
      end
    end

    Note over S: Skip rules
    S->>S: Skip if default/protected/open PR

    alt eligible to delete
      S->>G: delete branch (or dry-run)
      alt ok
        S->>S: deleted_branches += branch
      else failure
        S->>S: error_branches += delete_failed
        S->>S: dump debug.log
      end
    end
  end

  Note over S,O: Finalize
  S->>O: output_results(deleted_branches, error_branches)
  S-->>U: Print summary to console and exit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble old twigs from the repo tree,
Fetch, hop back—unshallow, we’ll see.
Branch by branch, I tidy the trail,
Log my crumbs when deletions fail.
With a thump and a wink, results I compose—
Then scamper off, whiskers dusted with prose. 🐇🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description does not follow the repository’s template because it lacks the required “## Description” header and a “#### Related Issues” section linking to any issues. While it explains an example error scenario, it fails to use the prescribed structure or reference related issues for context. Please update the description to include the “## Description” header with detailed changes, add a “#### Related Issues” section with any issue numbers or references, and ensure the template structure is fully followed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly highlights the main change of improving error handling, which matches the pull request’s focus on handling errors more gracefully. Including the “Bugfix/” prefix does not obscure the intent, but it is not necessary for understanding the change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eeeb87 and 9461d41.

📒 Files selected for processing (1)
  • delete-old-branches (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cfurrow cfurrow marked this pull request as ready for review October 3, 2025 17:20
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