From e246215663205ef5751874f3bb10bf6d9e7fa571 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Tue, 28 Oct 2025 15:28:42 +0100 Subject: [PATCH] ci: add a new workflow to close AI-generated PRs (#2098) * ci: add a new workflow to close AI-generated PRs This PR adds a workflow to automatically close the PRs with too much AI-generated code. * fix: apply review comments --- .github/workflows/ai-generated.yml | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/ai-generated.yml diff --git a/.github/workflows/ai-generated.yml b/.github/workflows/ai-generated.yml new file mode 100644 index 00000000..e213b897 --- /dev/null +++ b/.github/workflows/ai-generated.yml @@ -0,0 +1,59 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: 'AI-generated pull requests' + +on: + pull_request: + types: [labeled, unlabeled, reopened] + +permissions: + pull-requests: read + +jobs: + ai-generated-support: + if: github.event.label.name == 'ai-generated' || github.event.action == 'reopened' + runs-on: ubuntu-24.04 + concurrency: + group: support-${{ github.event.pull_request.number }} + cancel-in-progress: true + permissions: + pull-requests: write + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NUMBER: ${{ github.event.pull_request.number }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + steps: + - name: Label added, comment and close pull request + if: github.event.action == 'labeled' && github.event.label.name == 'ai-generated' + shell: bash + env: + BODY: > + :wave: @${{ env.PR_AUTHOR }}, thank you for your contribution! + + However, this pull request has been closed because it appears to contain a significant amount of AI-generated code without sufficient human review or supervision. + + AI-generated code can often introduce subtle bugs, poor design patterns, or inconsistent styles that make long-term maintenance difficult and reduce overall code quality. For the sake of the project's future stability and readability, we require that all contributions meet our established coding standards and demonstrate clear developer oversight. + + This pull request is also too large for effective human review. Please discuss with us on how to break down these changes into smaller, more focused PRs to ensure a thorough and efficient review process. + If you'd like to revise and resubmit your changes with careful review and cleanup, we'd be happy to take another look. + run: | + retry() { n=0; until "$@"; do n=$((n+1)); [ $n -ge 3 ] && break; echo "retry $n: $*" >&2; sleep 2; done; } + retry gh pr comment "$NUMBER" -R "$GH_REPO" -b "$BODY" || true + retry gh pr close "$NUMBER" -R "$GH_REPO" || true + gh pr lock "$NUMBER" -R "$GH_REPO" -r "spam" || true + + - name: Reopened or label removed, unlock pull request + if: github.event.action == 'unlabeled' && github.event.label.name == 'ai-generated' + shell: bash + run: | + retry() { n=0; until "$@"; do n=$((n+1)); [ $n -ge 3 ] && break; echo "retry $n: $*" >&2; sleep 2; done; } + retry gh pr reopen "$NUMBER" -R "$GH_REPO" || true + gh pr unlock "$NUMBER" -R "$GH_REPO" || true + + - name: Remove AI-generated label on manual reopen + if: github.event.action == 'reopened' + shell: bash + run: | + gh pr edit "$NUMBER" -R "$GH_REPO" --remove-label "ai-generated" || true + gh pr unlock "$NUMBER" -R "$GH_REPO" || true