generator icon indicating copy to clipboard operation
generator copied to clipboard

[FEATURE] Flag force-pushed PRs with a label in CI and update contributor docs

Open devxdh opened this issue 1 week ago • 6 comments

Why do we need this improvement?

Force-pushing on an open PR causes two problems:

  1. It wipes out the incremental diff between commits, so reviewers cannot see what changed since their last review and have to re-review the entire PR.
  2. As seen in the recent incident on #2277 and #2278, someone can force-push bad code and then force-push back to clean code. When that happens, earlier inline bot warnings get marked as outdated and hidden, making the PR look clean.

Right now, .github/pr-review-checklist.md asks contributors to avoid force-pushing, but it is just passive text inside a 10-point bot comment posted after a PR is opened—it isn't enforced, and it doesn't alert reviewers if someone force-pushes later. There is no automated check to flag force-pushes, and this rule is missing from apps/generator/docs/contributing.md, AGENTS.md, and CLAUDE.md.

How will this change help?

  • Maintainers will see a clear label on any PR whose commit history was rewritten, so they know to check the PR timeline and any collapsed review comments before approving.
  • Contributors and AI agents reading contributing.md, AGENTS.md, and CLAUDE.md will know upfront not to force-push on open PRs.

Screenshots

No response

How could it be implemented/designed?

1. Add a force-push check workflow

Create a small workflow (for example, .github/workflows/detect-force-push.yml) that runs on pull_request_target (synchronize) without checking out any PR code (same API-only, zizmor-safe setup as verify-ai-disclosure.yml, so it runs safely on fork PRs too):

  • Read context.payload.before and context.payload.after.
  • Call github.rest.repos.compareCommitsWithBasehead with basehead: ${before}...${after}.
  • A normal push always returns status: 'ahead'. If status is 'diverged' or 'behind', before is no longer an ancestor of after, which means a force-push happened.
  • Add a label (for example, force-pushed) to the PR. Open to maintainers' preference on the exact label name and color (e.g. an attention-grabbing orange or light red so reviewers notice it immediately).
name: Detect force-push on PR

on:
  pull_request_target:
    types:
      - synchronize # zizmor: ignore[dangerous-triggers] no checkout; API-only comparison of before/after SHAs

permissions: {}

jobs:
  detect-force-push:
    if: >
      github.event.pull_request.user.login != 'asyncapi-bot' &&
      github.event.pull_request.user.login != 'dependabot[bot]' &&
      github.event.pull_request.user.login != 'dependabot-preview[bot]'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Check if push rewrote commit history
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          script: |
            const { before, after, pull_request: pr } = context.payload;
            if (!before || !after || before === after) return;

            const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({
              owner: context.repo.owner,
              repo: context.repo.repo,
              basehead: `${before}...${after}`,
            });

            if (comparison.status === 'diverged' || comparison.status === 'behind') {
              await github.rest.issues.addLabels({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: pr.number,
                labels: ['force-pushed'],
              });
            }

2. Update docs and agent rules

Add a short rule stating not to force-push on open PRs (use normal incremental commits; PRs are squash-merged anyway) to:

  • apps/generator/docs/contributing.md
  • AGENTS.md (which CLAUDE.md symlinks to)

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • [x] I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

devxdh avatar Nov 26 '26 03:11 devxdh

@derberg one optional thing to consider alongside the label: when a force push happens, the workflow could also post one comment (and update that same comment if it happens again) with the before..after compare link.

That way, reviewers don't have to dig for collapsed commits in the timeline or re-review the entire pr thread again. They get a 1-click view of what changed. Since it only runs on force-pushed prs, normal prs won't get any extra comment. The only tradeoff I can think of right now is one extra bot comment on force-pushed prs alongside the other bots, and gh does log force-pushes in the timeline if you go looking for them.

Let me know wdyt on this, whether you'd prefer just the label or including this too.

devxdh avatar Nov 26 '26 03:11 devxdh

@devxdh The proposed API-only approach looks good, particularly because it avoids checking out or executing PR-authored code.

One edge case worth considering,I believe, is when the Compare API cannot resolve the previous HEAD or returns an API error. Since this is a security-oriented check, an unsuccessful comparison should not be silently treated as a normal push.

SHUBHANSHU602 avatar Nov 26 '26 04:11 SHUBHANSHU602

@SHUBHANSHU602 good catch. In the pr I'll wrap it in try/catch and treat 404/422 as rewritten history, and fail explicitly on other api errors.

devxdh avatar Nov 26 '26 05:11 devxdh

one optional thing to consider alongside the label: when a force push happens, the workflow could also post one comment (and update that same comment if it happens again) with the before..after compare link.

100% this + label

/approve

derberg avatar Nov 26 '26 07:11 derberg

/approve

derberg avatar Nov 26 '26 07:11 derberg

👋 Thanks for your patience. This issue has been reviewed and is ready to be worked on.

Before you start:

  • Comment below to let others know you're working on it (avoids duplicate work)
  • Read our CONTRIBUTING.md if you haven't already
  • Fork the repo, create a feature branch, and open a draft PR early

Approved by @derberg

asyncapi-bot avatar Nov 26 '26 07:11 asyncapi-bot