Skip to content
Open
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
13 changes: 13 additions & 0 deletions .github/workflow-scripts/__tests__/extractIssueOncalls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('extractIssueOncalls', () => {
});

afterEach(() => {
jest.restoreAllMocks();
jest.useRealTimers();
});
it('extracts m and f on 6 of April', () => {
Expand Down Expand Up @@ -80,4 +81,16 @@ describe('extractIssueOncalls', () => {
const oncalls = extractIssueOncalls(schedule, userMap);
expect(oncalls).toEqual([userMap['@g'], userMap['@d']]);
});

it('continues the latest rotation after the schedule ends', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.setSystemTime(new Date(2025, 3, 15));

const oncalls = extractIssueOncalls(schedule, userMap);

expect(oncalls).toEqual([userMap['@g'], userMap['@d']]);
expect(warn).toHaveBeenCalledWith(
'No issue oncall schedule found for 2025-04-15; continuing the rotation from 2025-04-08',
);
});
});
21 changes: 19 additions & 2 deletions .github/workflow-scripts/extractIssueOncalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ function extractUsersFromScheduleAndDate(schedule, userMap, date) {
const month = date.getMonth() + 1; // 0 is January, 1 is February
const day = date.getDate();
const dateStr = `${year}-${month < 10 ? `0${month}` : month}-${day < 10 ? `0${day}` : day}`;
const user1 = userMap[schedule[dateStr][0]];
const user2 = userMap[schedule[dateStr][1]];
const scheduledDate = Object.keys(schedule)
.filter(candidateDate => candidateDate <= dateStr)
.sort()
.at(-1);

if (scheduledDate == null) {
throw new Error(`No issue oncall schedule found on or before ${dateStr}`);
}

if (scheduledDate !== dateStr) {
console.warn(
`No issue oncall schedule found for ${dateStr}; continuing the rotation from ${scheduledDate}`,
);
}

const user1 = userMap[schedule[scheduledDate][0]];
const user2 = userMap[schedule[scheduledDate][1]];
return [user1, user2];
}

Expand All @@ -47,6 +62,8 @@ function extractUsersFromScheduleAndDate(schedule, userMap, date) {
* }
* ```
*
* Each dated entry stays active until a newer entry takes effect.
*
* When uploading the secret, make sure that the JSON strings are escaped!
* The script will fail otherwise, because GitHub will remove the `"` characters.
*/
Expand Down
Loading