File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change
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 }}
You can’t perform that action at this time.
0 commit comments