import { classifyPath } from './classify.ts'
import { getCommitDetail } from './github.ts'
import { loadIgnoreIndex } from './ignore-rules.ts'
import { getRepoSettings } from './storage.ts'
/**
* Re-fetch one commit and show how Lineage classifies each file.
* Use this to debug empty buckets or generated-file filters.
*
* @param input.sha - Commit SHA to inspect
* @returns File classifications and countable totals
*
* @example
* import inspectCommit from 'kody:@kentcdodds/lineage/inspect-commit'
*
* const report = await inspectCommit({ sha: '35878a47ef4aa3567eb6f6b5ea4d3d2c753934b5' })
*/
export default async function inspectCommit(input: { sha?: string } = {}) {
const repo = await getRepoSettings()
const sha = input.sha || '35878a47ef4aa3567eb6f6b5ea4d3d2c753934b5'
const [detail, ignore] = await Promise.all([
getCommitDetail(repo, sha),
loadIgnoreIndex(),
])
const files = (detail.files ?? []).map((file) => {
const classification = classifyPath(file.filename, {
patch: file.patch,
ignore,
})
return {
filename: file.filename,
additions: file.additions,
deletions: file.deletions,
...classification,
}
})
return {
sha: detail.sha,
fileCount: files.length,
dataKeys: Object.keys(detail),
countable: files.filter((file) => file.countable).length,
skipped: files.filter((file) => !file.countable),
counted: files.filter((file) => file.countable),
}
}