From 239a0875422de2a9b5eca0c2e481427f454dd2cb Mon Sep 17 00:00:00 2001 From: Michael Clark <5285928+MikesGlitch@users.noreply.github.com> Date: Sat, 2 Aug 2025 17:33:18 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Paginate=20the=20count=20poin?= =?UTF-8?q?ts=20list=20files=20call=20(#5448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * paginate the count points list files call * fix tier assignment * paginate the count points list files call * fix tier assignment * ensure utc dates and fix issue filtering to include issues updated in other months --- .github/scripts/count-points.mjs | 86 +++++++++++++++++--------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/.github/scripts/count-points.mjs b/.github/scripts/count-points.mjs index ebdb2d949c..09cb6b0872 100644 --- a/.github/scripts/count-points.mjs +++ b/.github/scripts/count-points.mjs @@ -46,24 +46,25 @@ const REPOSITORY_CONFIG = new Map([ function getLastMonthDates() { // Get data relating to the last month const now = new Date(); + // Always use UTC for calculations const firstDayOfLastMonth = new Date( - now.getFullYear(), - now.getMonth() - 1, - 1, + Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1, 0, 0, 0, 0), ); const since = process.env.START_DATE - ? new Date(process.env.START_DATE) + ? new Date(Date.parse(process.env.START_DATE)) : firstDayOfLastMonth; - // Calculate the end of the month for the since date + // Calculate the end of the month for the since date in UTC const until = new Date( - since.getFullYear(), - since.getMonth() + 1, - 0, - 23, - 59, - 59, - 999, + Date.UTC( + since.getUTCFullYear(), + since.getUTCMonth() + 1, + 0, + 23, + 59, + 59, + 999, + ), ); return { since, until }; @@ -76,7 +77,9 @@ function getLastMonthDates() { * @returns {number} The total points earned for the repository */ async function countContributorPoints(repo) { - const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); + const octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN, + }); const owner = 'actualbudget'; const config = REPOSITORY_CONFIG.get(repo); @@ -140,12 +143,17 @@ async function countContributorPoints(repo) { pull_number: pr.number, }); - // Get list of modified files - const { data: modifiedFiles } = await octokit.pulls.listFiles({ - owner, - repo, - pull_number: pr.number, - }); + // Get list of modified files with pagination + const modifiedFiles = await octokit.paginate( + octokit.pulls.listFiles, + { + owner, + repo, + pull_number: pr.number, + per_page: 100, // Maximum allowed by GitHub API + }, + response => response.data, + ); // Calculate points based on PR size, excluding specified files const totalChanges = modifiedFiles @@ -162,7 +170,7 @@ async function countContributorPoints(repo) { // Calculate points for reviewers based on PR size const prPoints = - config.PR_REVIEW_POINT_TIERS.find(tier => totalChanges > tier.minChanges) + config.PR_REVIEW_POINT_TIERS.find(tier => totalChanges >= tier.minChanges) ?.points ?? 0; // Award points to the PR creator if it's a release PR @@ -197,20 +205,15 @@ async function countContributorPoints(repo) { } // Get all issues with label events in the last month - const issues = await octokit.paginate( - octokit.issues.listForRepo, - { - owner, - repo, - state: 'all', - sort: 'updated', - direction: 'desc', - per_page: 100, - since: since.toISOString(), - }, - (response, done) => - response.data.filter(issue => new Date(issue.updated_at) <= until), - ); + const issues = await octokit.paginate(octokit.issues.listForRepo, { + owner, + repo, + state: 'all', + sort: 'updated', + direction: 'desc', + per_page: 100, + since: since.toISOString(), + }); // Get label events for each issue for (const issue of issues) { @@ -222,12 +225,15 @@ async function countContributorPoints(repo) { // Process events events - .filter( - event => - new Date(event.created_at) > since && - new Date(event.created_at) <= until && - stats.has(event.actor?.login), - ) + .filter(event => { + // Always compare UTC times + const createdAt = new Date(event.created_at); + return ( + createdAt.getTime() > since.getTime() && + createdAt.getTime() <= until.getTime() && + stats.has(event.actor?.login) + ); + }) .forEach(event => { if ( event.event === 'unlabeled' &&