( input: z.infer<typeof apiGitlabTestConnection>, )
| 262 | }; |
| 263 | |
| 264 | export const testGitlabConnection = async ( |
| 265 | input: z.infer<typeof apiGitlabTestConnection>, |
| 266 | ) => { |
| 267 | const { gitlabId, groupName } = input; |
| 268 | |
| 269 | if (!gitlabId) { |
| 270 | throw new Error("Gitlab provider not found"); |
| 271 | } |
| 272 | |
| 273 | await refreshGitlabToken(gitlabId); |
| 274 | |
| 275 | const gitlabProvider = await findGitlabById(gitlabId); |
| 276 | |
| 277 | const repositories = await validateGitlabProvider(gitlabProvider); |
| 278 | |
| 279 | const filteredRepos = repositories.filter((repo: any) => { |
| 280 | const { full_path, kind } = repo.namespace; |
| 281 | |
| 282 | if (groupName) { |
| 283 | return groupName |
| 284 | .split(",") |
| 285 | .some((name: string) => |
| 286 | full_path.toLowerCase().startsWith(name.trim().toLowerCase()), |
| 287 | ); |
| 288 | } |
| 289 | return kind === "user"; |
| 290 | }); |
| 291 | |
| 292 | return filteredRepos.length; |
| 293 | }; |
| 294 | |
| 295 | export const validateGitlabProvider = async (gitlabProvider: Gitlab) => { |
| 296 | try { |
no test coverage detected