mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-19 22:53:08 +00:00
feat: Add git log parsing and rebase endpoint with input validation
This commit is contained in:
55
apps/server/src/lib/git-log-parser.ts
Normal file
55
apps/server/src/lib/git-log-parser.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
export interface CommitFields {
|
||||
hash: string;
|
||||
shortHash: string;
|
||||
author: string;
|
||||
authorEmail: string;
|
||||
date: string;
|
||||
subject: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export function parseGitLogOutput(output: string): CommitFields[] {
|
||||
const commits: CommitFields[] = [];
|
||||
|
||||
// Split by NUL character to separate commits
|
||||
const commitBlocks = output.split('\0').filter((block) => block.trim());
|
||||
|
||||
for (const block of commitBlocks) {
|
||||
const fields = block.split('\n');
|
||||
|
||||
// Validate we have all expected fields (at least hash, shortHash, author, authorEmail, date, subject)
|
||||
if (fields.length < 6) {
|
||||
continue; // Skip malformed blocks
|
||||
}
|
||||
|
||||
const commit: CommitFields = {
|
||||
hash: fields[0].trim(),
|
||||
shortHash: fields[1].trim(),
|
||||
author: fields[2].trim(),
|
||||
authorEmail: fields[3].trim(),
|
||||
date: fields[4].trim(),
|
||||
subject: fields[5].trim(),
|
||||
body: fields.slice(6).join('\n').trim(),
|
||||
};
|
||||
|
||||
commits.push(commit);
|
||||
}
|
||||
|
||||
return commits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a commit object from parsed fields, matching the expected API response format
|
||||
*/
|
||||
export function createCommitFromFields(fields: CommitFields, files?: string[]) {
|
||||
return {
|
||||
hash: fields.hash,
|
||||
shortHash: fields.shortHash,
|
||||
author: fields.author,
|
||||
authorEmail: fields.authorEmail,
|
||||
date: fields.date,
|
||||
subject: fields.subject,
|
||||
body: fields.body,
|
||||
files: files || [],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user