diff --git a/ci/github-script/bot.js b/ci/github-script/bot.js index 2c3bd45f69e5..133a6881d235 100644 --- a/ci/github-script/bot.js +++ b/ci/github-script/bot.js @@ -119,6 +119,24 @@ module.exports = async ({ github, context, core, dry }) => { return members[team_slug] } + // Caching users saves API requests when running the bot on the schedule and processing + // many PRs at once. It also helps to encapsulate the special logic we need, because + // actions/github doesn't support that endpoint fully, yet. + const users = {} + function getUser(id) { + if (!users[id]) { + users[id] = github + .request({ + method: 'GET', + url: '/user/{id}', + id, + }) + .then((resp) => resp.data) + } + + return users[id] + } + async function handlePullRequest({ item, stats, events }) { const log = (k, v) => core.info(`PR #${item.number} - ${k}: ${v}`) @@ -145,6 +163,7 @@ module.exports = async ({ github, context, core, dry }) => { events, maintainers, getTeamMembers, + getUser, }) // When the same change has already been merged to the target branch, a PR will still be diff --git a/ci/github-script/merge.js b/ci/github-script/merge.js index 8a6789a30544..688a7928fe97 100644 --- a/ci/github-script/merge.js +++ b/ci/github-script/merge.js @@ -80,6 +80,7 @@ function runChecklist({ return { checklist, + eligible, result, } } @@ -119,6 +120,7 @@ async function handleMerge({ events, maintainers, getTeamMembers, + getUser, }) { const pull_number = pull_request.number @@ -240,7 +242,7 @@ async function handleMerge({ } } - const { result, checklist } = runChecklist({ + const { result, eligible, checklist } = runChecklist({ committers, events, files, @@ -270,6 +272,18 @@ async function handleMerge({ '', ] + if (eligible.size > 0 && !eligible.has(comment.user.id)) { + const users = await Promise.all( + Array.from(eligible, async (id) => (await getUser(id)).login), + ) + body.push( + '> [!TIP]', + '> Maintainers eligible to merge are:', + ...users.map((login) => `> - ${login}`), + '', + ) + } + if (result) { await react('ROCKET') try {