Skip to content

[chore]: add delete-outdated-pr-branches GitHub Action#1108

Merged
kevalmorabia97 merged 1 commit intomainfrom
auto/delete-outdated-pr-branches
Mar 24, 2026
Merged

[chore]: add delete-outdated-pr-branches GitHub Action#1108
kevalmorabia97 merged 1 commit intomainfrom
auto/delete-outdated-pr-branches

Conversation

@kevalmorabia97
Copy link
Copy Markdown
Collaborator

@kevalmorabia97 kevalmorabia97 commented Mar 24, 2026

What does this PR do?

Type of change: new feature

Adds a scheduled GitHub Action that automatically deletes pull-request/<num> branches where the corresponding PR is no longer open (i.e., closed or merged). This prevents stale branches from accumulating over time.

Testing

The workflow can be triggered on-demand via workflow_dispatch for manual testing before relying on the weekly schedule.

Before your PR is "Ready for review"

  • Is this change backward compatible?: N/A
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: N/A
  • Did you update Changelog?: N/A

Summary by CodeRabbit

  • Chores
    • Added automated workflow to periodically clean up branches associated with closed or merged pull requests, running weekly and available for manual trigger.

Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
@kevalmorabia97 kevalmorabia97 requested a review from a team as a code owner March 24, 2026 08:13
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

A new GitHub Actions workflow is introduced that automatically deletes remote branches corresponding to closed or merged pull requests. The workflow runs weekly on Mondays and can be triggered manually, iterating through pull-request branches and removing those no longer active.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow
.github/workflows/delete_outdated_pr_branches.yml
New scheduled workflow (weekly, Mondays 09:00 UTC) with manual dispatch that queries PR states via GitHub CLI and deletes remote branches for closed/merged PRs while tracking deletion and skip counts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new GitHub Action workflow for deleting outdated PR branches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Security Anti-Patterns ✅ Passed The custom security check targets Python code changes in the modelopt package and examples, but this PR only adds a GitHub Actions workflow file written in YAML with bash scripting, containing no Python code modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auto/delete-outdated-pr-branches

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/delete_outdated_pr_branches.yml (1)

32-32: Consider preserving stderr for debugging.

Suppressing stderr with 2>/dev/null may hide useful error messages when troubleshooting. Consider logging to a variable or removing the suppression since the || echo "" fallback already handles failures gracefully.

♻️ Optional: Capture stderr for visibility
-            STATE=$(gh pr view "$branch" --repo "$REPO" --json state --jq '.state' 2>/dev/null || echo "")
+            STATE=$(gh pr view "$branch" --repo "$REPO" --json state --jq '.state' || echo "")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/delete_outdated_pr_branches.yml at line 32, The command
that sets STATE uses stderr suppression (2>/dev/null) which hides gh CLI errors;
remove the redirection or capture stderr for debugging so failures are
visible—for example, change the assignment that uses STATE=$(gh pr view
"$branch" --repo "$REPO" --json state --jq '.state' 2>/dev/null || echo "") to
either remove "2>/dev/null" so gh errors appear, or capture stderr into a
separate variable (e.g., ERR) via "2>&1" and log ERR when STATE is empty; update
references to STATE, the gh pr view invocation, "$branch" and "$REPO"
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/delete_outdated_pr_branches.yml:
- Line 32: The command that sets STATE uses stderr suppression (2>/dev/null)
which hides gh CLI errors; remove the redirection or capture stderr for
debugging so failures are visible—for example, change the assignment that uses
STATE=$(gh pr view "$branch" --repo "$REPO" --json state --jq '.state'
2>/dev/null || echo "") to either remove "2>/dev/null" so gh errors appear, or
capture stderr into a separate variable (e.g., ERR) via "2>&1" and log ERR when
STATE is empty; update references to STATE, the gh pr view invocation, "$branch"
and "$REPO" accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4b01f70-d2ac-4481-b540-943c272e8469

📥 Commits

Reviewing files that changed from the base of the PR and between c425524 and b86894d.

📒 Files selected for processing (1)
  • .github/workflows/delete_outdated_pr_branches.yml

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 24, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-24 09:04 UTC

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.23%. Comparing base (c425524) to head (b86894d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1108   +/-   ##
=======================================
  Coverage   70.23%   70.23%           
=======================================
  Files         227      227           
  Lines       25909    25909           
=======================================
  Hits        18198    18198           
  Misses       7711     7711           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kevalmorabia97 kevalmorabia97 merged commit 029593e into main Mar 24, 2026
36 checks passed
@kevalmorabia97 kevalmorabia97 deleted the auto/delete-outdated-pr-branches branch March 24, 2026 09:04
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