Skip to content

Commit 8259d3a

Browse files
committed
chore: add helper function and fix failing tests
1 parent c9a94a7 commit 8259d3a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/proxy/processors/push-action/parsePush.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const getParsedData = (headerLines: string[]) => {
142142

143143
switch (key) {
144144
case 'tree':
145-
if (parsedData.tree) {
145+
if (parsedData.tree !== '') {
146146
throw new Error('Multiple tree lines found in commit.');
147147
}
148148
parsedData.tree = value.trim();
@@ -151,13 +151,13 @@ const getParsedData = (headerLines: string[]) => {
151151
parsedData.parents.push(value.trim());
152152
break;
153153
case 'author':
154-
if (parsedData.author) {
154+
if (!isBlankPersonLine(parsedData.author)) {
155155
throw new Error('Multiple author lines found in commit.');
156156
}
157157
parsedData.author = parsePersonLine(value);
158158
break;
159159
case 'committer':
160-
if (parsedData.committer) {
160+
if (!isBlankPersonLine(parsedData.committer)) {
161161
throw new Error('Multiple committer lines found in commit.');
162162
}
163163
parsedData.committer = parsePersonLine(value);
@@ -176,20 +176,29 @@ const getParsedData = (headerLines: string[]) => {
176176
*/
177177
const validateParsedData = (parsedData: CommitHeader) => {
178178
const missing = [];
179-
if (!parsedData.tree) {
179+
if (parsedData.tree === '') {
180180
missing.push('tree');
181181
}
182-
if (!parsedData.author) {
182+
if (isBlankPersonLine(parsedData.author)) {
183183
missing.push('author');
184184
}
185-
if (!parsedData.committer) {
185+
if (isBlankPersonLine(parsedData.committer)) {
186186
missing.push('committer');
187187
}
188188
if (missing.length > 0) {
189189
throw new Error(`Invalid commit data: Missing ${missing.join(', ')}`);
190190
}
191191
}
192192

193+
/**
194+
* Checks if a person line is blank.
195+
* @param {PersonLine} personLine - The person line to check.
196+
* @return {boolean} True if the person line is blank, false otherwise.
197+
*/
198+
const isBlankPersonLine = (personLine: PersonLine): boolean => {
199+
return personLine.name === '' && personLine.email === '' && personLine.timestamp === '';
200+
}
201+
193202
/**
194203
* Parses the commit data from the contents of a pack file.
195204
* @param {CommitContent[]} contents - The contents of the pack file.

0 commit comments

Comments
 (0)