mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-10 09:43:30 +01:00
ci/github-script/bot: move getTeamMembers cache into main file
This allows re-using this elsewhere with a shared cache.
This commit is contained in:
parent
2d6602908b
commit
58a1fe4761
|
|
@ -96,6 +96,29 @@ module.exports = async ({ github, context, core, dry }) => {
|
||||||
return maintainerMaps[branch]
|
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]
|
||||||
|
}
|
||||||
|
|
||||||
async function handlePullRequest({ item, stats, events }) {
|
async function handlePullRequest({ item, stats, events }) {
|
||||||
const log = (k, v) => core.info(`PR #${item.number} - ${k}: ${v}`)
|
const log = (k, v) => core.info(`PR #${item.number} - ${k}: ${v}`)
|
||||||
|
|
||||||
|
|
@ -121,6 +144,7 @@ module.exports = async ({ github, context, core, dry }) => {
|
||||||
pull_request,
|
pull_request,
|
||||||
events,
|
events,
|
||||||
maintainers,
|
maintainers,
|
||||||
|
getTeamMembers,
|
||||||
})
|
})
|
||||||
|
|
||||||
// When the same change has already been merged to the target branch, a PR will still be
|
// When the same change has already been merged to the target branch, a PR will still be
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,6 @@ async function handleMergeComment({ github, body, node_id, reaction }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caching the list of team members saves API requests when running the bot on the schedule and
|
|
||||||
// processing many PRs at once.
|
|
||||||
const members = {}
|
|
||||||
|
|
||||||
async function handleMerge({
|
async function handleMerge({
|
||||||
github,
|
github,
|
||||||
context,
|
context,
|
||||||
|
|
@ -122,31 +118,13 @@ async function handleMerge({
|
||||||
pull_request,
|
pull_request,
|
||||||
events,
|
events,
|
||||||
maintainers,
|
maintainers,
|
||||||
|
getTeamMembers,
|
||||||
}) {
|
}) {
|
||||||
const pull_number = pull_request.number
|
const pull_number = pull_request.number
|
||||||
|
|
||||||
function getTeamMembers(team_slug) {
|
const committers = new Set(
|
||||||
if (context.eventName === 'pull_request') {
|
(await getTeamMembers('nixpkgs-committers')).map(({ id }) => id),
|
||||||
// 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 new Set()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!members[team_slug]) {
|
|
||||||
members[team_slug] = github
|
|
||||||
.paginate(github.rest.teams.listMembersInOrg, {
|
|
||||||
org: context.repo.owner,
|
|
||||||
team_slug,
|
|
||||||
per_page: 100,
|
|
||||||
})
|
|
||||||
.then((members) => new Set(members.map(({ id }) => id)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return members[team_slug]
|
|
||||||
}
|
|
||||||
const committers = await getTeamMembers('nixpkgs-committers')
|
|
||||||
|
|
||||||
const files = await github.paginate(github.rest.pulls.listFiles, {
|
const files = await github.paginate(github.rest.pulls.listFiles, {
|
||||||
...context.repo,
|
...context.repo,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue