Tucker McKnight <tmcknight@instructure.com> | Tue May 26 2026
Make files() function return actual file contents and git blame info
9 10 11 12 13 14
import cloneUrl from './vcses/git/helpers.ts'
import { addBranchToCommitsMap } from './vcses/git/operations.ts'
import { getLocation} from './helpers.ts'
import { getFileList } from './vcses/git/operations.ts'
const exec = util.promisify(childProcess.exec)
9 10 11 12 13 14
import cloneUrl from './vcses/git/helpers.ts'
import { addBranchToCommitsMap } from './vcses/git/operations.ts'
import { getLocation} from './helpers.ts'
import { getFileList, getFileLastTouchInfo } from './vcses/git/operations.ts'
const exec = util.promisify(childProcess.exec)
225 226 227 228 229 230 231 232 233 234 235 236
defaultBranch: reposConfig.repos[repoName].defaultBranch,
tags: tags,
files: async (filename: string, sha: string) => {
return Promise.resolve({
contents: "Pretend like this is the text of the file.",
lastModified: new Date(),
blameLines: [
{ sha: 'abc123', author: 'You Did This' }
]
})
},
commits,
})225 226 227 228 229 230 231 232 233 234 235 236 237
defaultBranch: reposConfig.repos[repoName].defaultBranch,
tags: tags,
files: async (filename: string, sha: string) => {
const gitShowCmd = `git -C ${repoLocation} show ${sha}:${filename}`
const fileContents = (await exec(gitShowCmd)).stdout
const blameLines = await getFileLastTouchInfo(filename, sha, repoLocation)
return {
contents: fileContents,
lastModified: new Date(), //TODO: make lastModified check the actual modification date
blameLines,
}
},
commits,
})119 120 121 122 123 124 125 126 127
}
export const getFileLastTouchInfo = async (
branch: string, filename: string, repoLocation: string
) : Promise<Array<BlameInfo>> => {
const regex = RegExp(".* [0-9]+ [0-9]+")
const command = `git -C ${repoLocation} blame --porcelain ${branch} ${filename}`
const res = await exec(command)
const output = res.stdout
const outputLines = output.split("\n")119 120 121 122 123 124 125 126 127
}
export const getFileLastTouchInfo = async (
filename: string, sha: string, repoLocation: string
) : Promise<Array<BlameInfo>> => {
const regex = RegExp(".* [0-9]+ [0-9]+")
const command = `git -C ${repoLocation} blame --porcelain ${sha} ${filename}`
const res = await exec(command)
const output = res.stdout
const outputLines = output.split("\n")