From 57c83b8053be33a7f55b38f2b27c72f2637e15cc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 2 Mar 2026 16:06:12 -1000 Subject: [PATCH 1/2] dry --- .github/scripts/auto-label-pr/detectors.js | 18 ++++-------- .../workflows/codeowner-review-request.yml | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.github/scripts/auto-label-pr/detectors.js b/.github/scripts/auto-label-pr/detectors.js index 527a08da85..e517f8747f 100644 --- a/.github/scripts/auto-label-pr/detectors.js +++ b/.github/scripts/auto-label-pr/detectors.js @@ -7,7 +7,7 @@ const { hasDashboardChanges, hasGitHubActionsChanges, } = require('../detect-tags'); -const { fetchCodeowners } = require('../codeowners'); +const { fetchCodeowners, getEffectiveOwners } = require('../codeowners'); // Strategy: Merge branch detection async function detectMergeBranch(context) { @@ -155,18 +155,10 @@ async function detectCodeOwner(github, context, changedFiles) { const codeownersPatterns = await fetchCodeowners(github, owner, repo); const prAuthor = context.payload.pull_request.user.login; - // Check if PR author is a codeowner of any changed file (last-match-wins) - for (const file of changedFiles) { - let effectiveOwners = null; - for (const { regex, owners } of codeownersPatterns) { - if (regex.test(file)) { - effectiveOwners = owners; - } - } - if (effectiveOwners && effectiveOwners.some(o => o === `@${prAuthor}`)) { - labels.add('by-code-owner'); - return labels; - } + // Check if PR author is a codeowner of any changed file + const effective = getEffectiveOwners(changedFiles, codeownersPatterns); + if (effective.users.has(prAuthor)) { + labels.add('by-code-owner'); } } catch (error) { console.log('Failed to read or parse CODEOWNERS file:', error.message); diff --git a/.github/workflows/codeowner-review-request.yml b/.github/workflows/codeowner-review-request.yml index abe90836f7..02bf0e4a29 100644 --- a/.github/workflows/codeowner-review-request.yml +++ b/.github/workflows/codeowner-review-request.yml @@ -45,12 +45,15 @@ jobs: const BOT_COMMENT_MARKER = ''; try { - // Get the list of changed files in this PR - const { data: files } = await github.rest.pulls.listFiles({ - owner, - repo, - pull_number: pr_number - }); + // Get the list of changed files in this PR (with pagination) + const files = await github.paginate( + github.rest.pulls.listFiles, + { + owner, + repo, + pull_number: pr_number + } + ); const changedFiles = files.map(file => file.filename); console.log(`Found ${changedFiles.length} changed files`); @@ -116,11 +119,14 @@ jobs: } // Check for completed reviews to avoid re-requesting users who have already reviewed - const { data: reviews } = await github.rest.pulls.listReviews({ - owner, - repo, - pull_number: pr_number - }); + const reviews = await github.paginate( + github.rest.pulls.listReviews, + { + owner, + repo, + pull_number: pr_number + } + ); const reviewedUsers = new Set(); reviews.forEach(review => { From 1f270ce1d1e7f8b0ba4467a2cfc68642daccd339 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 2 Mar 2026 16:10:02 -1000 Subject: [PATCH 2/2] dry --- .github/scripts/auto-label-pr/detectors.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/scripts/auto-label-pr/detectors.js b/.github/scripts/auto-label-pr/detectors.js index e517f8747f..832fcb41db 100644 --- a/.github/scripts/auto-label-pr/detectors.js +++ b/.github/scripts/auto-label-pr/detectors.js @@ -7,7 +7,7 @@ const { hasDashboardChanges, hasGitHubActionsChanges, } = require('../detect-tags'); -const { fetchCodeowners, getEffectiveOwners } = require('../codeowners'); +const { loadCodeowners, getEffectiveOwners } = require('../codeowners'); // Strategy: Merge branch detection async function detectMergeBranch(context) { @@ -149,10 +149,9 @@ async function detectGitHubActionsChanges(changedFiles) { // Strategy: Code owner detection async function detectCodeOwner(github, context, changedFiles) { const labels = new Set(); - const { owner, repo } = context.repo; try { - const codeownersPatterns = await fetchCodeowners(github, owner, repo); + const codeownersPatterns = loadCodeowners(); const prAuthor = context.payload.pull_request.user.login; // Check if PR author is a codeowner of any changed file