From dbc43dcc7816b7c357aa0671ff5ed0fc1f41d3d5 Mon Sep 17 00:00:00 2001 From: Chang Su Date: Tue, 14 Apr 2026 11:10:36 -0700 Subject: [PATCH] ci: move branch naming check from Mergify to GitHub Actions Mergify's pull_request_rules creates a post_check on fork PRs with bad branch names even when head-repo-full-name guards should exclude them. This produces noisy failing checks on external contributions. Replace with a GitHub Actions job that uses a proper `if` gate to skip fork PRs entirely, and auto-closes internal PRs with bad branch names. Signed-off-by: Chang Su --- .github/mergify.yml | 29 ----------------- .github/workflows/pr-naming-check.yml | 46 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/.github/mergify.yml b/.github/mergify.yml index 18c8f9e1da..0dd70d6d3c 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -1,33 +1,4 @@ -# post_check rule 'Enforce branch naming convention (internal)' was removed without replacement (no success_conditions or neutral_conditions to migrate) pull_request_rules: - - name: Enforce branch naming convention (internal) - description: Auto-close PRs from internal branches that don't follow naming convention - conditions: - - -head~=^[a-z0-9]([a-z0-9._-]*[a-z0-9])?(/[a-z0-9._-]+)+$ - - head != main - - head-repo-full-name = lightseekorg/smg - actions: - comment: - message: | - Hi @{{author}}, the branch `{{head}}` does not follow our naming convention. - - Please use one of the following formats: - - `/` — e.g. `feat/add-auth`, `fix/null-pointer`, `dependabot/cargo/pyo3-0.28.1` - - `/` — e.g. `changsu/fix-routing` - - Allowed types: `feat`, `fix`, `chore`, `docs`, `refactor`, `test`, `ci`, `perf` - - > **Note:** PRs with non-conforming branch names **will be auto-closed**. Please follow the naming convention for all branches. - close: - message: | - Closing this PR because the branch name `{{head}}` does not follow the naming convention. - - To fix this, please rename your branch locally, push the new branch, and open a new PR: - ```bash - git branch -m - git push origin -u - ``` - - name: Comment on DCO check failure description: Post fix instructions when DCO sign-off is missing conditions: diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 5e08260331..ba95678106 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -9,6 +9,52 @@ concurrency: cancel-in-progress: true jobs: + branch-naming: + name: Branch Naming Convention + runs-on: ubuntu-latest + # Only enforce on internal PRs, not forks + if: github.event.pull_request.head.repo.full_name == 'lightseekorg/smg' && github.head_ref != 'main' + permissions: + contents: read + pull-requests: write + steps: + - name: Validate branch name + env: + BRANCH: ${{ github.head_ref }} + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + REGEX='^[a-z0-9]([a-z0-9._-]*[a-z0-9])?(/[a-z0-9._-]+)+$' + + if [[ "$BRANCH" =~ $REGEX ]]; then + echo "✅ Branch name is valid: '$BRANCH'" + exit 0 + fi + + # Post comment and close the PR + gh pr comment "$PR_NUMBER" \ + --repo "${{ github.repository }}" \ + --body "Hi @${PR_AUTHOR}, the branch \`${BRANCH}\` does not follow our naming convention. + + Please use one of the following formats: + - \`/\` — e.g. \`feat/add-auth\`, \`fix/null-pointer\`, \`dependabot/cargo/pyo3-0.28.1\` + - \`/\` — e.g. \`changsu/fix-routing\` + + Allowed types: \`feat\`, \`fix\`, \`chore\`, \`docs\`, \`refactor\`, \`test\`, \`ci\`, \`perf\` + + To fix, rename your branch locally, push the new branch, and open a new PR: + \`\`\`bash + git branch -m + git push origin -u + \`\`\`" + + gh pr close "$PR_NUMBER" \ + --repo "${{ github.repository }}" \ + --comment "Closing this PR because the branch name \`${BRANCH}\` does not follow the naming convention." + + exit 1 + pr-validation: name: PR Title & Commit Messages runs-on: ubuntu-latest