From 268b0f99549f637b665943c1e8731426f7b942f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rio=20Val=C3=A9rio?= Date: Wed, 26 Nov 2025 09:46:40 +0200 Subject: [PATCH] Introduce a new optional filter in queryWithPaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new filter will allow excluding items returned from the GitHub API, given a boolean condition, before passing them to the transformer. Signed-off-by: Valério Valério --- .../src/lib/github.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index 030fa93fad..8d8410b182 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -211,17 +211,6 @@ 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 @@ -230,12 +219,13 @@ export async function getOrganizationUsers( query, org, r => r.organization?.membersWithRole, - suspendedUserFilteringTransformer, + userTransformer, { org, email: tokenType === 'token', organizationMembersPageSize: pageSizes.organizationMembers, }, + u => (excludeSuspendedUsers ? !u.suspendedAt : true), ); return { users }; @@ -772,6 +762,7 @@ export async function getTeamMembers( * @param transformer - A function that, given one of the nodes in the Connection, * returns the model mapped form of it * @param variables - The variable values that the query needs, minus the cursor + * @param filter - An optional filter function to filter the nodes before transforming them */ export async function queryWithPaging< GraphqlType, @@ -788,6 +779,7 @@ export async function queryWithPaging< ctx: TransformerContext, ) => Promise, variables: Variables, + filter?: (item: GraphqlType) => boolean, ): Promise { const result: OutputType[] = []; const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); @@ -805,6 +797,9 @@ export async function queryWithPaging< } for (const node of conn.nodes) { + if (filter && !filter(node)) { + continue; + } const transformedNode = await transformer(node, { client, query,