Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions backend/src/serverless/integrations/usecases/gitlab/getProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,48 @@ export async function fetchAllGitlabGroups(accessToken: string) {
}))
}

export async function fetchGitlabGroupProjects(accessToken: string, groups: any[]) {
const groupProjects = {}
async function fetchProjectsForGroup(accessToken: string, group: any) {
const projects = []
let page = 1
let hasMorePages = true

for (const group of groups) {
const projects = []
let page = 1
let hasMorePages = true
while (hasMorePages) {
const response = await axios.get(`https://gitlab.com/api/v4/groups/${group.id}/projects`, {
headers: { Authorization: `Bearer ${accessToken}` },
params: { page, per_page: 100, archived: false },
})
projects.push(...response.data)
hasMorePages = response.headers['x-next-page'] !== ''
page++
}

while (hasMorePages) {
const response = await axios.get(`https://gitlab.com/api/v4/groups/${group.id}/projects`, {
headers: { Authorization: `Bearer ${accessToken}` },
params: { page, per_page: 100, archived: false },
})
projects.push(...response.data)
hasMorePages = response.headers['x-next-page'] !== ''
page++
}
return projects.map((project) => ({
groupId: group.id,
groupName: group.name,
groupPath: group.path,
id: project.id,
name: project.name,
path_with_namespace: project.path_with_namespace,
enabled: false,
forkedFrom: project?.forked_from_project?.web_url || null,
}))
}

groupProjects[group.id] = projects.map((project) => ({
groupId: group.id,
groupName: group.name,
groupPath: group.path,
id: project.id,
name: project.name,
path_with_namespace: project.path_with_namespace,
enabled: false,
forkedFrom: project?.forked_from_project?.web_url || null,
}))
export async function fetchGitlabGroupProjects(accessToken: string, groups: any[]) {
const CONCURRENCY = 10
const groupProjects: Record<number, any[]> = {}
Comment thread
mbani01 marked this conversation as resolved.

for (let i = 0; i < groups.length; i += CONCURRENCY) {
Comment thread
mbani01 marked this conversation as resolved.
const batch = groups.slice(i, i + CONCURRENCY)
const results = await Promise.all(
batch.map((group) => fetchProjectsForGroup(accessToken, group)),
)
Comment on lines +59 to +61
batch.forEach((group, idx) => {
groupProjects[group.id] = results[idx]
})
}

return groupProjects as Record<number, any[]>
return groupProjects
}

export async function fetchGitlabUserProjects(accessToken: string, userId: number) {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/services/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,18 @@ export default class IntegrationService {

await SequelizeRepository.commitTransaction(transaction)
} catch (err) {
this.options.log.error(
{
errMessage: err?.message,
errName: err?.name,
errStack: err?.stack,
gitlabStatus: err?.response?.status,
gitlabError: err?.response?.data,
gitlabUrl: err?.config?.url,
gitlabMethod: err?.config?.method,
},
'gitlabConnect failed',
)
Comment thread
mbani01 marked this conversation as resolved.
Comment on lines +2777 to +2788
await SequelizeRepository.rollbackTransaction(transaction)
throw err
}
Expand Down
Loading