MCPcopy Index your code
hub / github.com/simstudioai/sim / fileToDocument

Function fileToDocument

apps/sim/connectors/gitlab/gitlab.ts:322–384  ·  view source on GitHub ↗

* Builds a repository-file document from a fetched (non-raw) file response. Returns * null for binary, oversized, or empty files so they are not indexed.

(
  apiBase: string,
  encodedProject: string,
  host: string,
  projectPath: string,
  ref: string,
  path: string,
  file: GitLabFile
)

Source from the content-addressed store, hash-verified

320 * null for binary, oversized, or empty files so they are not indexed.
321 */
322function fileToDocument(
323 apiBase: string,
324 encodedProject: string,
325 host: string,
326 projectPath: string,
327 ref: string,
328 path: string,
329 file: GitLabFile
330): ExternalDocument | null {
331 const blobSha = file.blob_id?.trim()
332 if (!blobSha) return null
333
334 const title = path.split('/').pop() || path
335 const skippedForSize = (size: number): ExternalDocument => {
336 logger.info('Skipping oversized GitLab file', { path, size })
337 return markSkipped(
338 {
339 externalId: `${FILE_PREFIX}${path}`,
340 title,
341 content: '',
342 mimeType: 'text/plain',
343 sourceUrl: buildFileSourceUrl(apiBase, encodedProject, host, projectPath, ref, path),
344 contentHash: buildFileContentHash(encodedProject, path, blobSha),
345 metadata: { contentType: 'file', title, path, size },
346 },
347 sizeLimitSkipReason(MAX_FILE_SIZE)
348 )
349 }
350
351 if (typeof file.size === 'number' && file.size > MAX_FILE_SIZE) {
352 return skippedForSize(file.size)
353 }
354
355 const raw = typeof file.content === 'string' ? file.content : ''
356 const buffer = file.encoding === 'base64' ? Buffer.from(raw, 'base64') : Buffer.from(raw, 'utf8')
357 if (isBinaryBuffer(buffer)) {
358 logger.info('Skipping binary GitLab file', { path })
359 return null
360 }
361 if (buffer.byteLength > MAX_FILE_SIZE) {
362 return skippedForSize(buffer.byteLength)
363 }
364
365 const content = buffer.toString('utf8')
366 const body = composeBody(title, content)
367 if (!body.trim()) return null
368
369 return {
370 externalId: `${FILE_PREFIX}${path}`,
371 title,
372 content: body,
373 contentDeferred: false,
374 mimeType: 'text/plain',
375 sourceUrl: buildFileSourceUrl(apiBase, encodedProject, host, projectPath, ref, path),
376 contentHash: buildFileContentHash(encodedProject, path, blobSha),
377 metadata: {
378 contentType: 'file',
379 title,

Callers 1

gitlab.tsFile · 0.85

Calls 7

skippedForSizeFunction · 0.85
composeBodyFunction · 0.85
infoMethod · 0.80
isBinaryBufferFunction · 0.70
buildFileSourceUrlFunction · 0.70
buildFileContentHashFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected