Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check force push #489

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/force_push_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PR Force Push Check

on:
pull_request_target:
types:
- synchronize

permissions:
pull-requests: write


jobs:
detect-force-push:
name: Detect Force push
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]' &&!github.event.pull_request.draft &&!contains(github.event.pull_request.title, 'WIP')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check for force push
id: check_force_push
run: |
# The first push is always empty, so skip it.
BEFORE_SHA=${{ github.event.before }}
[[ -z "${BEFORE_SHA}" ]] && echo "force_push=false" >> $GITHUB_ENV

AFTER_SHA=${{ github.event.after }}
if ! git merge-base --is-ancestor $BEFORE_SHA $AFTER_SHA 2>/dev/null; then
echo "force_push=true" >> $GITHUB_ENV
else
echo "force_push=false" >> $GITHUB_ENV
fi

- name: Comment on PR if force push detected
if: env.force_push == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comment = "We’ve detected a force push. Please review the [contribution guidelines](https://github.com/envoyproxy/ai-gateway/blob/main/CONTRIBUTING.md), and avoid force pushing unless you’re addressing a DCO issue after marking your PR as ready for review."
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});