Skip to content

Commit f6bc71c

Browse files
authored
BCR PR reviewer: notify BCR maintainers on modules with metadata only changes (#2213)
1 parent 148bacc commit f6bc71c

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

actions/bcr-pr-reviewer/index.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { getInput, setFailed } = require('@actions/core');
22
const { context, getOctokit } = require("@actions/github");
33

4-
async function fetchAllModifiedModules(octokit, owner, repo, prNumber) {
4+
async function fetchAllModifiedModuleVersions(octokit, owner, repo, prNumber) {
55
let page = 1;
66
const perPage = 100; // GitHub's max per_page value
77
let accumulate = new Set();
@@ -29,6 +29,34 @@ async function fetchAllModifiedModules(octokit, owner, repo, prNumber) {
2929
return accumulate;
3030
}
3131

32+
async function fetchAllModulesWithMetadataChange(octokit, owner, repo, prNumber) {
33+
let page = 1;
34+
const perPage = 100; // GitHub's max per_page value
35+
let accumulate = new Set();
36+
let response;
37+
38+
do {
39+
response = await octokit.rest.pulls.listFiles({
40+
owner,
41+
repo,
42+
pull_number: prNumber,
43+
per_page: perPage,
44+
page,
45+
});
46+
47+
response.data.forEach(file => {
48+
const match = file.filename.match(/^modules\/([^\/]+)\/metadata\.json/);
49+
if (match) {
50+
accumulate.add(match[1]);
51+
}
52+
});
53+
54+
page++;
55+
} while (response.data.length === perPage);
56+
57+
return accumulate;
58+
}
59+
3260
async function generateMaintainersMap(octokit, owner, repo, modifiedModules, toNotifyOnly) {
3361
const maintainersMap = new Map(); // Map: maintainer GitHub username -> Set of module they maintain
3462
const modulesWithoutGithubMaintainers = new Set(); // Set of module names without module maintainers
@@ -263,7 +291,7 @@ async function reviewPR(octokit, owner, repo, prNumber) {
263291
}
264292

265293
// Fetch modified modules
266-
const modifiedModuleVersions = await fetchAllModifiedModules(octokit, owner, repo, prNumber);
294+
const modifiedModuleVersions = await fetchAllModifiedModuleVersions(octokit, owner, repo, prNumber);
267295
const modifiedModules = new Set(Array.from(modifiedModuleVersions).map(module => module.split('@')[0]));
268296
console.log(`Modified modules: ${Array.from(modifiedModules).join(', ')}`);
269297
if (modifiedModules.size === 0) {
@@ -354,7 +382,7 @@ async function runNotifier(octokit) {
354382
const { owner, repo } = context.repo;
355383

356384
// Fetch modified modules
357-
const modifiedModuleVersions = await fetchAllModifiedModules(octokit, owner, repo, prNumber);
385+
const modifiedModuleVersions = await fetchAllModifiedModuleVersions(octokit, owner, repo, prNumber);
358386
const modifiedModules = new Set(Array.from(modifiedModuleVersions).map(module => module.split('@')[0]));
359387
console.log(`Modified modules: ${Array.from(modifiedModules).join(', ')}`);
360388

@@ -372,6 +400,20 @@ async function runNotifier(octokit) {
372400
`Hello @bazelbuild/bcr-maintainers, modules without existing maintainers (${modulesList}) have been updated in this PR.
373401
Please review the changes. You can view a diff against the previous version in the "Generate module diff" check.`);
374402
}
403+
404+
// Notify BCR maintainers for modules with only metadata.json changes
405+
const allModulesWithMetadataChange = await fetchAllModulesWithMetadataChange(octokit, owner, repo, prNumber);
406+
const modulesWithOnlyMetadataChanges = new Set(
407+
[...allModulesWithMetadataChange].filter(module => !modifiedModules.has(module))
408+
);
409+
410+
if (modulesWithOnlyMetadataChanges.size > 0) {
411+
const modulesList = Array.from(modulesWithOnlyMetadataChanges).join(', ');
412+
console.log(`Notifying @bazelbuild/bcr-maintainers for modules with only metadata.json changes: ${modulesList}`);
413+
await postComment(octokit, owner, repo, prNumber,
414+
`Hello @bazelbuild/bcr-maintainers, modules with only metadata.json changes (${modulesList}) have been updated in this PR.
415+
Please review the changes.`);
416+
}
375417
}
376418

377419
async function waitForDismissApprovalsWorkflow(octokit, owner, repo) {
@@ -516,7 +558,7 @@ async function runDiffModule(octokit) {
516558
const { owner, repo } = context.repo;
517559

518560
// Fetch modified modules
519-
const modifiedModuleVersions = await fetchAllModifiedModules(octokit, owner, repo, prNumber);
561+
const modifiedModuleVersions = await fetchAllModifiedModuleVersions(octokit, owner, repo, prNumber);
520562
console.log(`Modified modules: ${Array.from(modifiedModuleVersions).join(', ')}`);
521563

522564
// Use group if more than one module are modified

0 commit comments

Comments
 (0)