From bad559c1f9ae96382cd321d22b0c810e6eca4211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rio=20Val=C3=A9rio?= Date: Tue, 21 Oct 2025 13:31:17 +0300 Subject: [PATCH] Move the suspended user logic to a transformer filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valério Valério --- .changeset/fuzzy-phones-own.md | 2 +- docs/integrations/github/org.md | 4 +--- plugins/catalog-backend-module-github/config.d.ts | 2 -- .../src/lib/defaultTransformers.ts | 3 --- .../src/lib/github.test.ts | 2 +- .../catalog-backend-module-github/src/lib/github.ts | 13 ++++++++++++- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.changeset/fuzzy-phones-own.md b/.changeset/fuzzy-phones-own.md index a980bcffba..69a40e29b2 100644 --- a/.changeset/fuzzy-phones-own.md +++ b/.changeset/fuzzy-phones-own.md @@ -5,5 +5,5 @@ Introduce new configuration option to exclude suspended users from GitHub Enterprise instances. -When it’s set to true, suspended users won’t be emitted by the default transform. +When it’s set to true, suspended users won’t be returned when querying the organization users for GitHub Enterprise instances. Note that this option should be used only against GitHub Enterprise instances, the property does not exist in the github.com GraphQL schema, setting it will cause a schema validation error and the syncing of users will fail. diff --git a/docs/integrations/github/org.md b/docs/integrations/github/org.md index cfc71d3e5a..284451af8c 100644 --- a/docs/integrations/github/org.md +++ b/docs/integrations/github/org.md @@ -99,7 +99,6 @@ Directly under the `githubOrg` is a list of configurations, each entry is a stru - `githubUrl`: The target that this provider should consume - `orgs` (optional): The list of the GitHub orgs to consume. If you only list a single org the generated group entities will use the `default` namespace, otherwise they will use the org name as the namespace. By default the provider will consume all accessible orgs on the given GitHub instance (support for GitHub App integration only). - `schedule`: The refresh schedule to use, matches the structure of [`SchedulerServiceTaskScheduleDefinitionConfig`](https://backstage.io/docs/reference/backend-plugin-api.schedulerservicetaskscheduledefinitionconfig/) -<<<<<<< HEAD - `pageSizes` (optional): Configure page sizes for GitHub GraphQL API queries to prevent `RESOURCE_LIMITS_EXCEEDED` errors. You can configure the following page sizes: - `teams`: Number of teams to fetch per page when querying organization teams (default: 25) @@ -107,9 +106,8 @@ Directly under the `githubOrg` is a list of configurations, each entry is a stru - `organizationMembers`: Number of organization members to fetch per page (default: 50) Reducing page sizes will result in more API calls and slightly longer sync times, but will prevent API resource limits for organizations with large number of teams and members. -======= + - `excludeSuspendedUsers` (optional): Whether to exclude suspended users when querying organization users. Only for GitHub Enterprise instances. Will error if used against GitHub.com API. ->>>>>>> 40785ff87c (Update documentation to list the new option 'excludeSuspendedUsers') ### Events Support diff --git a/plugins/catalog-backend-module-github/config.d.ts b/plugins/catalog-backend-module-github/config.d.ts index 6277f7aa2e..5425cae9d0 100644 --- a/plugins/catalog-backend-module-github/config.d.ts +++ b/plugins/catalog-backend-module-github/config.d.ts @@ -266,7 +266,6 @@ export interface Config { /** * (Optional) Only for GitHub Enterprise. Whether to exclude suspended users when querying organization users. - * If true, the defaultTransformer will not return suspended users. * Default: `false`. */ excludeSuspendedUsers?: boolean; @@ -324,7 +323,6 @@ export interface Config { /** * (Optional) Only for GitHub Enterprise. Whether to exclude suspended users when querying organization users. - * If true, the defaultTransformer will not return suspended users. * Default: `false`. */ excludeSuspendedUsers?: boolean; diff --git a/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts b/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts index 02f5052ae1..6befd32056 100644 --- a/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts +++ b/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts @@ -62,9 +62,6 @@ export const defaultUserTransformer = async ( item: GithubUser, _ctx: TransformerContext, ): Promise => { - if (item.suspendedAt) { - return undefined; - } const entity: UserEntity = { apiVersion: 'backstage.io/v1alpha1', kind: 'User', diff --git a/plugins/catalog-backend-module-github/src/lib/github.test.ts b/plugins/catalog-backend-module-github/src/lib/github.test.ts index fc4fdb14da..3cfb1b523a 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.test.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.test.ts @@ -385,7 +385,7 @@ describe('github', () => { graphql, 'a', 'token', - true, + false, customUserTransformer, ), ).resolves.toEqual(output); diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index b614b4be64..7f2fd0e08b 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -210,6 +210,17 @@ export async function getOrganizationUsers( } }`; + // Transformer to filter out suspended users, only for GitHub Enterprise instances. + const suspendedUserFilteringTransformer = async ( + item: GithubUser, + ctx: TransformerContext, + ): Promise => { + 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 @@ -218,7 +229,7 @@ export async function getOrganizationUsers( query, org, r => r.organization?.membersWithRole, - userTransformer, + suspendedUserFilteringTransformer, { org, email: tokenType === 'token',