(gitlabProvider: Gitlab)
| 293 | }; |
| 294 | |
| 295 | export const validateGitlabProvider = async (gitlabProvider: Gitlab) => { |
| 296 | try { |
| 297 | const allProjects = []; |
| 298 | let page = 1; |
| 299 | const perPage = 100; // GitLab's max per page is 100 |
| 300 | const baseUrl = ( |
| 301 | gitlabProvider.gitlabInternalUrl || gitlabProvider.gitlabUrl |
| 302 | ).replace(/\/+$/, ""); |
| 303 | |
| 304 | while (true) { |
| 305 | const response = await fetch( |
| 306 | `${baseUrl}/api/v4/projects?membership=true&page=${page}&per_page=${perPage}`, |
| 307 | { |
| 308 | headers: { |
| 309 | Authorization: `Bearer ${gitlabProvider.accessToken}`, |
| 310 | }, |
| 311 | }, |
| 312 | ); |
| 313 | |
| 314 | if (!response.ok) { |
| 315 | throw new TRPCError({ |
| 316 | code: "BAD_REQUEST", |
| 317 | message: `Failed to fetch repositories: ${response.statusText}`, |
| 318 | }); |
| 319 | } |
| 320 | |
| 321 | const projects = await response.json(); |
| 322 | |
| 323 | if (projects.length === 0) { |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | allProjects.push(...projects); |
| 328 | page++; |
| 329 | |
| 330 | const total = response.headers.get("x-total"); |
| 331 | if (total && allProjects.length >= Number.parseInt(total)) { |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | return allProjects; |
| 337 | } catch (error) { |
| 338 | throw error; |
| 339 | } |
| 340 | }; |
no outgoing calls
no test coverage detected