From d0a648c6b6f82afc1d3fe33cad11dba757478cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=B9d=C5=8Dng=20Y=C3=A1ng?= Date: Tue, 17 Sep 2024 23:49:05 +0200 Subject: [PATCH 1/2] BCR PR reviewer: add support for a "doNotNotify" field A maintainer can request to not be notified by new PRs by setting `"doNotNotify": true`. In this case, they can still approve the PR and have it count, but they won't be pinged. This helps in situations like protobuf's release rotation, which has a lot of people but ideally only the releaser should be notified and be able to approve the PR. It's rather hard to support a "rotating" maintainer model, though. Thus we compromise by adding everyone from that rotation as a "do-not-notify" maintainer, and asking the releaser to watch out for the PR manually as a release step. --- actions/bcr-pr-reviewer/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/actions/bcr-pr-reviewer/index.js b/actions/bcr-pr-reviewer/index.js index 0fcb4917d7..63a9e741be 100644 --- a/actions/bcr-pr-reviewer/index.js +++ b/actions/bcr-pr-reviewer/index.js @@ -29,7 +29,7 @@ async function fetchAllModifiedModules(octokit, owner, repo, prNumber) { return accumulate; } -async function generateMaintainersMap(octokit, owner, repo, modifiedModules) { +async function generateMaintainersMap(octokit, owner, repo, modifiedModules, toNotifyOnly) { const maintainersMap = new Map(); // Map: maintainer GitHub username -> Set of module they maintain const modulesWithoutGithubMaintainers = new Set(); // Set of module names without module maintainers for (const moduleName of modifiedModules) { @@ -45,7 +45,8 @@ async function generateMaintainersMap(octokit, owner, repo, modifiedModules) { const metadata = JSON.parse(Buffer.from(metadataContent.content, 'base64').toString('utf-8')); let hasGithubMaintainer = false; metadata.maintainers.forEach(maintainer => { - if (maintainer.github) { // Check if the github field is specified + // Only add maintainers with a github handle set. When `toNotifyOnly`, also exclude those who have set "doNotNotify" + if (maintainer.github && !(toNotifyOnly && maintainer.doNotNotify)) { hasGithubMaintainer = true; if (!maintainersMap.has(maintainer.github)) { maintainersMap.set(maintainer.github, new Set()); @@ -256,7 +257,7 @@ async function reviewPR(octokit, owner, repo, prNumber) { } // Figure out maintainers for each modified module - const [ maintainersMap, modulesWithoutGithubMaintainers ] = await generateMaintainersMap(octokit, owner, repo, modifiedModules); + const [ maintainersMap, modulesWithoutGithubMaintainers ] = await generateMaintainersMap(octokit, owner, repo, modifiedModules, /* toNotifyOnly= */ false); console.log('Maintainers Map:'); for (const [maintainer, maintainedModules] of maintainersMap.entries()) { console.log(`- Maintainer: ${maintainer}, Modules: ${Array.from(maintainedModules).join(', ')}`); @@ -332,7 +333,7 @@ async function runNotifier(octokit) { console.log(`Modified modules: ${Array.from(modifiedModules).join(', ')}`); // Figure out maintainers for each modified module - const [ maintainersMap, modulesWithoutGithubMaintainers ] = await generateMaintainersMap(octokit, owner, repo, modifiedModules); + const [ maintainersMap, modulesWithoutGithubMaintainers ] = await generateMaintainersMap(octokit, owner, repo, modifiedModules, /* toNotifyOnly= */ true); // Notify maintainers for modules with module maintainers await notifyMaintainers(octokit, owner, repo, prNumber, maintainersMap); From 0a6d4b2d599a6bb0ed91c5dc626378aa1f14deaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=B9d=C5=8Dng=20Y=C3=A1ng?= Date: Tue, 17 Sep 2024 23:52:27 +0200 Subject: [PATCH 2/2] "doNotNotify" -> "do_not_notify" metadata.json already has the field "yanked_versions" using lower snake case, so I updated this field to follow suit. --- actions/bcr-pr-reviewer/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/bcr-pr-reviewer/index.js b/actions/bcr-pr-reviewer/index.js index 63a9e741be..21369c2f64 100644 --- a/actions/bcr-pr-reviewer/index.js +++ b/actions/bcr-pr-reviewer/index.js @@ -45,8 +45,8 @@ async function generateMaintainersMap(octokit, owner, repo, modifiedModules, toN const metadata = JSON.parse(Buffer.from(metadataContent.content, 'base64').toString('utf-8')); let hasGithubMaintainer = false; metadata.maintainers.forEach(maintainer => { - // Only add maintainers with a github handle set. When `toNotifyOnly`, also exclude those who have set "doNotNotify" - if (maintainer.github && !(toNotifyOnly && maintainer.doNotNotify)) { + // Only add maintainers with a github handle set. When `toNotifyOnly`, also exclude those who have set "do_not_notify" + if (maintainer.github && !(toNotifyOnly && maintainer["do_not_notify"])) { hasGithubMaintainer = true; if (!maintainersMap.has(maintainer.github)) { maintainersMap.set(maintainer.github, new Set());