| 58 | ]); |
| 59 | |
| 60 | export function* execute( |
| 61 | input: LoadingInput, |
| 62 | ctx: PipelineContext, |
| 63 | ): Generator<PipelineEvent, ScanResult> { |
| 64 | const { repo } = input; |
| 65 | const repoId = `${repo.owner}/${repo.repo}`; |
| 66 | |
| 67 | yield { |
| 68 | kind: 'stage_start', |
| 69 | phase: 'scanning', |
| 70 | message: `Scanning ${repo.files.length} files`, |
| 71 | }; |
| 72 | |
| 73 | const repoProps: Record<string, unknown> = { ref: repo.ref }; |
| 74 | if (repo.url) repoProps.sourceUri = repo.url; |
| 75 | if (repo.provider) repoProps.provider = repo.provider; |
| 76 | |
| 77 | const repoNode: GraphNode = { |
| 78 | id: repoId, |
| 79 | type: 'Repository', |
| 80 | name: repoId, |
| 81 | properties: repoProps, |
| 82 | }; |
| 83 | |
| 84 | const dirNodes = new Map<string, GraphNode>(); |
| 85 | const fileNodes: GraphNode[] = []; |
| 86 | const structureRels: GraphRelationship[] = []; |
| 87 | const parseableFiles: RepoFile[] = []; |
| 88 | const packageNodes = new Map<string, GraphNode>(); |
| 89 | const dependencyRels: GraphRelationship[] = []; |
| 90 | let goModulePath: string | undefined; |
| 91 | |
| 92 | // Pre-compute lookup maps for downstream stages |
| 93 | const knownPaths = new Set<string>(); |
| 94 | const pathToFileId = new Map<string, string>(); |
| 95 | |
| 96 | const total = repo.files.length; |
| 97 | |
| 98 | for (let i = 0; i < repo.files.length; i++) { |
| 99 | if (ctx.cancelled) break; |
| 100 | |
| 101 | const file = repo.files[i]; |
| 102 | const ext = getExtension(file.path); |
| 103 | const language = detectLanguage(ext); |
| 104 | |
| 105 | const fileId = `${repoId}/${file.path}`; |
| 106 | const fileName = file.path.includes('/') |
| 107 | ? file.path.slice(file.path.lastIndexOf('/') + 1) |
| 108 | : file.path; |
| 109 | |
| 110 | const fileProps: Record<string, unknown> = { |
| 111 | path: file.path, |
| 112 | extension: ext, |
| 113 | }; |
| 114 | if (language) fileProps.language = language; |
| 115 | if (repo.url) { |
| 116 | fileProps.sourceUri = `${repo.url}/blob/${repo.ref}/${file.path}`; |
| 117 | } |