Skip to content

Commit 65908b1

Browse files
authored
- updated detect-ai script to use pull_request_target (geopython#2462)
1 parent 932602e commit 65908b1

1 file changed

Lines changed: 37 additions & 26 deletions

File tree

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

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,64 @@
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.
1+
# Runs script to detect the likelihood of a PR having been created
2+
# by an agent, or by a human with heavy use of AI.
33

44
name: Detect AI
55

66
on:
7-
pull_request:
7+
pull_request_target:
88
branches:
99
- master
10-
- uncover-agent # We can remove this later
10+
- fix-workflow # remove later
11+
types: [opened, synchronize, reopened]
1112

12-
permissions:
13-
contents: read
14-
pull-requests: write
15-
issues: write
13+
permissions: {}
14+
15+
concurrency:
16+
group: detect-ai-${{ github.event.pull_request.number }}
17+
cancel-in-progress: true
1618

1719
jobs:
1820
analyse:
1921
name: Classify PR (AI vs human)
2022
runs-on: ubuntu-latest
21-
env:
22-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
23+
# Strict permissions
24+
permissions:
25+
contents: read
26+
pull-requests: write
27+
issues: write
28+
2429
steps:
25-
- name: Check out repository
26-
# The Codeberg repo is private, so we have to clone it with a Codeberg token
30+
# The Codeberg repo is private, so we have to clone it with a Codeberg token
31+
- name: Checkout script
2732
run: |
2833
set -euo pipefail
2934
[ -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
35+
auth=$(printf 'geoamish:%s' "$CODEBERG_TOKEN" | base64 -w0)
36+
echo "::add-mask::$auth"
37+
git -c http.extraheader="Authorization: Basic $auth" \
38+
clone --quiet --depth 1 \
39+
https://codeberg.org/geoamish/uncover-agent.git "$RUNNER_TEMP/uncover-agent"
40+
rm -rf "$RUNNER_TEMP/uncover-agent/.git"
41+
env:
42+
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
43+
- uses: actions/setup-python@v5
3844
with:
39-
python-version: "3.12" # we can change this later
45+
python-version: "3.12" # we can upgrade this later
4046

4147
- name: Run uncover_agents.py
48+
working-directory: ${{ runner.temp }}/uncover-agent
4249
run: |
4350
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
51+
python uncover_agents.py "$PR_URL" > "$RUNNER_TEMP/result.json"
52+
cat "$RUNNER_TEMP/result.json"
53+
env:
54+
GITHUB_TOKEN: ${{ github.token }}
55+
PR_URL: ${{ github.event.pull_request.html_url }}
4656

4757
# These labels must exist in the repository
4858
- name: Apply AI / human label
4959
run: |
5060
set -euo pipefail
51-
LABEL=$(python3 -c "import json;print(json.load(open('result.json')).get('label',''))")
61+
LABEL=$(python3 -c "import json,os;print(json.load(open(os.environ['RUNNER_TEMP']+'/result.json')).get('label',''))")
5262
echo "Classifier label: $LABEL"
5363
case "$LABEL" in
5464
Low)
@@ -59,4 +69,5 @@ jobs:
5969
echo "Label '$LABEL' maps to no auto-label; nothing to do." ;;
6070
esac
6171
env:
62-
PR_NUMBER: ${{ github.event.pull_request.number }}
72+
GH_TOKEN: ${{ github.token }}
73+
PR_NUMBER: ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)