-
Notifications
You must be signed in to change notification settings - Fork 2.1k
92 lines (81 loc) · 3.16 KB
/
Copy pathpr-ai-disclosure.yml
File metadata and controls
92 lines (81 loc) · 3.16 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Check AI disclosure in PRs
on:
pull_request_target:
types: [opened, reopened, edited]
permissions:
pull-requests: write
issues: write
jobs:
check-disclosure:
name: Check AI disclosure section
runs-on: ubuntu-latest
steps:
- name: Check if AI label is already present
id: labels
uses: actions/github-script@v9
with:
script: |
const hasAiLabel = context.payload.pull_request.labels.some(
l => l.name.startsWith("AI: ")
);
core.setOutput("has_ai_label", hasAiLabel);
- name: Validate that PR body contains AI disclosure
id: check
uses: actions/github-script@v8
with:
script: |
// Remove template hints.
const body = (context.payload.pull_request.body || "")
.replace(/\r/g, "")
.replace(/<!--[\s\S]*?-->/g, "");
// Match first non-empty line that doesn't start with '#'
const heading = `##+\\s+Declaration of AI-Tools \\/ LLMs usage:?`;
const sectionRegex = new RegExp(
`^${heading}\\s*(^\\s*[^#\\s].*$)`,
"m"
);
const match = body.match(sectionRegex);
const missing = !match || match[1].trim().length === 0;
core.setOutput("is_declaration_missing", String(missing));
- name: Remove AI label if declaration exists
if: steps.check.outputs.is_declaration_missing == 'false'
uses: actions/github-script@v9
with:
script: |
const prNumber = context.payload.pull_request.number;
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: "AI: Declaration Missing"
});
} catch (error) {
// Ignore if the label does not exist
if (error.status !== 404) {
throw error;
}
}
- name: Comment on PR and add labels
uses: actions/github-script@v9
if: >-
steps.check.outputs.is_declaration_missing == 'true' &&
steps.labels.outputs.has_ai_label != 'true'
with:
script: |
const prNumber = context.payload.pull_request.number;
const user = context.payload.pull_request.user.login;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Hey @${user}, thank you for your contribution to RIOT!
Please note that we require for all PRs to RIOT a declaration of AI-Tools / LLMs usage. It appears as if this section is missing in your PR. Please copy and fill in the section from .github/PULL_REQUEST_TEMPLATE.md.
Thank you!`
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ["AI: Declaration Missing"]
});