Skip to content

[MNT] Created workflow for closing "AI Spam" pull requests #2750

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions .github/utilities/ai_spam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Script for handling AI Spam label on pull requests.

Triggered when AI Spam label is added to a PR,
it adds a comment and closes the PR.
"""

import json
import os

from github import Github

context_dict = json.loads(os.getenv("CONTEXT_GITHUB"))

repo_name = context_dict["repository"]
g = Github(os.getenv("GITHUB_TOKEN"))
repo = g.get_repo(repo_name)
pr_number = context_dict["event"]["pull_request"]["number"]
pr = repo.get_pull(pr_number)
label_name = context_dict["event"]["label"]["name"]

if label_name == "AI Spam":
comment_body = (
"This pull request has been flagged with the **AI Spam** label.\n\n"
"This PR is being closed."
)
pr.create_issue_comment(comment_body)
pr.edit(state="closed")
42 changes: 42 additions & 0 deletions .github/workflows/ai_spam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: AI Spam Detection On PR

on:
pull_request:
types: [labeled]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
ai-spam-present:
if: ${{ github.event.label.name == 'AI Spam' }}
runs-on: ubuntu-24.04

steps:
- name: Create app token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_APP_ID }}
private-key: ${{ secrets.PR_APP_KEY }}

- name: Checkout main
uses: actions/checkout@v4
with:
sparse-checkout: .github/utilities

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install PyGithub
run: pip install -Uq PyGithub

- name: Process AI Spam
id: handle_spam
run: python .github/utilities/ai_spam.py
env:
CONTEXT_GITHUB: ${{ toJson(github) }}
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}