Skip to content

Commit fca01d4

Browse files
authored
Add workflow to detect AI PRs (#1049)
* - - added workflow for detecting and labelling agentic PRs * - updated human label, to match the label name on the repo
1 parent 83badb0 commit fca01d4

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎.github/workflows/detect-ai.yml‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Runs script to detect the likelihood of a PR have being create
2+
# by an agent, or with a human with heavy use of AI.
3+
4+
name: Detect AI
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- master
10+
- uncover-agent # We can remove this later
11+
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
issues: write
16+
17+
jobs:
18+
analyse:
19+
name: Classify PR (AI vs human)
20+
runs-on: ubuntu-latest
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
24+
steps:
25+
- name: Check out repository
26+
# The Codeberg repo is private, so we have to clone it with a Codeberg token
27+
run: |
28+
set -euo pipefail
29+
[ -n "$CODEBERG_TOKEN" ] || { echo "::error::CODEBERG_TOKEN secret is required"; exit 1; }
30+
clone_url="https://user:${CODEBERG_TOKEN}@codeberg.org/geoamish/uncover-agent.git"
31+
git clone --quiet "$clone_url" "$RUNNER_TEMP/uncover-agent"
32+
shopt -s dotglob
33+
mv "$RUNNER_TEMP/uncover-agent"/* .
34+
rmdir "$RUNNER_TEMP/uncover-agent"
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.12" # we can change this later
40+
41+
- name: Run uncover_agents.py
42+
run: |
43+
set -euo pipefail
44+
PR_URL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
45+
python uncover_agents.py "$PR_URL" | tee result.json
46+
47+
# These labels must exist in the repository
48+
- name: Apply AI / human label
49+
run: |
50+
set -euo pipefail
51+
LABEL=$(python3 -c "import json;print(json.load(open('result.json')).get('label',''))")
52+
echo "Classifier label: $LABEL"
53+
case "$LABEL" in
54+
Low)
55+
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "Human generated" ;;
56+
High|Very\ High)
57+
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "AI generated" ;;
58+
*)
59+
echo "Label '$LABEL' maps to no auto-label; nothing to do." ;;
60+
esac
61+
env:
62+
PR_NUMBER: ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)