Tucker McKnight <tmcknight@instructure.com> | Sun Apr 19 2026
Use the flatRels object on all templates Fixes bugs with pages not getting generated for tags. Tag pages, and having links properly point to them, seems to be working in all places now.
6 7 8 9 10 11 12 13 14 15
eleventyConfig: any,
data: any,
) => {
const pagesJustForRel = eleventyConfig.getFilter("pagesJustForRel")
const slugify = eleventyConfig.getFilter("slugify")
const date = eleventyConfig.getFilter("date")
const nav = NavHelper(reposConfig, slugify, data.patchPage.repoName, data.patchPage.relName)
const pageContent = [
m('div', {class: "row mt-3 mb-1"},6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
eleventyConfig: any,
data: any,
) => {
const pagesJustForRef = eleventyConfig.getFilter("pagesJustForRef")
const slugify = eleventyConfig.getFilter("slugify")
const date = eleventyConfig.getFilter("date")
const nav = NavHelper({
reposConfig,
slugify,
currentRepoName: data.patchPage.repoName,
currentRefName: data.patchPage.refName,
currentRefType: data.patchPage.type,
})
const pageContent = [
m('div', {class: "row mt-3 mb-1"},20 21 22 23 24 25
m('span', {class: "font-monospace me-2"}, data.patchPage.relName),
m('a', {
class: "btn btn-outline-primary badge shadow-none",
href: nav.repoCurrentBranchRssFeed()
}, [
m('img', {
src: `${nav.rootPath()}frontend/img/rss-icon.svg`,20 21 22 23 24 25
m('span', {class: "font-monospace me-2"}, data.patchPage.relName),
m('a', {
class: "btn btn-outline-primary badge shadow-none",
href: nav.rssFeed()
}, [
m('img', {
src: `${nav.rootPath()}frontend/img/rss-icon.svg`,33 34 35 36 37 38
),
m('nav',
m('ul', {class: "pagination"},
pagesJustForRel(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.relName,33 34 35 36 37 38
),
m('nav',
m('ul', {class: "pagination"},
pagesJustForRef(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.relName,67 68 69 70 71 72
})),
m('nav',
m('ul', {class: "pagination"},
pagesJustForRel(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.relName,67 68 69 70 71 72
})),
m('nav',
m('ul', {class: "pagination"},
pagesJustForRef(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.relName,10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
}
const repo: Repository = data.currentRepo
const rel: Repository['branches'][0] = data.currentRel
const slugify = eleventyConfig.getFilter("slugify")
const nav = NavHelper(reposConfig, slugify, repo.name, rel.name)
const branchesWithHrefs = repo.branches.map((branch) => {
return {
name: branch.name,
href: nav.repoBranchHome(branch.name) + '/' + data.nav.path,
date: repo.commits.get(branch.sha).date.toISOString(),
}
}).concat(repo.tags.map((tag) => {
return {
name: tag.name,
href: nav.repoTagHome(tag.name) + '/' + data.nav.path,
date: repo.commits.get(tag.sha).date.toISOString(),
}
}))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
}
const repo: Repository = data.currentRepo
const ref: Repository['branches'][0] = data.currentRef
const slugify = eleventyConfig.getFilter("slugify")
const nav = NavHelper({
reposConfig,
slugify,
currentRepoName: repo.name,
currentRefName: ref.name,
currentRefType: data.currentRefType,
})
const branchesWithHrefs = repo.branches.map((branch) => {
return {
name: branch.name,
href: nav.refHome({refName: branch.name, refType: 'branch'}) + '/' + data.nav.path,
date: repo.commits.get(branch.sha).date.toISOString(),
}
}).concat(repo.tags.map((tag) => {
return {
name: tag.name,
href: nav.refHome({refName: tag.name, refType: 'tag'}) + '/' + data.nav.path,
date: repo.commits.get(tag.sha).date.toISOString(),
}
}))36 37 38 39 40 41
m('script', m.trust(`
window.branchesWithHrefs = ${JSON.stringify(branchesWithHrefs)};
window.defaultBranch = "${repo.defaultBranch}";
window.currentBranch = "${rel.name}";
window.cloneUrl = "${repo.cloneUrl}";
`)),
m('link', {36 37 38 39 40 41
m('script', m.trust(`
window.branchesWithHrefs = ${JSON.stringify(branchesWithHrefs)};
window.defaultBranch = "${repo.defaultBranch}";
window.currentBranch = "${ref.name}";
window.cloneUrl = "${repo.cloneUrl}";
`)),
m('link', {57 58 59 60 61 62
m('li', {class: "nav-item"},
m('a', {
class: "nav-link",
href: nav.repoCurrentBranchHome()
}, repo.name)
),
m('li', {class: "nav-item"}, [57 58 59 60 61 62
m('li', {class: "nav-item"},
m('a', {
class: "nav-link",
href: nav.refHome()
}, repo.name)
),
m('li', {class: "nav-item"}, [68 69 70 71 72 73
'data-bs-toggle': "dropdown",
'data-bs-auto-close': "outside",
'aria-expanded': "false"
}, rel.name),
m('div', {class: "dropdown-menu"}, [
m('form', {class: "mx-3 my-1"}, [
m('input', {type: "text", class: "form-control", id: "dropdownBranchSearch", placeholder: "Search branches..."}),68 69 70 71 72 73
'data-bs-toggle': "dropdown",
'data-bs-auto-close': "outside",
'aria-expanded': "false"
}, ref.name),
m('div', {class: "dropdown-menu"}, [
m('form', {class: "mx-3 my-1"}, [
m('input', {type: "text", class: "form-control", id: "dropdownBranchSearch", placeholder: "Search branches..."}),92 93 94 95 96 97
]),
m('div', {class: "dropdown-divider"}),
m('div', {id: "dropdown-branches-results", class: "dropdown-branches"},
branchesListItems(branchesWithHrefs, repo.defaultBranch, rel.name, 'date')
)
])
])92 93 94 95 96 97
]),
m('div', {class: "dropdown-divider"}),
m('div', {id: "dropdown-branches-results", class: "dropdown-branches"},
branchesListItems(branchesWithHrefs, repo.defaultBranch, ref.name, 'date')
)
])
])0 1 2 3 4 5
import m from 'mithril'
import render from 'mithril-node-render'
import { type Repository } from '../src/dataTypes.ts'
import getFlatRels from '../src/flatRels.ts'
import { dateToRfc3339 } from '@11ty/eleventy-plugin-rss'
import flatPatches from '../src/flatPatches.ts'
0 1 2 3 4 5
import m from 'mithril'
import render from 'mithril-node-render'
import { type Repository } from '../src/dataTypes.ts'
import getFlatRefs from '../src/flatRefs.ts'
import { dateToRfc3339 } from '@11ty/eleventy-plugin-rss'
import flatPatches from '../src/flatPatches.ts'
14 15 16 17 18 19
const languageExtension = eleventyConfig.getFilter("languageExtension")
const renderContentIfAvailable = eleventyConfig.getFilter("renderContentIfAvailable")
const currentRel: Branch = data.currentRel
const fileInfo: FlatFileEntry = data.fileInfo
const pageContent = [ 14 15 16 17 18 19
const languageExtension = eleventyConfig.getFilter("languageExtension")
const renderContentIfAvailable = eleventyConfig.getFilter("renderContentIfAvailable")
const currentRef: Branch = data.currentRef
const fileInfo: FlatFileEntry = data.fileInfo
const pageContent = [ 95 96 97 98 99 100
m('div', {class: "row rendered-content"},
m('div', {class: "col"},
m.trust(await renderContentIfAvailable(
currentRel.fileList.get(fileInfo.file).fileInfo.contents
))
)
)95 96 97 98 99 100
m('div', {class: "row rendered-content"},
m('div', {class: "col"},
m.trust(await renderContentIfAvailable(
currentRef.fileList.get(fileInfo.file).fileInfo.contents
))
)
)115 116 117 118 119 120
m('div', {class: "col-auto p-0"},
m('code', {style: "white-space: pre;"},
m('pre', {class: "language-text"},
lineNumbers(currentRel.fileList.get(fileInfo.file).fileInfo.contents).map((lineNumber) => {
return lineNumber
}).join('\n')
)115 116 117 118 119 120
m('div', {class: "col-auto p-0"},
m('code', {style: "white-space: pre;"},
m('pre', {class: "language-text"},
lineNumbers(currentRef.fileList.get(fileInfo.file).fileInfo.contents).map((lineNumber) => {
return lineNumber
}).join('\n')
)124 125 126 127 128 129 130 131 132 133 134 135 136
m('div', {id: "annotations", class: "col-auto d-none p-0"},
m('code', {style: "white-space: pre;"}, [
m('pre', {class: "language-text"}, m.trust(
currentRel.fileList.get(fileInfo.file).fileInfo.blameLines.map((annotation) => {
return `<a href="${data.reposPath}/${slugify(fileInfo.repoName)}/branch/${slugify(fileInfo.branchName)}/commits/${annotation.sha}">${annotation.sha.substr(0, 6)}</a> ${annotation.author}`
}).join('\n')))
])
),
m('div', {class: "col overflow-scroll p-0"},
m('code', m.trust(highlightCode(
currentRel.fileList.get(fileInfo.file).fileInfo.contents,
languageExtension(
fileInfo.file,
fileInfo.repoName124 125 126 127 128 129 130 131 132 133 134 135 136
m('div', {id: "annotations", class: "col-auto d-none p-0"},
m('code', {style: "white-space: pre;"}, [
m('pre', {class: "language-text"}, m.trust(
currentRef.fileList.get(fileInfo.file).fileInfo.blameLines.map((annotation) => {
return `<a href="${data.reposPath}/${slugify(fileInfo.repoName)}/branch/${slugify(fileInfo.branchName)}/commits/${annotation.sha}">${annotation.sha.substr(0, 6)}</a> ${annotation.author}`
}).join('\n')))
])
),
m('div', {class: "col overflow-scroll p-0"},
m('code', m.trust(highlightCode(
currentRef.fileList.get(fileInfo.file).fileInfo.contents,
languageExtension(
fileInfo.file,
fileInfo.repoName2 3 4 5 6 7
import htmlPage from './common/htmlPage.ts'
export default async (reposConfig: any, eleventyConfig: any, data: any) => {
const branch: Repository['branches'][0] = data.currentRel
const topLevelFilesOnly = eleventyConfig.getFilter("topLevelFilesOnly")
const slugify = eleventyConfig.getFilter("slugify")
2 3 4 5 6 7
import htmlPage from './common/htmlPage.ts'
export default async (reposConfig: any, eleventyConfig: any, data: any) => {
const branch: Repository['branches'][0] = data.currentRef
const topLevelFilesOnly = eleventyConfig.getFilter("topLevelFilesOnly")
const slugify = eleventyConfig.getFilter("slugify")
13 14 15 16 17 18
m('div', {class: "col"},
m('p', [
'Files snapshot from ',
m('span', {class: "font-monospace"}, data.flatRel.relName)
])
)
]),13 14 15 16 17 18
m('div', {class: "col"},
m('p', [
'Files snapshot from ',
m('span', {class: "font-monospace"}, data.flatRef.relName)
])
)
]),26 27 28 29 30 31
return m('li', {class: 'list-group-item'}, [
file.isDirectory ? m.trust('<span>📁 </span>') : null,
m('a', {
href: `${data.reposPath}/${slugify(data.flatRel.repoName)}/branch/${slugify(data.flatRel.relName)}/files/${
file.fullPath.split('/')
.map((pathPart) => {
return pathPart.split('.').map((subPart) => {26 27 28 29 30 31
return m('li', {class: 'list-group-item'}, [
file.isDirectory ? m.trust('<span>📁 </span>') : null,
m('a', {
href: `${data.reposPath}/${slugify(data.flatRef.repoName)}/branch/${slugify(data.flatRef.relName)}/files/${
file.fullPath.split('/')
.map((pathPart) => {
return pathPart.split('.').map((subPart) => {2 3 4 5 6 7
export default async (eleventyConfig: any) => {
return async (data) => {
const branch: Branch = data.currentRel
return branch.fileList.get(data.fileInfo.file).fileInfo.contents
}2 3 4 5 6 7
export default async (eleventyConfig: any) => {
return async (data) => {
const branch: Branch = data.currentRef
return branch.fileList.get(data.fileInfo.file).fileInfo.contents
}30 31 32 33 34 35
// todo: this is probably broken for repos that use fewer than 6 languages
let languagePercentages: Array<[string, number]> = []
const total = Array.from(rel.fileList.keys()).length
for (const entry of languageCounts) {
languagePercentages.push([entry[0], entry[1] / total])30 31 32 33 34 35
// todo: this is probably broken for repos that use fewer than 6 languages
let languagePercentages: Array<[string, number]> = []
const total = Array.from(ref.fileList.keys()).length
for (const entry of languageCounts) {
languagePercentages.push([entry[0], entry[1] / total])45 46 47 48 49 50
const largestPercent = Math.max(...topLanguagePercentages.map(tuple => tuple[1]), otherLanguagePercent)
const readmeContent = await renderContentIfAvailable(await getReadMe(repo.name, rel.name), rel.name)
const pageContent = [
m('div', {class: "row"}, [45 46 47 48 49 50
const largestPercent = Math.max(...topLanguagePercentages.map(tuple => tuple[1]), otherLanguagePercent)
const readmeContent = await renderContentIfAvailable(await getReadMe(repo.name, ref.name), ref.name)
const pageContent = [
m('div', {class: "row"}, [102 103 104 105 106 107 108 109 110 111 112
m('div', {class: "row mt-2"}, [
m('div', {class: "col"}, [
m('p', {class: "font-monospace text-white mb-2 d-inline-block"}, [
m('a', {class: "btn btn-outline-info badge shadow-none me-2", href: nav.repoCurrentBranchRssFeed()}, [
m('img', {src: `${nav.rootPath()}frontend/img/rss-icon.svg`, style: "width: 11px; margin-right: 5px;"}),
'RSS'
]),
`Latest commit: ${latestCommit.date.toDateString()} `,
m('a', {class: "fw-bold link-info", href: `${nav.repoBranchCommitsBase()}${latestCommit.hash}`}, latestCommit.hash.substr(0, 6)),
' ',
latestCommitMessage,
])102 103 104 105 106 107 108 109 110 111 112
m('div', {class: "row mt-2"}, [
m('div', {class: "col"}, [
m('p', {class: "font-monospace text-white mb-2 d-inline-block"}, [
m('a', {class: "btn btn-outline-info badge shadow-none me-2", href: nav.rssFeed()}, [
m('img', {src: `${nav.rootPath()}frontend/img/rss-icon.svg`, style: "width: 11px; margin-right: 5px;"}),
'RSS'
]),
`Latest commit: ${latestCommit.date.toDateString()} `,
m('a', {class: "fw-bold link-info", href: `${nav.commit(latestCommit.hash)}`}, latestCommit.hash.substr(0, 6)),
' ',
latestCommitMessage,
])7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
data: any,
) => {
const slugify = eleventyConfig.getFilter("slugify")
const nav = NavHelper(reposConfig, slugify, data.flatRel.repoName, data.flatRel.relName)
const tags = data.flatRels.filter(rel => rel.type === "tag")
const branchCards = (tags) => {
return m('ul', tags.map((tag) => {
return tag.repoName === data.flatRel.repoName ?
m('li', [
m('a', {
href: `${data.reposPath}/${slugify(tag.repoName)}/tag/${slugify(tag.relName)}/tags`
}, tag.relName),
tag.relName === data.flatRel.relName
? m('div', {class: "badge rounded-pill bg-secondary mx-1"}, 'current') : null,
m('ul', [
tag.description ? m('li', tag.description) : null7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
data: any,
) => {
const slugify = eleventyConfig.getFilter("slugify")
const nav = NavHelper({
reposConfig,
slugify,
currentRepoName: data.flatRef.repoName,
currentRefName: data.flatRef.refName,
currentRefType: data.flatRef.refType,
})
const tags = data.flatRefs.filter(ref => ref.type === "tag")
const branchCards = (tags) => {
return m('ul', tags.map((tag) => {
return tag.repoName === data.flatRef.repoName ?
m('li', [
m('a', {
href: `${data.reposPath}/${slugify(tag.repoName)}/tag/${slugify(tag.refName)}/tags`
}, tag.refName),
tag.refName === data.flatRef.refName
? m('div', {class: "badge rounded-pill bg-secondary mx-1"}, 'current') : null,
m('ul', [
tag.description ? m('li', tag.description) : null1 2 3 4 5 6
import util from 'util'
import childProcess from 'child_process'
import {repos, getBranchesAndTags} from './src/repos.ts'
import getFlatRels from './src/flatRels.ts'
import flatFiles from './src/flatFiles.ts'
import flatPatches from './src/flatPatches.ts'
import paginatedPatches, {type PatchPage} from './src/paginatedPatches.ts'1 2 3 4 5 6
import util from 'util'
import childProcess from 'child_process'
import {repos, getBranchesAndTags} from './src/repos.ts'
import getFlatRefs from './src/flatRefs.ts'
import flatFiles from './src/flatFiles.ts'
import flatPatches from './src/flatPatches.ts'
import paginatedPatches, {type PatchPage} from './src/paginatedPatches.ts'88 89 90 91 92 93 94
eleventyConfig.addGlobalData("reposConfig", reposConfiguration)
eleventyConfig.addGlobalData("reposPath", reposPath)
const flatRels = getFlatRels(reposData)
eleventyConfig.addGlobalData("flatRels", flatRels)
eleventyConfig.addFilter("getFileName", (filePath: string) => {
const pathParts = filePath.split("/")88 89 90 91 92 93 94
eleventyConfig.addGlobalData("reposConfig", reposConfiguration)
eleventyConfig.addGlobalData("reposPath", reposPath)
const flatRefs = getFlatRefs(reposData)
eleventyConfig.addGlobalData("flatRefs", flatRefs)
eleventyConfig.addFilter("getFileName", (filePath: string) => {
const pathParts = filePath.split("/")253 254 255 256 257 258 259
return isDirectory
})
eleventyConfig.addFilter("pagesJustForRel", (pages: Array<PatchPage>, repoName: string, relName: string, relType: "branch" | "tag") => {
return pages.filter(page => page.repoName === repoName && page.relName === relName && page.type === relType)
})
eleventyConfig.addFilter("date", (dateString: string) => {253 254 255 256 257 258 259
return isDirectory
})
eleventyConfig.addFilter("pagesJustForRef", (pages: Array<PatchPage>, repoName: string, refName: string, refType: "branch" | "tag") => {
return pages.filter(page => page.repoName === repoName && page.refName === refName && page.type === refType)
})
eleventyConfig.addFilter("date", (dateString: string) => {382 383 384 385 386 387 388
permalink: (data) => {
const repoName = data.fileInfo.repoName
const branchName = data.fileInfo.branchName
const relType = data.fileInfo.type
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/${relType}/${eleventyConfig.getFilter("slugify")(branchName)}/files/${data.fileInfo.file.split('/').map((filePart) => filePart.split('.').map((subPart) => eleventyConfig.getFilter("slugify")(subPart)).join('.')).join('/')}.html`
},
eleventyComputed: {
nav: {382 383 384 385 386 387 388
permalink: (data) => {
const repoName = data.fileInfo.repoName
const branchName = data.fileInfo.branchName
const refType = data.fileInfo.type
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/${refType}/${eleventyConfig.getFilter("slugify")(branchName)}/files/${data.fileInfo.file.split('/').map((filePart) => filePart.split('.').map((subPart) => eleventyConfig.getFilter("slugify")(subPart)).join('.')).join('/')}.html`
},
eleventyComputed: {
nav: {394 395 396 397 398 399 400 401 402 403
currentRepo: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}),
currentRel: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}).branches.find(branch => {
return branch.name === data.fileInfo.branchName
}),
},
navTab: "files",
}394 395 396 397 398 399 400 401 402 403 404
currentRepo: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}),
currentRef: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}).branches.find(branch => {
return branch.name === data.fileInfo.branchName
}),
currentRefType: (data) => data.fileInfo.refType,
},
navTab: "files",
}419 420 421 422 423 424 425 426 427 428 429 430 431 432
permalink: (data) => {
const repoName = data.fileInfo.repoName
const branchName = data.fileInfo.branchName
const relType = data.fileInfo.type
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/${relType}/${eleventyConfig.getFilter("slugify")(branchName)}/raw/${data.fileInfo.file.split('.').map(filePart => eleventyConfig.getFilter("slugify")(filePart)).join('.')}`
},
eleventyComputed: {
currentRel: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}).branches.find(branch => {
return branch.name === data.fileInfo.branchName
}),
}
}
)419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
permalink: (data) => {
const repoName = data.fileInfo.repoName
const branchName = data.fileInfo.branchName
const refType = data.fileInfo.type
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/${refType}/${eleventyConfig.getFilter("slugify")(branchName)}/raw/${data.fileInfo.file.split('.').map(filePart => eleventyConfig.getFilter("slugify")(filePart)).join('.')}`
},
eleventyComputed: {
currentRef: (data) => reposData.find(repo => {
return repo.name === data.fileInfo.repoName
}).branches.find(branch => {
return branch.name === data.fileInfo.branchName
}),
currentRefType: (data) => data.fileInfo.refType,
}
}
)
-1 0 1 2 3 4 5 6
import { expect, test } from 'vitest'
import { getGitDiffsFromPatchText } from '../../dist/src/helpers.js'
import { singleCommit, largerCommit } from './fixtures/patches.js'
test("asdf", () => {
const result = getGitDiffsFromPatchText(largerCommit)
console.log(result[0])
expect(true).toBe(true)
})0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
export type Repository = {
name: string,
description?: string,
cloneUrl: string,
defaultBranch: string,
branches: Array<{
name: string,
head: string,
fileList: Array<string>,
}>,
tags?: Array<{
name: string,
sha: string,
fileList: Array<string>,
}>,
<<<<<<< HEAD
commits: Map<string, {
hash: string,
=======
commits?: Map<string, {
>>>>>>> 359136b (allow commit references to be null, e.g. for the first commit which has no parent)
message: string,
author: string,
date: Date,
parent: string | null,
diffs: Array<{
fileName: string,
lineNumber: number,
beforeText: string,
afterText: string,
}>
}>,
}
2 3 4 5 6 7
type FlatPatchRecord = {
commit: ReturnType<Repository['commits']['get']>,
repoName: string,
relName: string,
type: "branch" | "tag",
}
2 3 4 5 6 7
type FlatPatchRecord = {
commit: ReturnType<Repository['commits']['get']>,
repoName: string,
refName: string,
type: "branch" | "tag",
}
22 23 24 25 26 27
type: "branch",
commit: currentCommit,
repoName: repo.name,
relName: branch.name
})
currentCommit = repo.commits.get(currentCommit.parent)22 23 24 25 26 27
type: "branch",
commit: currentCommit,
repoName: repo.name,
refName: branch.name
})
currentCommit = repo.commits.get(currentCommit.parent)39 40 41 42 43 44
type: "tag",
commit: currentCommit,
repoName: repo.name,
relName: tag.name,
})
currentCommit = repo.commits.get(currentCommit.parent)39 40 41 42 43 44
type: "tag",
commit: currentCommit,
repoName: repo.name,
refName: tag.name,
})
currentCommit = repo.commits.get(currentCommit.parent)0 1 2 3 4 5
import { type Repository } from "./dataTypes.ts"
type BranchEntry = {
relName: string,
type: "branch",
repoName: string,
compareTo: string,0 1 2 3 4 5
import { type Repository } from "./dataTypes.ts"
type BranchEntry = {
refName: string,
type: "branch",
repoName: string,
compareTo: string,9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
}
type TagEntry = {
relName: string,
type: "tag",
repoName: string,
}
let cachedRels: Array<BranchEntry | TagEntry> | null = null
export default (repos: Array<Repository>) => {
if (cachedRels !== null) { return cachedRels }
cachedRels = repos.flatMap((repo) => {
const branches: Array<BranchEntry> = repo.branches.map((branch) => {
const result: BranchEntry = {
relName: branch.name,
type: "branch",
repoName: repo.name,
compareTo: branch.compareTo,9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
}
type TagEntry = {
refName: string,
type: "tag",
repoName: string,
}
let cachedRefs: Array<BranchEntry | TagEntry> | null = null
export default (repos: Array<Repository>) => {
if (cachedRefs !== null) { return cachedRefs }
cachedRefs = repos.flatMap((repo) => {
const branches: Array<BranchEntry> = repo.branches.map((branch) => {
const result: BranchEntry = {
refName: branch.name,
type: "branch",
repoName: repo.name,
compareTo: branch.compareTo,34 35 36 37 38 39
})
const tags: Array<TagEntry> = repo.tags.map((tag) => {
return {
relName: tag.name,
type: "tag",
repoName: repo.name,
}34 35 36 37 38 39
})
const tags: Array<TagEntry> = repo.tags.map((tag) => {
return {
refName: tag.name,
type: "tag",
repoName: repo.name,
}43 44 45 46
return [...branches, ...tags]
})
return cachedRels
}43 44 45 46
return [...branches, ...tags]
})
return cachedRefs
}2 3 4 5 6 7
export type PatchPage = {
repoName: string,
relName: string,
type: "branch" | "tag",
commits: Array<ReturnType<Repository['commits']['get']>>,
pageNumber: number,2 3 4 5 6 7
export type PatchPage = {
repoName: string,
refName: string,
type: "branch" | "tag",
commits: Array<ReturnType<Repository['commits']['get']>>,
pageNumber: number,21 22 23 24 25 26
const index = paginatedPatches.findIndex((page) => {
return (
page.repoName === patch.repoName
&& page.relName == patch.relName
&& page.type == patch.type
&& page.commits.length <= patchesPerPage
)21 22 23 24 25 26
const index = paginatedPatches.findIndex((page) => {
return (
page.repoName === patch.repoName
&& page.refName == patch.refName
&& page.type == patch.type
&& page.commits.length <= patchesPerPage
)30 31 32 33 34 35 36 37 38 39 40
if (index === -1) {
const pageNumber = paginatedPatches.filter(page => (
page.repoName === patch.repoName
&& page.relName === patch.relName
&& page.type === patch.type
)).length + 1
paginatedPatches.push({
repoName: patch.repoName,
relName: patch.relName,
commits: [patch.commit],
type: patch.type,
// current page number is one more than "how many items in paginatedPatches already30 31 32 33 34 35 36 37 38 39 40
if (index === -1) {
const pageNumber = paginatedPatches.filter(page => (
page.repoName === patch.repoName
&& page.refName === patch.refName
&& page.type === patch.type
)).length + 1
paginatedPatches.push({
repoName: patch.repoName,
refName: patch.refName,
commits: [patch.commit],
type: patch.type,
// current page number is one more than "how many items in paginatedPatches already26 27 28 29 30 31
const cachedBranchNames = branchesForReposMap.get(repoName)
const cachedTagNames = tagsForReposMap.get(repoName)
if (cachedBranchNames !== undefined) {
console.log({branches: cachedBranchNames, tags: cachedTagNames})
return {branches: cachedBranchNames, tags: cachedTagNames}
}
26 27 28 29 30
const cachedBranchNames = branchesForReposMap.get(repoName)
const cachedTagNames = tagsForReposMap.get(repoName)
if (cachedBranchNames !== undefined) {
return {branches: cachedBranchNames, tags: cachedTagNames}
}
127 128 129 130 131 132 133
}).flat()
}).flat()
console.log(tags)
if (branchesForReposMap.get(repoName) === undefined) {
branchesForReposMap.set(repoName, branches)
}127 128 129 130 131
}).flat()
}).flat()
if (branchesForReposMap.get(repoName) === undefined) {
branchesForReposMap.set(repoName, branches)
}