Skip to content

Commit 9aaec9b

Browse files
zaniebzaniebot
andauthored
Handle AI policy labels through Actions (#4812)
Handle `bot:ai-policy-comment` and `bot:ai-policy-close` on issues and pull requests with the shared `ai-policy` action. The automation dispatcher runs `ai-policy.yml` on `main`, where an STS-issued `astral-automations-bot` token posts the policy reminder and optionally closes the target. Draft and fork PRs are supported. The workflow checks the current label and state without checking out PR code. Co-authored-by: zaniebot <[email protected]>
1 parent e1b8efa commit 9aaec9b

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

‎.github/automations-dispatch.json‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"version": 2,
3+
"repositories": {
4+
"ty": {
5+
"name": "astral-sh/ty",
6+
"id": 976731654
7+
}
8+
},
9+
"rules": [
10+
{
11+
"repository": "ty",
12+
"on": {
13+
"pull_request": ["labeled"]
14+
},
15+
"conditions": {
16+
"/label/name": {
17+
"one_of": ["bot:ai-policy-comment", "bot:ai-policy-close"]
18+
}
19+
},
20+
"allow_draft": true,
21+
"allow_forks": true,
22+
"allow_stale_head": true,
23+
"workflow": "ai-policy.yml",
24+
"inputs": {
25+
"label": "/label/name"
26+
}
27+
},
28+
{
29+
"repository": "ty",
30+
"on": {
31+
"issues": ["labeled"]
32+
},
33+
"conditions": {
34+
"/label/name": {
35+
"one_of": ["bot:ai-policy-comment", "bot:ai-policy-close"]
36+
},
37+
"/issue/state": "open"
38+
},
39+
"workflow": "ai-policy.yml",
40+
"inputs": {
41+
"issue": "/issue/number",
42+
"label": "/label/name"
43+
}
44+
}
45+
]
46+
}

‎.github/secure-token-service.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
}
1515
},
1616
"rules": [
17+
{
18+
"caller": "ty",
19+
"environment": "automations",
20+
"caller_workflow": "ai-policy.yml",
21+
"on": ["workflow_dispatch"],
22+
"permissions": { "issues": "write", "pull_requests": "write" },
23+
"target": "ty"
24+
},
1725
{
1826
"caller": "ty",
1927
"environment": "automations",

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "AI policy"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
issue:
7+
description: "An issue number"
8+
required: false
9+
type: number
10+
pull_request:
11+
description: "A pull request number"
12+
required: false
13+
type: number
14+
head_sha:
15+
description: "The pull request head SHA supplied by the dispatcher"
16+
required: false
17+
type: string
18+
label:
19+
description: "The applied policy label"
20+
required: true
21+
type: choice
22+
options:
23+
- bot:ai-policy-comment
24+
- bot:ai-policy-close
25+
26+
permissions: {}
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ inputs.issue || inputs.pull_request }}
30+
cancel-in-progress: false
31+
32+
jobs:
33+
apply:
34+
if: github.repository == 'astral-sh/ty' && github.ref == 'refs/heads/main'
35+
runs-on: ${{ github.repository == 'astral-sh/ty' && 'github-ubuntu-24.04-x86_64-4' || 'ubuntu-latest' }}
36+
environment:
37+
name: automations
38+
deployment: false
39+
timeout-minutes: 5
40+
permissions:
41+
id-token: write
42+
steps:
43+
- name: "Get policy token"
44+
id: token
45+
uses: astral-sh/github-actions/simple-token-service@eb81cf4d13127c3f9539f621c17e4c65327636c8
46+
with:
47+
exchange-url: ${{ secrets.STS_API_URL }}/exchange
48+
audience: ${{ secrets.STS_API_URL }}
49+
repository: ${{ github.repository }}
50+
permissions: |
51+
issues: write
52+
pull_requests: write
53+
54+
- name: "Apply AI policy"
55+
uses: astral-sh/github-actions/ai-policy@610c50be70008f185dfde2683cbfe7c4b3927e7d
56+
with:
57+
token: ${{ steps.token.outputs.token }}
58+
number: ${{ inputs.issue || inputs.pull_request }}
59+
label: ${{ inputs.label }}

0 commit comments

Comments
 (0)