nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at release-25.11 85 lines 2.3 kB view raw
1const excludeTeams = [ 2 /^voters.*$/, 3 /^nixpkgs-maintainers$/, 4 /^nixpkgs-committers$/, 5] 6 7module.exports = async ({ github, context, core, outFile }) => { 8 const withRateLimit = require('./withRateLimit.js') 9 const { writeFileSync } = require('node:fs') 10 11 const org = context.repo.owner 12 13 const result = {} 14 15 await withRateLimit({ github, core }, async () => { 16 // Turn an Array of users into an Object, mapping user.login -> user.id 17 function makeUserSet(users) { 18 // Sort in-place and build result by mutation 19 users.sort((a, b) => (a.login > b.login ? 1 : -1)) 20 21 return users.reduce((acc, user) => { 22 acc[user.login] = user.id 23 return acc 24 }, {}) 25 } 26 27 // Process a list of teams and append to the result variable 28 async function processTeams(teams) { 29 for (const team of teams) { 30 core.notice(`Processing team ${team.slug}`) 31 if (!excludeTeams.some((regex) => team.slug.match(regex))) { 32 const members = makeUserSet( 33 await github.paginate(github.rest.teams.listMembersInOrg, { 34 org, 35 team_slug: team.slug, 36 role: 'member', 37 }), 38 ) 39 const maintainers = makeUserSet( 40 await github.paginate(github.rest.teams.listMembersInOrg, { 41 org, 42 team_slug: team.slug, 43 role: 'maintainer', 44 }), 45 ) 46 result[team.slug] = { 47 description: team.description, 48 id: team.id, 49 maintainers, 50 members, 51 name: team.name, 52 } 53 } 54 await processTeams( 55 await github.paginate(github.rest.teams.listChildInOrg, { 56 org, 57 team_slug: team.slug, 58 }), 59 ) 60 } 61 } 62 63 const teams = await github.paginate(github.rest.repos.listTeams, { 64 ...context.repo, 65 }) 66 67 await processTeams(teams) 68 }) 69 70 // Sort the teams by team name 71 const sorted = Object.keys(result) 72 .sort() 73 .reduce((acc, key) => { 74 acc[key] = result[key] 75 return acc 76 }, {}) 77 78 const json = `${JSON.stringify(sorted, null, 2)}\n` 79 80 if (outFile) { 81 writeFileSync(outFile, json) 82 } else { 83 console.log(json) 84 } 85}