Repository: spotify/backstage
File: plugins/catalog-backend-module-github/src/lib/github.ts (TypeScript)

Code before:
            ${suspendedAtField}
            organizationVerifiedDomainEmails(login: $org)
          }
        }
      }
    }`;

  // Transformer to filter out suspended users, only for GitHub Enterprise instances.
  const suspendedUserFilteringTransformer = async (
    item: GithubUser,
    ctx: TransformerContext,
  ): Promise<Entity | undefined> => {
    if (excludeSuspendedUsers && item.suspendedAt) {
      return undefined;
    }
    return userTransformer(item, ctx);
  };

  // There is no user -> teams edge, so we leave the memberships empty for
  // now and let the team iteration handle it instead

  const users = await queryWithPaging(
    client,
    query,
    org,
    r => r.organization?.membersWithRole,
    suspendedUserFilteringTransformer,
    {
      org,
      email: tokenType === 'token',
      organizationMembersPageSize: pageSizes.organizationMembers,
    },
  );

  return { users };
}

/**
 * Gets all the teams out of a Github organization.
 *
 * Note that the teams will not have any relations apart from parent filled in.
 *
 * @param client - An octokit graphql client
 * @param org - The slug of the org to read
 * @param teamTransformer - Optional transformer for team entities
 * @param pageSizes - Optional page sizes configuration
 */
export async function getOrganizationTeams(
  client: typeof graphql,
  org: string,
  teamTransformer: TeamTransformer = defaultOrganizationTeamTransformer,

Review comment (suggestion):
I think we should do the filtering here.

```suggestion
    r => r.organization?.membersWithRole.filter(u => excludeSuspendedUsers ? !u.suspendedAt : true),
```

Code after:
            ${suspendedAtField}
            organizationVerifiedDomainEmails(login: $org)
          }
        }
      }
    }`;

  // There is no user -> teams edge, so we leave the memberships empty for
  // now and let the team iteration handle it instead

  const users = await queryWithPaging({
    client,
    query,
    org,
    connection: r => r.organization?.membersWithRole,
    transformer: userTransformer,
    variables: {
      org,
      email: tokenType === 'token',
      organizationMembersPageSize: pageSizes.organizationMembers,
    },
    filter: u => (excludeSuspendedUsers ? !u.suspendedAt : true),
  });

  return { users };
}

/**
 * Gets all the teams out of a Github organization.
 *
 * Note that the teams will not have any relations apart from parent filled in.
 *
 * @param client - An octokit graphql client
 * @param org - The slug of the org to read
 * @param teamTransformer - Optional transformer for team entities
 * @param pageSizes - Optional page sizes configuration
 */
export async function getOrganizationTeams(
  client: typeof graphql,
  org: string,
  teamTransformer: TeamTransformer = defaultOrganizationTeamTransformer,
  pageSizes: GithubPageSizes = DEFAULT_PAGE_SIZES,
): Promise<{
  teams: Entity[];
}> {
  const query = `
    query teams($org: String!, $cursor: String, $teamsPageSize: Int!, $membersPageSize: Int!) {
      organization(login: $org) {
        teams(first: $teamsPageSize, after: $cursor) {
          pageInfo { hasNextPage, endCursor }
          nodes {