wip: cli git parsing

This commit is contained in:
Lars Hampe 2024-10-25 19:50:21 +02:00
parent a42342b99d
commit 4a4eea5e91

View File

@ -1,18 +1,8 @@
const GITFORMAT = `--pretty=format:{ const GITFORMAT = `--pretty=format:{%n "commit": "%h",%n "parent": "%p",%n "refs": "%D",%n "subject": "%s",%n "notes": "%N",%n "body": "%b",%n "author": { "name": "%aN", "email": "%aE", "date": "%ad" },%n "commiter": { "name": "%cN", "email": "%cE", "date": "%cd" }%n},`
"commit": "%h",
"parent": "%p",
"refs": "%D",
"subject": "%s",
"notes": "%N",
"body": "%b",
"author": { "name": "%aN", "email": "%aE", "date": "%ad" },
"commiter": { "name": "%cN", "email": "%cE", "date": "%cd" }
},`
export const git_log = async ( export const git_log = async (
from: string | undefined, from: string | undefined,
to = 'HEAD', to = 'HEAD',
// biome-ignore lint/suspicious/noExplicitAny: <explanation> ): Promise<boolean> => {
): Promise<any[]> => {
// https://git-scm.com/docs/pretty-formats // https://git-scm.com/docs/pretty-formats
const r = await Bun.spawn([ const r = await Bun.spawn([
'git', 'git',
@ -24,22 +14,8 @@ export const git_log = async (
'--date=iso', '--date=iso',
]) ])
const text = await new Response(r.stdout).text() const text = await new Response(r.stdout).text()
console.log(text) // console.log(JSON.parse('[' + text.slice(0, -1) + ']'))
r /* eturn text // const str = JSON.stringify(`[${text.slice(0, -1)}]`)
.split('----\n') // console.log(JSON.parse(str))
.splice(1) return false
.map((line) => {
const [firstLine, , ..._body] = line.split('\n')
const [message, shortHash, authorName, date, authorEmail] =
firstLine.split('|')
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const r: any = {
date,
message,
shortHash,
author: { name: authorName, email: authorEmail },
body: _body.join('\n'),
}
return r
}) */
} }