* Creates a lightweight stub ExternalDocument from a tree item. * Uses the Git blob SHA as contentHash for change detection, avoiding * the need to fetch blob content for every file during listing. * Content is deferred and only fetched for new/changed documents.
( owner: string, repo: string, branch: string, item: TreeItem )
| 160 | * Content is deferred and only fetched for new/changed documents. |
| 161 | */ |
| 162 | function treeItemToStub( |
| 163 | owner: string, |
| 164 | repo: string, |
| 165 | branch: string, |
| 166 | item: TreeItem |
| 167 | ): ExternalDocument { |
| 168 | return { |
| 169 | externalId: item.path, |
| 170 | title: item.path.split('/').pop() || item.path, |
| 171 | content: '', |
| 172 | contentDeferred: true, |
| 173 | mimeType: 'text/plain', |
| 174 | sourceUrl: `https://github.com/${owner}/${repo}/blob/${branch.split('/').map(encodeURIComponent).join('/')}/${item.path.split('/').map(encodeURIComponent).join('/')}`, |
| 175 | contentHash: `${GIT_SHA_PREFIX}${item.sha}`, |
| 176 | metadata: { |
| 177 | path: item.path, |
| 178 | sha: item.sha, |
| 179 | size: item.size, |
| 180 | branch, |
| 181 | repository: `${owner}/${repo}`, |
| 182 | }, |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | export const githubConnector: ConnectorConfig = { |
| 187 | ...githubConnectorMeta, |