mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
890b8f7ea3
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50526 This change wants to automate the rotation of the issue triaging squad on Discord. This is taking us a few minutes every week to rotate the oncall. This change can save us some time. The configuration file format is supposed to be like this: ``` { "userMap": { "discord-username1": "discord-id1", "discord-username2": "discord-id2", "discord-username3": "discord-id3", "discord-username4": "discord-id4" }, "schedule": { "date1": ["discord-username1", "discord-username2"], "date2": ["discord-username3", "discord-username4"], } } ``` ## Changelog [Internal] - Automate the issue triage oncall rotation Reviewed By: cortinico Differential Revision: D72569435 fbshipit-source-id: 435c13350cf503e99302775674e78a20e328e68d
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
|
|
const MSEC_IN_DAY = 1000 * 60 * 60 * 24;
|
|
|
|
function formatUsers(users) {
|
|
console.log(`${users[0]} ${users[1]}`.trim());
|
|
}
|
|
|
|
function extractUsersFromScheduleAndDate(schedule, userMap, date) {
|
|
const year = date.getFullYear();
|
|
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]];
|
|
return [user1, user2];
|
|
}
|
|
|
|
function main() {
|
|
const configuration = process.argv[2];
|
|
const {userMap, schedule} = JSON.parse(configuration);
|
|
extractIssueOncalls(schedule, userMap);
|
|
}
|
|
|
|
function extractIssueOncalls(schedule, userMap) {
|
|
const now = new Date();
|
|
const dayOfTheWeek = now.getDay(); // 0 is Sunday, 1 is Monday, etc.
|
|
let users;
|
|
if (dayOfTheWeek === 2) {
|
|
// exact match in the schedule
|
|
users = extractUsersFromScheduleAndDate(schedule, userMap, now);
|
|
} else if (dayOfTheWeek < 2) {
|
|
// sunday
|
|
// go to the tuesday of the last week
|
|
const lastWeekTuesday = new Date(now - (5 + dayOfTheWeek) * MSEC_IN_DAY);
|
|
users = extractUsersFromScheduleAndDate(schedule, userMap, lastWeekTuesday);
|
|
} else if (dayOfTheWeek > 1) {
|
|
// go to the previous tuesday
|
|
const thisWeekTuesday = new Date(now - (dayOfTheWeek - 2) * MSEC_IN_DAY);
|
|
users = extractUsersFromScheduleAndDate(schedule, userMap, thisWeekTuesday);
|
|
}
|
|
formatUsers(users);
|
|
return users;
|
|
}
|
|
|
|
if (require.main === module) {
|
|
void main();
|
|
}
|
|
|
|
module.exports = {
|
|
extractIssueOncalls,
|
|
};
|