Skip to content

Commit b342e14

Browse files
committed
Fix issue oncall schedule expiry
1 parent 99d327c commit b342e14

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎.github/workflow-scripts/__tests__/extractIssueOncalls-test.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('extractIssueOncalls', () => {
3131
});
3232

3333
afterEach(() => {
34+
jest.restoreAllMocks();
3435
jest.useRealTimers();
3536
});
3637
it('extracts m and f on 6 of April', () => {
@@ -80,4 +81,16 @@ describe('extractIssueOncalls', () => {
8081
const oncalls = extractIssueOncalls(schedule, userMap);
8182
expect(oncalls).toEqual([userMap['@g'], userMap['@d']]);
8283
});
84+
85+
it('continues the latest rotation after the schedule ends', () => {
86+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
87+
jest.setSystemTime(new Date(2025, 3, 15));
88+
89+
const oncalls = extractIssueOncalls(schedule, userMap);
90+
91+
expect(oncalls).toEqual([userMap['@g'], userMap['@d']]);
92+
expect(warn).toHaveBeenCalledWith(
93+
'No issue oncall schedule found for 2025-04-15; continuing the rotation from 2025-04-08',
94+
);
95+
});
8396
});

‎.github/workflow-scripts/extractIssueOncalls.js‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,23 @@ function extractUsersFromScheduleAndDate(schedule, userMap, date) {
2020
const month = date.getMonth() + 1; // 0 is January, 1 is February
2121
const day = date.getDate();
2222
const dateStr = `${year}-${month < 10 ? `0${month}` : month}-${day < 10 ? `0${day}` : day}`;
23-
const user1 = userMap[schedule[dateStr][0]];
24-
const user2 = userMap[schedule[dateStr][1]];
23+
const scheduledDate = Object.keys(schedule)
24+
.filter(candidateDate => candidateDate <= dateStr)
25+
.sort()
26+
.at(-1);
27+
28+
if (scheduledDate == null) {
29+
throw new Error(`No issue oncall schedule found on or before ${dateStr}`);
30+
}
31+
32+
if (scheduledDate !== dateStr) {
33+
console.warn(
34+
`No issue oncall schedule found for ${dateStr}; continuing the rotation from ${scheduledDate}`,
35+
);
36+
}
37+
38+
const user1 = userMap[schedule[scheduledDate][0]];
39+
const user2 = userMap[schedule[scheduledDate][1]];
2540
return [user1, user2];
2641
}
2742

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

0 commit comments

Comments
 (0)