Skip to content

Commit 026df55

Browse files
committed
Refactor Plus Code handling and update related tests for event issue processing
1 parent 198b4f7 commit 026df55

6 files changed

Lines changed: 59 additions & 17 deletions

.github/scripts/event-issue-helpers.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ export const VALID_ORG_TYPES = new Set([
1616

1717
export const VALID_EVENT_FORMATS = new Set(['In person', 'Online']);
1818

19+
// Historical aliases in newest-first order (covers retried or edited older issues)
20+
export const PLUS_CODE_FIELD_ALIASES = [
21+
'Plus Code (for map placement)', // current
22+
'Plus Code for map placement', // transitional (commit 24064d2)
23+
'Map placement', // original
24+
];
25+
26+
export const PLUS_CODE_FIELD_LABEL = PLUS_CODE_FIELD_ALIASES[0];
27+
28+
// Like required(), but tries each label in order and returns the first non-empty value.
29+
export function requiredAny(fields, labels, errors, errorOverride) {
30+
for (const label of labels) {
31+
const v = fields.get(label)?.trim();
32+
if (v) return v;
33+
}
34+
errors.push(errorOverride ?? { field: labels[0], message: 'This field is required.' });
35+
return '';
36+
}
37+
1938
export function parseIssueSections(body) {
2039
const normalized = body.replace(/\r/g, '');
2140
const sections = normalized.split(/^### /m).slice(1);

.github/scripts/process-edit-event-issue.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
PCD_CONTACT_EMAIL,
88
VALID_ORG_TYPES,
99
VALID_EVENT_FORMATS,
10+
PLUS_CODE_FIELD_ALIASES,
1011
parseIssueSections,
1112
required,
13+
requiredAny,
1214
isValidDate,
1315
isValidTime,
1416
isValidEmail,
@@ -90,7 +92,7 @@ async function main() {
9092

9193
const canonicalId = required(fields, 'Event canonical ID', errors);
9294
const eventName = required(fields, 'Event name', errors);
93-
const rawPlusCode = required(fields, 'Map placement', errors, {
95+
const rawPlusCode = requiredAny(fields, PLUS_CODE_FIELD_ALIASES, errors, {
9496
field: 'Map placement (Plus Code)',
9597
message: 'This field is required. A Plus Code looks like `8FW4V75V+8Q`. [Find your Plus Code →](https://plus.codes/)',
9698
});

.github/scripts/process-edit-event-issue.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function makeValidEditBody({
7777
'### Forum discussion URL',
7878
forumThreadUrl,
7979
'',
80-
'### Map placement',
80+
'### Plus Code (for map placement)',
8181
plusCode,
8282
'',
8383
'### Event format',
@@ -257,7 +257,7 @@ describe('process-edit-event-issue', () => {
257257
});
258258

259259
test('missing ### Event canonical ID heading causes valid=skip', async () => {
260-
const body = '### Event name\nPCD @ Test\n### Map placement\n8FW4V75V+8Q\n';
260+
const body = '### Event name\nPCD @ Test\n### Plus Code (for map placement)\n8FW4V75V+8Q\n';
261261
const { outputs } = await runScript(body, { tmpDir, number: 15 });
262262
assert.equal(outputs.valid, 'skip');
263263
});

.github/scripts/process-new-event-issue.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import {
77
PCD_CONTACT_EMAIL,
88
VALID_ORG_TYPES,
99
VALID_EVENT_FORMATS,
10+
PLUS_CODE_FIELD_LABEL,
11+
PLUS_CODE_FIELD_ALIASES,
1012
parseIssueSections,
1113
required,
14+
requiredAny,
1215
isValidDate,
1316
isValidTime,
1417
isValidEmail,
@@ -79,16 +82,17 @@ function buildPrBody(number, name, submitterLogin, isOnlineEvent, eventDate, sta
7982

8083
console.log(`[process-new-event-issue] issue #${issueNumber}, body length: ${issueBody.length}`);
8184

82-
// Skip if this is an edit-event issue (has ### Event ID heading)
83-
if (issueBody.includes('### Event ID')) {
84-
console.log('[process-new-event-issue] found ### Event ID heading — skipping (this is an edit event issue)');
85+
// Skip if this is an edit-event issue (has ### Event canonical ID heading)
86+
if (issueBody.includes('### Event canonical ID')) {
87+
console.log('[process-new-event-issue] found ### Event canonical ID heading — skipping (this is an edit event issue)');
8588
await setOutput('valid', 'skip');
8689
process.exit(0);
8790
}
8891

89-
// GitHub strips HTML comments from markdown blocks, so we detect the template
90-
// by checking for a heading that is unique to the new-event issue form.
91-
if (!issueBody.includes('### Map placement')) {
92+
// GitHub strips HTML comments from markdown blocks. The edit-event guard above
93+
// handles the only other template that uses this heading, so reaching here means
94+
// we are processing a new-event issue or something unrecognized.
95+
if (!issueBody.includes(`### ${PLUS_CODE_FIELD_LABEL}`)) {
9296
console.log('[process-new-event-issue] template headings not found — skipping (not a new event issue)');
9397
await setOutput('valid', 'skip');
9498
process.exit(0);
@@ -99,7 +103,7 @@ async function main() {
99103
const errors = [];
100104

101105
const eventName = required(fields, 'Event name', errors);
102-
const rawPlusCode = required(fields, 'Map placement', errors, {
106+
const rawPlusCode = requiredAny(fields, PLUS_CODE_FIELD_ALIASES, errors, {
103107
field: 'Map placement (Plus Code)',
104108
message: 'This field is required. A Plus Code looks like `8FW4V75V+8Q`. [Find your Plus Code →](https://plus.codes/)',
105109
});

.github/scripts/process-new-event-issue.test.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function makeValidBody({
4949
'### Event name',
5050
eventName,
5151
'',
52-
'### Map placement',
52+
'### Plus Code (for map placement)',
5353
plusCode,
5454
'',
5555
'### Event format',
@@ -251,15 +251,31 @@ describe('process-new-event-issue', () => {
251251
}
252252
});
253253

254-
test('issue body with ### Event ID heading causes valid=skip', async () => {
255-
const body = makeValidBody() + '\n### Event ID\npcd-some-event-2026\n';
254+
test('issue body with ### Event canonical ID heading causes valid=skip', async () => {
255+
const body = makeValidBody() + '\n### Event canonical ID\npcd-some-event-2026-abc1234\n';
256256
const { outputs } = await runScript(body, { tmpDir, eventsDir, number: 4 });
257257
assert.equal(outputs.valid, 'skip');
258258
});
259259

260-
test('issue body missing ### Map placement heading causes valid=skip', async () => {
260+
test('issue body missing ### Plus Code (for map placement) heading causes valid=skip', async () => {
261261
const body = '### Event name\nPCD @ Nowhere\n### Some other heading\nvalue\n';
262262
const { outputs } = await runScript(body, { tmpDir, eventsDir, number: 5 });
263263
assert.equal(outputs.valid, 'skip');
264264
});
265+
266+
test('edit-event issue body (with ### Event canonical ID) causes valid=skip on new-event script', async () => {
267+
const body = [
268+
'### Event canonical ID',
269+
'pcd-some-event-2026-abc1234',
270+
'',
271+
'### Event name',
272+
'PCD @ Some City',
273+
'',
274+
'### Plus Code (for map placement)',
275+
'8FW4V75V+8Q',
276+
'',
277+
].join('\n');
278+
const { outputs } = await runScript(body, { tmpDir, eventsDir, number: 6 });
279+
assert.equal(outputs.valid, 'skip');
280+
});
265281
});

TEST.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ These tests cover the shared pure functions extracted into `event-issue-helpers.
3333
| Valid new-event issue body | `valid=true`, writes `metadata.json` with all fields including `uid` (7 hex chars) |
3434
| `Event page URL` field present | Value appears in `metadata.json` as `event_page_url` (regression for the `Event website` field-name bug) |
3535
| Duplicate event directory | `valid=false`, validation comment mentions the generated id |
36-
| Issue body contains `### Event ID` heading | `valid=skip` (guard against running on edit-event template) |
37-
| Issue body missing `### Map placement` and no `### Event ID` | `valid=skip` (unrecognized template) |
36+
| Issue body contains `### Event canonical ID` heading | `valid=skip` (guard against running on edit-event template) |
37+
| Edit-event issue body (contains `### Event canonical ID` and `### Plus Code (for map placement)`) | `valid=skip` (regression: edit-event body must not be processed as new event) |
38+
| Issue body missing `### Plus Code (for map placement)` and no `### Event canonical ID` | `valid=skip` (unrecognized template) |
3839

3940
---
4041

@@ -51,7 +52,7 @@ These tests cover the shared pure functions extracted into `event-issue-helpers.
5152
| All activities unchecked | Existing `event_activities` preserved (checkbox prefill limitation) |
5253
| Some activities checked | `event_activities` overwritten with checked values |
5354
| Event directory does not exist | `valid=false`, validation comment mentions the missing event id |
54-
| Missing `### Event ID` heading | `valid=skip` (guard against running on new-event template) |
55+
| Missing `### Event canonical ID` heading | `valid=skip` (guard against running on new-event template) |
5556

5657
---
5758

0 commit comments

Comments
 (0)