diff --git a/packages/components/nodes/documentloaders/Github/Github.ts b/packages/components/nodes/documentloaders/Github/Github.ts index 552790abf6a..bbaad3cb016 100644 --- a/packages/components/nodes/documentloaders/Github/Github.ts +++ b/packages/components/nodes/documentloaders/Github/Github.ts @@ -40,6 +40,12 @@ class Github_DocumentLoaders implements INode { placeholder: '', optional: true }, + { + label: 'Recursive', + name: 'recursive', + type: 'boolean', + optional: true + }, { label: 'Text Splitter', name: 'textSplitter', @@ -59,41 +65,33 @@ class Github_DocumentLoaders implements INode { async init(nodeData: INodeData): Promise { const repoLink = nodeData.inputs?.repoLink as string const branch = nodeData.inputs?.branch as string + const recursive = nodeData.inputs?.recursive as boolean const accessToken = nodeData.inputs?.accessToken as string const textSplitter = nodeData.inputs?.textSplitter as TextSplitter const metadata = nodeData.inputs?.metadata const options: GithubRepoLoaderParams = { branch, - recursive: false, + recursive, unknown: 'warn' } if (accessToken) options.accessToken = accessToken const loader = new GithubRepoLoader(repoLink, options) - let docs = [] - - if (textSplitter) { - docs = await loader.loadAndSplit(textSplitter) - } else { - docs = await loader.load() - } + const docs = textSplitter ? await loader.loadAndSplit(textSplitter) : await loader.load() if (metadata) { const parsedMetadata = typeof metadata === 'object' ? metadata : JSON.parse(metadata) - let finaldocs = [] - for (const doc of docs) { - const newdoc = { + return docs.map((doc) => { + return { ...doc, metadata: { ...doc.metadata, ...parsedMetadata } } - finaldocs.push(newdoc) - } - return finaldocs + }) } return docs