Repository navigation
188 lines (171 loc) · 9.55 KB
/
Copy pathunmet-pr-close.yml
File metadata and controls
188 lines (171 loc) · 9.55 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: PR Script Requirements Check
on:
pull_request_target:
types: [opened, edited, synchronize, reopened]
permissions:
pull-requests: write
contents: read
issues: write
jobs:
validate-script-requirements:
runs-on: ubuntu-latest
steps:
- name: Validate new script requirements
uses: actions/github-script@v9
with:
script: |
// Never closes a PR itself; stale_pr_close.yml does that after 7 days.
const MARKER = "<!-- requirements-check -->";
const LABEL = "requirements missing";
const TEAM = "@community-scripts/contributor";
const { owner, repo } = context.repo;
const pr = context.payload.pull_request;
const number = pr.number;
const author = pr.user.login;
const prLabels = (pr.labels || []).map(l => l.name);
if (prLabels.includes("keep-open")) {
console.log("PR has keep-open label — skipping requirement check.");
return;
}
const body = pr.body || "";
const lines = body.split("\n");
function checkboxChecked(line) {
return /\[\s*x\s*\]/i.test(line);
}
function findLine(text) {
return lines.find(l => l.includes(text));
}
// --- Ping author if new ct/ or install/ files were added without checking "New script" ---
try {
const files = await github.paginate(github.rest.pulls.listFiles, {
owner, repo, pull_number: number, per_page: 100
});
const newScriptFiles = files.filter(f =>
f.status === "added" && (f.filename.startsWith("ct/") || f.filename.startsWith("install/"))
);
const newScriptLineForPing = findLine("🆕 **New script**");
const newScriptCheckedForPing = newScriptLineForPing && checkboxChecked(newScriptLineForPing);
if (newScriptFiles.length > 0 && !newScriptCheckedForPing) {
const marker = "<!-- new-script-files-ping -->";
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number: number, per_page: 100
});
if (!comments.some(c => c.body && c.body.includes(marker))) {
const fileList = newScriptFiles.map(f => "- `" + f.filename + "`").join("\n");
await github.rest.issues.createComment({
owner, repo, issue_number: number,
body:
marker + "\n" +
"👋 @" + author + " this PR adds new file(s) under `ct/` or `install/`, but the **🆕 New script** box in the **Type of Change** section isn't checked:\n\n" +
fileList + "\n\n" +
"If this is a new script submission, please check that box and fill out the **📦 Application Requirements** section — it's required for review.\n" +
"If this isn't actually a new script (e.g. a rename or a shared helper file), you can ignore this message."
});
}
}
} catch (err) {
console.log("New-script-file ping check failed: " + err.message);
}
const problems = [];
if (!findLine("📦 Application Requirements")) {
problems.push(
"The description does not use the DevScripts PR template (the **📦 Application Requirements** section is missing). " +
"Paste [`.github/pull_request_template.md`](https://github.com/community-scripts/DevScripts/blob/main/.github/pull_request_template.md) " +
"into the description and fill it in; your own write-up can go under **Description**."
);
} else {
// Template-version-gated: only enforced if the disclosure prompt exists in the body.
const llmDisclosureIdx = lines.findIndex(l => l.includes("describe to which degree, if any, an LLM was used"));
const noAiUsedChecked = (() => {
const line = findLine("**No AI used**");
return line && checkboxChecked(line);
})();
if (llmDisclosureIdx !== -1 && !noAiUsedChecked) {
let disclosureText = "";
for (let i = llmDisclosureIdx + 1; i < lines.length; i++) {
const trimmed = lines[i].trim();
if (trimmed.startsWith("##") || trimmed === "---") break;
if (trimmed === "" || trimmed.startsWith(">") || trimmed.startsWith("<!--")) continue;
disclosureText += trimmed + " ";
}
if (!disclosureText.trim()) {
problems.push(
"The **🤖 AI Assistance** section does not say whether, or how far, an LLM was used, e.g. *\"No LLM used\"* or " +
"*\"Claude Sonnet 4.5, high reasoning, used for the install script, then manually reviewed\"*."
);
}
}
const newScriptLine = findLine("🆕 **New script**");
if (newScriptLine && checkboxChecked(newScriptLine)) {
const requirements = [
"The application is **at least 6 months old**",
"The application is **actively maintained**",
"The application has **1,000+ GitHub stars**",
"Official **release tarballs** are published",
"I understand that not all scripts will be accepted"
];
for (const req of requirements) {
const line = findLine(req);
if (!line || !checkboxChecked(line)) problems.push(req);
}
const architectureOptions = ["**arm64 supported**", "**arm64 not tested**", "**arm64 not supported**"];
if (!architectureOptions.some(req => { const line = findLine(req); return line && checkboxChecked(line); })) {
problems.push("One arm64 support option (`arm64 supported`, `arm64 not tested`, or `arm64 not supported`) must be checked");
}
const aiNoUsedLine = findLine("**No AI used**");
const aiWasUsedLine = findLine("**AI was used**");
if ((aiNoUsedLine || aiWasUsedLine) &&
!((aiNoUsedLine && checkboxChecked(aiNoUsedLine)) || (aiWasUsedLine && checkboxChecked(aiWasUsedLine)))) {
problems.push("One AI assistance option (`No AI used` or `AI was used – confirmed compliance with AGENTS.md and pve-script-creator.agent.md`) must be checked");
}
const noDockerLine = findLine("**No Docker / Docker Compose**");
if (noDockerLine && !checkboxChecked(noDockerLine)) {
problems.push("`No Docker / Docker Compose` must be confirmed – the application must run bare-metal");
}
const noGitPullLine = findLine("**No git pull**");
if (noGitPullLine && !checkboxChecked(noGitPullLine)) {
problems.push("`No git pull` must be confirmed – use `fetch_and_deploy_gh_release` (or the Codeberg/GitLab/URL variants) instead");
}
}
}
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number: number, per_page: 100
});
const mine = comments.find(c => c.body && c.body.includes(MARKER));
if (problems.length === 0) {
if (mine && !mine.body.startsWith(MARKER + "\n✅")) {
await github.rest.issues.updateComment({
owner, repo, comment_id: mine.id,
body: MARKER + "\n✅ **Requirements check passed.** Thanks for fixing the description — the `stale` mark has been removed."
});
}
if (prLabels.includes(LABEL)) {
for (const name of [LABEL, "stale"]) {
if (prLabels.includes(name)) {
await github.rest.issues.removeLabel({ owner, repo, issue_number: number, name });
}
}
}
return;
}
const text =
MARKER + "\n" +
"### ⚠️ Not ready for review yet\n\n" +
"@" + author + ", this pull request is missing the following:\n\n" +
problems.map(p => "- " + p).join("\n") + "\n\n" +
"**Edit the PR description** to fix it — no new PR needed. This check runs again on every edit and clears itself once everything is in place.\n\n" +
"Until then the PR is marked `stale` and will be closed in **7 days**.\n\n" +
"---\n\n" +
TEAM + " please take a look: close it, comment, or set `keep-open` to keep it.";
if (mine) {
if (mine.body !== text) {
await github.rest.issues.updateComment({ owner, repo, comment_id: mine.id, body: text });
}
} else {
await github.rest.issues.createComment({ owner, repo, issue_number: number, body: text });
}
const toAdd = [LABEL, "stale"].filter(name => !prLabels.includes(name));
if (toAdd.length > 0) {
await github.rest.issues.addLabels({ owner, repo, issue_number: number, labels: toAdd });
}
core.setFailed("Requirements check: " + problems.length + " item(s) missing.");