Tucker McKnight <tmcknight@instructure.com> | Sat Jun 20 2026
DRY flatfiles function
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
export default (repos: Array<Repository>) : Array<FlatFileEntry> => {
if (cachedFlatFiles !== null) { return cachedFlatFiles }
const branches: FlatFileEntry[] = repos.flatMap((repo) => {
return repo.branches.flatMap((branch) => {
return Array.from(branch.fileList.keys()).map((file) => {
return {
file,
refName: branch.name,
repoName: repo.name,
type: 'branch',
}
})
})
})
const tags: FlatFileEntry[] = repos.flatMap((repo) => {
return repo.tags.flatMap((tag) => {
return Array.from(tag.fileList.keys()).map((file) => {
return {
file,
refName: tag.name,
repoName: repo.name,
type: 'tag',
}
})
})
})
cachedFlatFiles = [...branches, ...tags]10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
export default (repos: Array<Repository>) : Array<FlatFileEntry> => {
if (cachedFlatFiles !== null) { return cachedFlatFiles }
const itemsFromRefFileList: (ref: Repository['tags'][0], repoName: string, refType: 'branch' | 'tag') => Array<FlatFileEntry> = (ref, repoName, refType) => {
return Array.from(ref.fileList.keys()).map((file) => {
return {
file,
refName: ref.name,
repoName: repoName,
type: refType,
}
})
}
const branches: FlatFileEntry[] = repos.flatMap((repo) => {
return repo.branches.flatMap(branch => itemsFromRefFileList(branch, repo.name, 'branch'))
})
const tags: FlatFileEntry[] = repos.flatMap((repo) => {
return repo.tags.flatMap(tag => itemsFromRefFileList(tag, repo.name, 'tag'))
})
cachedFlatFiles = [...branches, ...tags]