* Drains the full Linear teams connection by following * `pageInfo.endCursor` until `hasNextPage` is false. Bounded by * `MAX_TEAMS_PAGES`; logs a warning if the cap is hit so a truncated list is * visible rather than silently dropped.
(linearClient: LinearClient)
| 30 | * visible rather than silently dropped. |
| 31 | */ |
| 32 | async function fetchAllTeams(linearClient: LinearClient): Promise<Team[]> { |
| 33 | const teams: Team[] = [] |
| 34 | let after: string | undefined |
| 35 | |
| 36 | for (let page = 0; page < MAX_TEAMS_PAGES; page++) { |
| 37 | const result = await linearClient.teams({ first: LINEAR_PAGE_SIZE, after }) |
| 38 | teams.push(...result.nodes) |
| 39 | |
| 40 | if (!result.pageInfo.hasNextPage) { |
| 41 | return teams |
| 42 | } |
| 43 | after = result.pageInfo.endCursor ?? undefined |
| 44 | if (!after) { |
| 45 | return teams |
| 46 | } |
| 47 | if (page === MAX_TEAMS_PAGES - 1) { |
| 48 | logger.warn('Linear teams pagination hit cap; team list may be incomplete', { |
| 49 | cap: MAX_TEAMS_PAGES, |
| 50 | fetched: teams.length, |
| 51 | }) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return teams |
| 56 | } |
| 57 | |
| 58 | export const POST = withRouteHandler(async (request: NextRequest) => { |
| 59 | try { |