Skip to content

Validate branch names on push and in PRs - #908

Merged
PedroLunet merged 5 commits into
betafrom
limwa/907-validate-branch-name
Oct 18, 2026
Merged

PedroLunet merged 5 commits into
betafrom
limwa/907-validate-branch-name

Conversation

@limwa

@limwa limwa commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Closes #907

What does this PR do?

Enforces the branch naming convention <user>/<issue-number>-<short-description> (e.g. francisca/499-fix-navbar-overflow) in two places:

  • Pre-push hook (.husky/pre-push): rejects pushes that would create a new remote branch whose name doesn't match the convention. Pushes to existing remote branches are allowed, as are deletions and pushes to main, develop, and beta.
  • CI workflow (.github/workflows/branch_name.yaml): when a PR targeting beta is opened, checks the head branch name and, if it doesn't match, posts an informational comment. The check never blocks the PR. It skips bot-authored PRs.

The description must be lowercase letters separated by hyphens. The hook and the workflow use the same regex, and the hook's comment notes they must be kept in sync.

How to test

  1. Run bun install so the Husky hooks are set up.
  2. Create a local branch with a non-conforming name (e.g. git switch -c my-feature) and push it with git push -u origin my-feature. The push should be rejected with the expected format message.
  3. Rename it to a conforming name (e.g. git branch -m <user>/907-validate-branch-name) and push again. The push should succeed.
  4. Push a commit to an existing remote branch with a non-conforming name. The push should succeed, since existing branches are grandfathered in.
  5. Open a PR against beta from a non-conforming branch. The workflow should post a comment explaining the convention and should not block merging.
  6. Open a PR against beta from a conforming branch. The workflow should log that the name is valid and post no comment.

Screenshots

N/A — no UI changes.

Summary by CodeRabbit

  • Chores
    • Pull requests targeting beta now receive an informational comment when the branch name does not follow the required format. Bot-authored pull requests are excluded.
    • Pushes that create new remote branches are blocked when their names do not follow the required format. Existing branches, branch deletions, and main, develop, and beta are exempt.

limwa added 5 commits October 17, 2026 14:35
- Add a workflow that comments on newly opened PRs targeting beta when the head branch doesn't match the naming convention
- Runs on pull_request_target without checking out PR code; skips bot-authored PRs
- Informational only: posts a reminder comment and does not block merging
- Make the issue prefix mandatory in the branch name check, so `<user>/<short-description>` no longer passes
- Drop that form from the error message so it matches the accepted formats
- Add a pre-push hook that checks pushed branch names against <user>/<issue-number>-<description> or <user>/NOISSUE-<description>
- Skip main, develop, beta, and branch deletions
- Mirrors the naming rule in .github/workflows/branch_name.yaml
- Only validate branch names when the push creates a new remote branch
- Pushes to branches that already exist on the remote are no longer rejected
- Comment updated to document the grandfathering behavior
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df8e2f9f-16c7-4273-a439-737b11726099
📥 Commits

Reviewing files that changed from the base of the PR and between e8e4647 and 3c2cbed.

📒 Files selected for processing: 2
  • .github/workflows/branch_name.yaml
  • .husky/pre-push

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

A pre-push hook checks names for newly created remote branches. A GitHub Actions workflow checks branch names when a pull request opens against beta and posts an informational comment for invalid names.

Changes: Branch naming enforcement

Layer / File(s) Summary
Local push validation
.husky/pre-push
The hook checks new remote branch names against the convention. It skips deletions, existing remote branches, non-branch refs, and main, develop, and beta.
Pull request validation
.github/workflows/branch_name.yaml
The workflow runs for pull requests opened against beta, skips bot-authored pull requests, and posts an informational comment when the branch name does not match. It uses actions/github-script@v7.

Sequence Diagram(s)

sequenceDiagram
  participant GitHub
  participant Workflow
  participant Script
  GitHub->>Workflow: Open pull request targeting beta
  Workflow->>Script: Run branch name check
  Script->>GitHub: Post informational comment when name is invalid
Loading

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 3c2cb

The disputed branch name is allowed by the project rule, and no actionable merge risk remains after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: branch-name validation on pushes and pull requests.
Description check Passed The description includes the required issue reference, change summary, testing steps, and screenshot status. It clearly explains the pre-push hook, CI workflow, exceptions, and expected behavior.
Linked Issues check Passed Issue #907 requires local and CI checks for the documented branch format. The .husky/pre-push hook checks only new remote branches, skips deletions, tags, existing remote branches, and main, `deve…
Out of Scope Changes check Passed The whole-PR diff adds only .husky/pre-push and .github/workflows/branch_name.yaml. Both files implement the local and CI branch-name requirements in issue #907. The workflow comment and safety co…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Full details: Linked Issues check

Explanation

Issue #907 requires local and CI checks for the documented branch format. The .husky/pre-push hook checks only new remote branches, skips deletions, tags, existing remote branches, and main, develop, and beta, and returns failure for invalid names. The workflow runs on pull_request_target with types: [opened] and base beta, skips bot authors, uses the matching naming pattern, and posts a non-blocking informational comment for invalid names. The hook and workflow document the shared pattern requirement.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff adds only .husky/pre-push and .github/workflows/branch_name.yaml. Both files implement the local and CI branch-name requirements in issue #907. The workflow comment and safety configuration support that objective. No unrelated change is present.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.)

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@limwa
limwa requested review from PedroLunet and franpts2 October 17, 2026 15:09

@franpts2 franpts2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@PedroLunet
PedroLunet merged commit 62d48d3 into beta Oct 18, 2026
3 checks passed
@PedroLunet
PedroLunet deleted the limwa/907-validate-branch-name branch October 18, 2026 16:22
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.

Enforce branch naming conventions locally and in CI

3 participants