ci/github-script/merge: improve merge operation and error messages (#458412)

This commit is contained in:
Wolfgang Walther
2025-11-04 19:54:02 +00:00
committed by GitHub
2 changed files with 93 additions and 61 deletions
+43
View File
@@ -96,6 +96,47 @@ module.exports = async ({ github, context, core, dry }) => {
return maintainerMaps[branch]
}
// Caching the list of team members saves API requests when running the bot on the schedule and
// processing many PRs at once.
const members = {}
function getTeamMembers(team_slug) {
if (context.eventName === 'pull_request') {
// We have no chance of getting a token in the pull_request context with the right
// permissions to access the members endpoint below. Thus, we're pretending to have
// no members. This is OK; because this is only for the Test workflow, not for
// real use.
return []
}
if (!members[team_slug]) {
members[team_slug] = github.paginate(github.rest.teams.listMembersInOrg, {
org: context.repo.owner,
team_slug,
per_page: 100,
})
}
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}`)
@@ -121,6 +162,8 @@ module.exports = async ({ github, context, core, dry }) => {
pull_request,
events,
maintainers,
getTeamMembers,
getUser,
})
// When the same change has already been merged to the target branch, a PR will still be