Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstruct times section when the issue body does not have it #110

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions test/check-serialization.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,107 @@ _No response_`;
});


it('adds times section if missing', async function () {
setEnvKey('PROJECT_NUMBER', 'tpac2023');
setEnvKey('ISSUE_TEMPLATE', 'test/data/tpac-template.yml');
const project = await fetchTestProject();
await initSectionHandlers(project);
const initialBody = `### Estimate of in-person participants

16-30`;
const expectedBody = `### Estimate of in-person participants

16-30

### Select preferred dates and times (11-15 September)

- [ ] Monday, 09:30 - 11:00
- [ ] Monday, 11:30 - 13:00
- [ ] Monday, 14:30 - 16:30
- [ ] Monday, 17:00 - 18:30
- [ ] Tuesday, 09:30 - 11:00
- [ ] Tuesday, 11:30 - 13:00
- [ ] Tuesday, 14:30 - 16:30
- [ ] Tuesday, 17:00 - 18:30
- [ ] Thursday, 09:30 - 11:00
- [ ] Thursday, 11:30 - 13:00
- [ ] Thursday, 14:30 - 16:30
- [ ] Thursday, 17:00 - 18:30
- [ ] Friday, 09:30 - 11:00
- [ ] Friday, 11:30 - 13:00
- [ ] Friday, 14:30 - 16:30
- [ ] Friday, 17:00 - 18:30

### Other sessions where we should avoid scheduling conflicts (Optional)

_No response_

### Other instructions for meeting planners (Optional)

_No response_

### Discussion channel (Optional)

_No response_

### Agenda for the meeting.

_No response_`;
const desc = parseSessionBody(initialBody);
const serializedBody = serializeSessionDescription(desc);
assert.strictEqual(serializedBody, expectedBody);
});


it('handles times choices correctly', async function () {
setEnvKey('PROJECT_NUMBER', 'tpac2023');
setEnvKey('ISSUE_TEMPLATE', 'test/data/tpac-template.yml');
const project = await fetchTestProject();
await initSectionHandlers(project);
const initialBody = `### Estimate of in-person participants

16-30

### Select preferred dates and times (11-15 September)

- [ ] Monday, 09:30 - 11:00
- [ ] Monday, 11:30 - 13:00
- [X] Monday, 14:30 - 16:30
- [X] Monday, 17:00 - 18:30
- [ ] Tuesday, 09:30 - 11:00
- [ ] Tuesday, 11:30 - 13:00
- [ ] Tuesday, 14:30 - 16:30
- [ ] Tuesday, 17:00 - 18:30
- [ ] Thursday, 09:30 - 11:00
- [ ] Thursday, 11:30 - 13:00
- [ ] Thursday, 14:30 - 16:30
- [ ] Thursday, 17:00 - 18:30
- [ ] Friday, 09:30 - 11:00
- [ ] Friday, 11:30 - 13:00
- [ ] Friday, 14:30 - 16:30
- [ ] Friday, 17:00 - 18:30

### Other sessions where we should avoid scheduling conflicts (Optional)

_No response_

### Other instructions for meeting planners (Optional)

_No response_

### Discussion channel (Optional)

_No response_

### Agenda for the meeting.

_No response_`;
const desc = parseSessionBody(initialBody);
const serializedBody = serializeSessionDescription(desc);
assert.strictEqual(serializedBody, initialBody);
});


it('parses the discussion URL correctly', async function () {
setEnvKey('PROJECT_NUMBER', 'tpac2023');
setEnvKey('ISSUE_TEMPLATE', 'test/data/tpac-template.yml');
Expand Down
7 changes: 4 additions & 3 deletions tools/lib/session.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export async function initSectionHandlers(project) {
case 'times':
// Each entry looks like "[x] Monday, 09:30 - 11:00"
const reTime = /^\[( |x)\]\s*(?:(monday|tuesday|thursday|friday),\s*(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2}))$/i;
handler.allowEmptyValue = true;
handler.parse = value => parseList(value, { linesOnly: true })
.map(time => {
const match = time.match(reTime);
Expand Down Expand Up @@ -308,7 +309,7 @@ export async function initSectionHandlers(project) {
.flat();
handler.serialize = value => daysAndSlots
.map(ds => {
const time = value.find(time =>
const time = value?.find(time =>
time.day === ds.day.name &&
time.slot === ds.slot.name);
return `- [${time ? 'X' : ' '}] ${ds.day.label}, ${ds.slot.name}`;
Expand Down Expand Up @@ -478,7 +479,7 @@ export function parseSessionBody(body) {
handler.title === section.title);
return {
id: sectionHandler.id,
value: section.value || section.value === 0 ?
value: section.value || section.value === 0 || sectionHandler.allowEmptyValue ?
sectionHandler.parse(section.value) :
null
};
Expand All @@ -502,7 +503,7 @@ export function serializeSessionDescription(description) {
description[handler.id] === 0)
.map(handler => `### ${handler.title}${handler.includeOptional ? ' (Optional)' : ''}

${(description[handler.id] || description[handler.id] === 0) ?
${(description[handler.id] || description[handler.id] === 0 || handler.allowEmptyValue) ?
handler.serialize(description[handler.id]) : '_No response_' }`)
.join('\n\n');
}
Expand Down