Repository navigation
73 lines (65 loc) · 2.49 KB
/
Copy pathdetect-ai.yml
File metadata and controls
73 lines (65 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Runs script to detect the likelihood of a PR having been created
# by an agent, or by a human with heavy use of AI.
name: Detect AI
on:
pull_request_target:
branches:
- master
- fix-workflow # remove later
types: [opened, synchronize, reopened]
permissions: {}
concurrency:
group: detect-ai-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
analyse:
name: Classify PR (AI vs human)
runs-on: ubuntu-latest
# Strict permissions
permissions:
contents: read
pull-requests: write
issues: write
steps:
# The Codeberg repo is private, so we have to clone it with a Codeberg token
- name: Checkout script
run: |
set -euo pipefail
[ -n "$CODEBERG_TOKEN" ] || { echo "::error::CODEBERG_TOKEN secret is required"; exit 1; }
auth=$(printf 'geoamish:%s' "$CODEBERG_TOKEN" | base64 -w0)
echo "::add-mask::$auth"
git -c http.extraheader="Authorization: Basic $auth" \
clone --quiet --depth 1 \
https://codeberg.org/geoamish/uncover-agent.git "$RUNNER_TEMP/uncover-agent"
rm -rf "$RUNNER_TEMP/uncover-agent/.git"
env:
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
- uses: actions/setup-python@v5
with:
python-version: "3.12" # we can upgrade this later
- name: Run uncover_agents.py
working-directory: ${{ runner.temp }}/uncover-agent
run: |
set -euo pipefail
python uncover_agents.py "$PR_URL" > "$RUNNER_TEMP/result.json"
cat "$RUNNER_TEMP/result.json"
env:
GITHUB_TOKEN: ${{ github.token }}
PR_URL: ${{ github.event.pull_request.html_url }}
# These labels must exist in the repository
- name: Apply AI / human label
run: |
set -euo pipefail
LABEL=$(python3 -c "import json,os;print(json.load(open(os.environ['RUNNER_TEMP']+'/result.json')).get('label',''))")
echo "Classifier label: $LABEL"
case "$LABEL" in
Low)
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "Human generated" ;;
High|Very\ High)
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "AI generated" ;;
*)
echo "Label '$LABEL' maps to no auto-label; nothing to do." ;;
esac
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}