Skip to content

Commit d140fe9

Browse files
Ramana-RajaRamana-Raja
andauthored
[MNT] Created workflow for closing "AI Spam" pull requests (#2750)
* added ai_spam * Automatic `pre-commit` fixes * fixed comment text * fixed comment text * updated to python 3.11 --------- Co-authored-by: Ramana-Raja <ramanarajakesavaraja@gamil.com>
1 parent b289d58 commit d140fe9

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

.github/utilities/ai_spam.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Script for handling AI Spam label on pull requests.
2+
3+
Triggered when AI Spam label is added to a PR,
4+
it adds a comment and closes the PR.
5+
"""
6+
7+
import json
8+
import os
9+
10+
from github import Github
11+
12+
context_dict = json.loads(os.getenv("CONTEXT_GITHUB"))
13+
14+
repo_name = context_dict["repository"]
15+
g = Github(os.getenv("GITHUB_TOKEN"))
16+
repo = g.get_repo(repo_name)
17+
pr_number = context_dict["event"]["pull_request"]["number"]
18+
pr = repo.get_pull(pr_number)
19+
label_name = context_dict["event"]["label"]["name"]
20+
21+
if label_name == "AI Spam":
22+
comment_body = (
23+
"This pull request has been flagged with the **AI Spam** label.\n\n"
24+
"This PR is being closed."
25+
)
26+
pr.create_issue_comment(comment_body)
27+
pr.edit(state="closed")

.github/workflows/ai_spam.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: AI Spam Detection On PR
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
ai-spam-present:
13+
if: ${{ github.event.label.name == 'AI Spam' }}
14+
runs-on: ubuntu-24.04
15+
16+
steps:
17+
- name: Create app token
18+
uses: actions/create-github-app-token@v1
19+
id: app-token
20+
with:
21+
app-id: ${{ vars.PR_APP_ID }}
22+
private-key: ${{ secrets.PR_APP_KEY }}
23+
24+
- name: Checkout main
25+
uses: actions/checkout@v4
26+
with:
27+
sparse-checkout: .github/utilities
28+
29+
- name: Setup Python 3.11
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
34+
- name: Install PyGithub
35+
run: pip install -Uq PyGithub
36+
37+
- name: Process AI Spam
38+
id: handle_spam
39+
run: python .github/utilities/ai_spam.py
40+
env:
41+
CONTEXT_GITHUB: ${{ toJson(github) }}
42+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

0 commit comments

Comments
 (0)