diff --git a/.github/scripts/leaderboard.js b/.github/scripts/leaderboard.js index 8db45ba8400..7d044a6fdb0 100644 --- a/.github/scripts/leaderboard.js +++ b/.github/scripts/leaderboard.js @@ -59,9 +59,14 @@ function generateKey(name) { return crypto.createHash('sha256').update(normalized).digest('hex'); } -// Change start and end dates -const startDate = "2024-11-01T00:00:00+00:00"; -const endDate = "2024-11-30T23:59:59+00:00"; +function formatDateToBeginningOfMonth(date) { + const year = date.getFullYear(); + const month = date.getMonth() + 1; // getMonth() is zero-indexed + + return `${year}-${month.toString().padStart(2, '0')}-01T00:00:00+00:00`; +} + +const formattedDate = formatDateToBeginningOfMonth(date); async function getProjectMembers() { try { @@ -85,12 +90,14 @@ async function getProjectMembers() { } } + + async function generateMonthlyReport() { try { const response = await makeRequest('post', `${CONFIG.CROWDIN_API_ENDPOINT}/projects/${CONFIG.CROWDIN_PROJECT_ID}/reports`, { data: { name: "top-members", - schema: { unit: "words", format: "csv", dateFrom: startDate, dateTo: endDate } // Updated date range + schema: { unit: "words", format: "csv", dateFrom: formattedDate } }, headers: { 'Authorization': `Bearer ${CROWDIN_PERSONAL_TOKEN}`, 'Content-Type': 'application/json' } }); @@ -217,4 +224,5 @@ async function saveDataToJson(data, filePath) { } catch (error) { console.error('Error in main function:', error); } -})(); \ No newline at end of file +})(); +