A local-first personal finance app
count points script should fetch the release note from the PR directly (#7309)
Matt Fiddamana729b9a4a05a
diff --git a/.github/scripts/count-points.mjs b/.github/scripts/count-points.mjsindex 8ef9a9c5d9..5314b40f11 100644--- a/.github/scripts/count-points.mjs+++ b/.github/scripts/count-points.mjs@@ -61,78 +61,29 @@ function parseReleaseNotesCategory(content) {return categoryMatch[1].trim();}-/**- * Get the last commit SHA on or before a given date.- * @param {Octokit} octokit - The Octokit instance.- * @param {string} owner - Repository owner.- * @param {string} repo - Repository name.- * @param {Date} beforeDate - The date to find the last commit before.- * @returns {Promise<string|null>} The commit SHA or null if not found.- */-async function getLastCommitBeforeDate(octokit, owner, repo, beforeDate) {- try {- // Get the default branch from the repository- const { data: repoData } = await octokit.repos.get({ owner, repo });- const defaultBranch = repoData.default_branch;-- const { data: commits } = await octokit.repos.listCommits({- owner,- repo,- sha: defaultBranch,- until: beforeDate.toISOString(),- per_page: 1,- });-- if (commits.length > 0) {- return commits[0].sha;- }- } catch {- // If error occurs, return null to fall back to default branch- }-- return null;-}-/*** Get the category and points for a PR by reading its release notes file.* @param {Octokit} octokit - The Octokit instance.* @param {string} owner - Repository owner.* @param {string} repo - Repository name.- * @param {number} prNumber - PR number.- * @param {Date} monthEnd - The end date of the month to use as base revision.- * @returns {Promise<Object>} Object with category and points, or null if error.+ * @param {string|null} releaseNoteBlobSha - The blob SHA of the release notes file, or null if not found.+ * @returns {Promise<Object>} Object with category and points.*/async function getPRCategoryAndPoints(octokit,owner,repo,- prNumber,- monthEnd,+ releaseNoteBlobSha,) {- const releaseNotesPath = `upcoming-release-notes/${prNumber}.md`;-try {- // Get the last commit of the month to use as base revision- const commitSha = await getLastCommitBeforeDate(- octokit,- owner,- repo,- monthEnd,- );-- // Try to read the release notes file from the last commit of the month- const { data: fileContent } = await octokit.repos.getContent({- owner,- repo,- path: releaseNotesPath,- ref: commitSha || undefined, // Use commit SHA if available, otherwise default branch- });-- if (fileContent.content) {- // Decode base64 content- const content = Buffer.from(fileContent.content, 'base64').toString(- 'utf-8',- );+ if (releaseNoteBlobSha) {+ const { data: blob } = await octokit.git.getBlob({+ owner,+ repo,+ file_sha: releaseNoteBlobSha,+ });++ const content = Buffer.from(blob.content, 'base64').toString('utf-8');const category = parseReleaseNotesCategory(content);const tier = CONFIG.PR_CONTRIBUTION_POINTS.find(e =>e.categories.includes(category),@@ -345,12 +296,15 @@ async function countContributorPoints() {// Award points to PR author if they are a core maintainerconst prAuthor = pr.user?.login;if (prAuthor && orgMemberLogins.has(prAuthor)) {+ const releaseNoteFile = modifiedFiles.find(+ file =>+ file.filename === `upcoming-release-notes/${pr.number}.md`,+ );const categoryAndPoints = await getPRCategoryAndPoints(octokit,owner,repo,- pr.number,- until,+ releaseNoteFile?.sha ?? null,);if (categoryAndPoints) {diff --git a/upcoming-release-notes/7309.md b/upcoming-release-notes/7309.mdnew file mode 100644index 0000000000..cf87fbfa56--- /dev/null+++ b/upcoming-release-notes/7309.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [matt-fidd]+---++Change maintainer points counting script to fetch the release note from the PR directly