-
Notifications
You must be signed in to change notification settings - Fork 2.9k
263 lines (220 loc) · 9.59 KB
/
validate-new-issue.yml
File metadata and controls
263 lines (220 loc) · 9.59 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Validate New Issue
on:
workflow_call:
# Called by submission-enforcement.yml after cooldown clears,
# or directly on issue edits. The enforcement workflow handles
# missing-label and informal submission detection, so this
# workflow only validates properly-submitted resources.
jobs:
validate-resource:
name: Validate Resource Submission
# Only run on issues with the resource-submission label
if: contains(github.event.issue.labels.*.name, 'resource-submission')
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
scripts/
templates/
THE_RESOURCES_TABLE.csv
pyproject.toml
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub PyYAML requests python-dotenv
- name: Parse and validate submission
id: validate
env:
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHONPATH: ${{ github.workspace }}
run: |
python -m scripts.resources.parse_issue_form --validate 2>&1 | tail -n 1 > validation_result.json
if grep -q '"valid": true' validation_result.json; then
echo "Validation passed!"
else
echo "Validation failed!"
fi
echo "=== Validation Result ==="
python -m json.tool validation_result.json || cat validation_result.json
- name: Remove old validation comments
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
for (const comment of comments.data) {
if (comment.user.type === 'Bot' && comment.body.includes('## 🤖 Validation Results')) {
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: comment.id,
});
}
}
- name: Post validation results
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const validation_result = JSON.parse(fs.readFileSync('validation_result.json', 'utf8'));
let comment_body = '## 🤖 Validation Results\n\n';
if (validation_result.valid) {
comment_body += '✅ **All validation checks passed!**\n\n';
comment_body += 'Your submission is ready for review by a maintainer.\n\n';
comment_body += '### Validated Data:\n';
comment_body += '```json\n';
comment_body += JSON.stringify(validation_result.data, null, 2);
comment_body += '\n```\n';
} else {
comment_body += '❌ **Validation failed**\n\n';
comment_body += 'Please fix the following issues and edit your submission:\n\n';
for (const error of validation_result.errors) {
comment_body += `- ❗ ${error}\n`;
}
if (validation_result.warnings && validation_result.warnings.length > 0) {
comment_body += '\n### Warnings:\n';
for (const warning of validation_result.warnings) {
comment_body += `- ⚠️ ${warning}\n`;
}
}
comment_body += '\n**Note:** You can edit your issue to fix these problems, and validation will run again automatically.';
}
comment_body += '\n\n---\n';
comment_body += '<sub>This comment is automatically updated when you edit the issue.</sub>';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment_body
});
- name: Update issue labels
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const validation_result = JSON.parse(fs.readFileSync('validation_result.json', 'utf8'));
const validation_passed = validation_result.valid;
const { data: issue } = await github.rest.issues.get({
owner,
repo,
issue_number,
});
let labels = issue.labels.map(label => label.name);
labels = labels.filter(label =>
label !== 'validation-passed' &&
label !== 'validation-failed' &&
label !== 'pending-validation'
);
if (validation_passed && labels.includes('changes-requested')) {
labels = labels.filter(label => label !== 'changes-requested');
}
if (validation_passed) {
labels.push('validation-passed');
} else {
labels.push('validation-failed');
}
await github.rest.issues.setLabels({
owner,
repo,
issue_number,
labels,
});
- name: Notify maintainer if changes were made
if: github.event.action == 'edited' && contains(github.event.issue.labels.*.name, 'changes-requested')
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const validation_result = JSON.parse(fs.readFileSync('validation_result.json', 'utf8'));
const issue_number = context.issue.number;
const current_validation_status = validation_result.valid;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
per_page: 100
});
let maintainer = null;
let changesRequestedTime = null;
for (let i = comments.data.length - 1; i >= 0; i--) {
const comment = comments.data[i];
const match = comment.body.match(/## 🔄 Changes Requested by @(\w+)/);
if (match) {
maintainer = match[1];
changesRequestedTime = new Date(comment.created_at);
break;
}
}
if (!maintainer) return;
let lastNotificationTime = null;
let lastNotifiedStatus = null;
let hasNotifiedAfterRequest = false;
for (const comment of comments.data) {
if (comment.body.includes('## 📝 Issue Updated') && comment.user.type === 'Bot') {
const commentTime = new Date(comment.created_at);
if (commentTime > changesRequestedTime) {
hasNotifiedAfterRequest = true;
const metaMatch = comment.body.match(/<!-- notification-meta: status=(\w+) -->/);
if (metaMatch) {
lastNotifiedStatus = metaMatch[1] === 'true';
}
if (!lastNotificationTime || commentTime > lastNotificationTime) {
lastNotificationTime = commentTime;
}
}
}
}
let shouldNotify = false;
let notificationReason = '';
if (!hasNotifiedAfterRequest) {
shouldNotify = true;
notificationReason = 'first edit after changes requested';
} else if (lastNotifiedStatus !== null && lastNotifiedStatus !== current_validation_status) {
shouldNotify = true;
notificationReason = 'validation status changed';
}
if (shouldNotify) {
let notification_body = `## 📝 Issue Updated\n\n`;
notification_body += `@${maintainer} - The submitter has edited their issue in response to your requested changes.\n\n`;
if (current_validation_status) {
notification_body += `✅ **The updated submission now passes all validation checks!**\n\n`;
notification_body += `You may want to review the changes and consider approving the submission.`;
} else {
notification_body += `❌ **The submission still has validation errors.**\n\n`;
notification_body += `The submitter may need additional guidance to fix the remaining issues.`;
}
notification_body += `\n\n<!-- notification-meta: status=${current_validation_status} -->`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: notification_body
});
console.log(`Notification sent (reason: ${notificationReason})`);
} else {
console.log('Skipping notification - no significant changes detected');
}
- name: Cleanup
if: always()
run: |
rm -f validation_result.json