Skip to content

Commit 46b7c0e

Browse files
committed
fix(gitlab): error on bad user branch (tree 404), warn on resolveRef fallback, normalize pathPrefix to directory boundary
1 parent ce0bcef commit 46b7c0e

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

apps/sim/connectors/gitlab/gitlab.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ async function resolveRef(
533533
}
534534
return branch
535535
}
536+
logger.warn('Failed to fetch GitLab project for default branch; falling back to "main"', {
537+
project: encodedProject,
538+
status: response.status,
539+
})
536540
return 'main'
537541
}
538542

@@ -724,10 +728,12 @@ export const gitlabConnector: ConnectorConfig = {
724728
}
725729

726730
if (state.phase === 'repo') {
731+
const userRef = typeof sourceConfig.ref === 'string' ? sourceConfig.ref.trim() : ''
727732
const ref = await resolveRef(sourceConfig, syncContext, apiBase, encodedProject, accessToken)
728733
const extSet = parseExtensions(sourceConfig.fileExtensions)
729-
const pathPrefix =
734+
const rawPrefix =
730735
typeof sourceConfig.pathPrefix === 'string' ? sourceConfig.pathPrefix.trim() : ''
736+
const pathPrefix = rawPrefix && !rawPrefix.endsWith('/') ? `${rawPrefix}/` : rawPrefix
731737

732738
const treeParams = new URLSearchParams({
733739
ref,
@@ -752,14 +758,16 @@ export const gitlabConnector: ConnectorConfig = {
752758

753759
if (!response.ok) {
754760
if (response.status === 404) {
755-
logger.warn(
756-
'GitLab repository tree not found; skipping files (empty repo or bad branch)',
757-
{
758-
host,
759-
project: encodedProject,
760-
ref,
761-
}
762-
)
761+
if (userRef) {
762+
throw new Error(
763+
`GitLab branch "${userRef}" not found for project ${sourceConfig.project}. Check the Branch setting.`
764+
)
765+
}
766+
logger.warn('GitLab repository tree empty; skipping files', {
767+
host,
768+
project: encodedProject,
769+
ref,
770+
})
763771
const adv = advance('repo')
764772
return { documents: [], nextCursor: adv.nextCursor, hasMore: adv.hasMore }
765773
}

0 commit comments

Comments
 (0)