Unverified Commit f7949cdb authored by Wolfgang Walther's avatar Wolfgang Walther Committed by GitHub
Browse files

workflows/teams: style review (#456424)

parents e22b95cf 3df31aa2
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ on:
  schedule:
    # Every Tuesday at 19:42 (randomly chosen)
    - cron: '42 19 * * 1'

  # Allows manual trigger
  workflow_dispatch:

permissions: {}
@@ -25,6 +23,7 @@ jobs:
          private-key: ${{ secrets.OWNER_APP_PRIVATE_KEY }}
          permission-administration: read
          permission-members: read

      - name: Fetch source
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
@@ -32,8 +31,10 @@ jobs:
          sparse-checkout: |
            ci/github-script
            maintainers/github-teams.json

      - name: Install dependencies
        run: npm install bottleneck

      - name: Synchronise teams
        uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
        with:
@@ -54,6 +55,7 @@ jobs:
          private-key: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }}
          permission-contents: write
          permission-pull-requests: write

      - name: Get GitHub App User Git String
        id: user
        env:
@@ -64,6 +66,7 @@ jobs:
          userId=$(gh api "/users/$name" --jq .id)
          email="$userId+$name@users.noreply.github.com"
          echo "git-string=$name <$email>" >> "$GITHUB_OUTPUT"

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
        with:

ci/github-script/get-teams.js

100755 → 100644
+11 −8
Original line number Diff line number Diff line
@@ -7,9 +7,13 @@ const excludeTeams = [
module.exports = async ({ github, context, core, outFile }) => {
  const withRateLimit = require('./withRateLimit.js')
  const { writeFileSync } = require('node:fs')

  const org = context.repo.owner

  const result = {}
  await withRateLimit({ github, core }, async (_stats) => {
    /// Turn an Array of users into an Object, mapping user.login -> user.id

  await withRateLimit({ github, core }, async () => {
    // Turn an Array of users into an Object, mapping user.login -> user.id
    function makeUserSet(users) {
      // Sort in-place and build result by mutation
      users.sort((a, b) => (a.login > b.login ? 1 : -1))
@@ -20,21 +24,21 @@ module.exports = async ({ github, context, core, outFile }) => {
      }, {})
    }

    /// Process a list of teams and append to the result variable
    // Process a list of teams and append to the result variable
    async function processTeams(teams) {
      for (const team of teams) {
        core.notice(`Processing team ${team.slug}`)
        if (!excludeTeams.some((regex) => team.slug.match(regex))) {
          const members = makeUserSet(
            await github.paginate(github.rest.teams.listMembersInOrg, {
              org: context.repo.owner,
              org,
              team_slug: team.slug,
              role: 'member',
            }),
          )
          const maintainers = makeUserSet(
            await github.paginate(github.rest.teams.listMembersInOrg, {
              org: context.repo.owner,
              org,
              team_slug: team.slug,
              role: 'maintainer',
            }),
@@ -49,7 +53,7 @@ module.exports = async ({ github, context, core, outFile }) => {
        }
        await processTeams(
          await github.paginate(github.rest.teams.listChildInOrg, {
            org: context.repo.owner,
            org,
            team_slug: team.slug,
          }),
        )
@@ -57,8 +61,7 @@ module.exports = async ({ github, context, core, outFile }) => {
    }

    const teams = await github.paginate(github.rest.repos.listTeams, {
      owner: context.repo.owner,
      repo: context.repo.repo,
      ...context.repo,
    })

    await processTeams(teams)
+0 −1
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@ program
  .argument('[outFile]', 'Path to the output file (Example: github-teams.json). If not set, prints to stdout')
  .action(async (owner, repo, outFile, options) => {
    const getTeams = (await import('./get-teams.js')).default
    // TODO: Refactor this file so we don't need to pass a PR
    await run(getTeams, owner, repo, undefined, { ...options, outFile })
  })