Skip to content

Commit b25a023

Browse files
committed
Fix author long names
1 parent c2ca67d commit b25a023

File tree

3 files changed

+82
-6
lines changed

3 files changed

+82
-6
lines changed

src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function parseGitPatch(patch: string) {
9797
nA++
9898
nB++
9999

100-
if (line === '-- ') {
100+
if (line === '-- ' || line === '--') {
101101
return
102102
}
103103
if (line.startsWith('+')) {
@@ -141,7 +141,12 @@ function splitMetaInfo(patch: string, lines: string[]) {
141141

142142
const [, hash] = match1
143143

144-
const authorLine = lines.shift()
144+
let authorLine = lines.shift()
145+
146+
// Parsing of long names
147+
while (lines[0].startsWith(' ')) {
148+
authorLine += ` ${lines.shift()}`
149+
}
145150

146151
if (!authorLine) return null
147152

@@ -165,7 +170,7 @@ function splitMetaInfo(patch: string, lines: string[]) {
165170

166171
return {
167172
hash,
168-
authorName,
173+
authorName: formatAuthorName(authorName),
169174
authorEmail,
170175
date,
171176
message,
@@ -196,4 +201,8 @@ function splitIntoParts(lines: string[], separator: string) {
196201
return parts
197202
}
198203

204+
function formatAuthorName(name: string) {
205+
return (name.startsWith('"') && name.endsWith('"') ? name.slice(1, -1) : name).trim()
206+
}
207+
199208
export default parseGitPatch

test/index.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,9 @@ test('parses a add and delete patch', () => {
333333
test('parses a add and delete patch with hyphen', () => {
334334
const result = parse(data['hyphen.patch'])
335335

336-
console.log('result', JSON.stringify(parse(data['hyphen.patch']), null, 2))
337-
338336
expect(result).toEqual({
339337
hash: '89afcd42fb6f2602fbcd03d6e5573b1859347787',
340-
authorName: '"Restyled.io"',
338+
authorName: 'Restyled.io',
341339
authorEmail: '[email protected]',
342340
date: 'Fri, 17 Jan 2025 18:09:56 +0000',
343341
message: '[PATCH 2/2] Restyled by prettier-yaml',
@@ -372,3 +370,45 @@ test('parses a add and delete patch with hyphen', () => {
372370
test('parses a complex patch 2', () => {
373371
parse(data['complex.patch'])
374372
})
373+
374+
test('parses a long author name', () => {
375+
const result = parse(data['one-file-author-line-break.patch'])
376+
377+
expect(result).toEqual({
378+
hash: '0f6f88c98fff3afa0289f46bf4eab469f45eebc6',
379+
date: 'Sat, 25 Jan 2020 19:21:35 +0200',
380+
message: '[PATCH] JSON stringify string responses',
381+
authorEmail: '[email protected]',
382+
authorName: 'Really long name spanning lots of characters',
383+
files: [
384+
{
385+
added: false,
386+
deleted: false,
387+
beforeName: 'src/events/http/HttpServer.js',
388+
afterName: 'src/events/http/HttpServer.js',
389+
modifiedLines: [
390+
{
391+
line: ' if (result && typeof result.body !== \'undefined\') {',
392+
lineNumber: 773,
393+
added: false,
394+
},
395+
{
396+
line: ' if (typeof result === \'string\') {',
397+
lineNumber: 773,
398+
added: true,
399+
},
400+
{
401+
line: ' response.source = JSON.stringify(result)',
402+
lineNumber: 774,
403+
added: true,
404+
},
405+
{
406+
line: ' } else if (result && typeof result.body !== \'undefined\') {',
407+
lineNumber: 775,
408+
added: true,
409+
},
410+
],
411+
},
412+
],
413+
})
414+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 0f6f88c98fff3afa0289f46bf4eab469f45eebc6 Mon Sep 17 00:00:00 2001
2+
From: Really long name spanning lots of characters
3+
4+
Date: Sat, 25 Jan 2020 19:21:35 +0200
5+
Subject: [PATCH] JSON stringify string responses
6+
7+
---
8+
src/events/http/HttpServer.js | 4 +++-
9+
1 file changed, 3 insertions(+), 1 deletion(-)
10+
11+
diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js
12+
index 20bf454..c0fdafb 100644
13+
--- a/src/events/http/HttpServer.js
14+
+++ b/src/events/http/HttpServer.js
15+
@@ -770,7 +770,9 @@ export default class HttpServer {
16+
override: false,
17+
})
18+
19+
- if (result && typeof result.body !== 'undefined') {
20+
+ if (typeof result === 'string') {
21+
+ response.source = JSON.stringify(result)
22+
+ } else if (result && typeof result.body !== 'undefined') {
23+
if (result.isBase64Encoded) {
24+
response.encoding = 'binary'
25+
response.source = Buffer.from(result.body, 'base64')
26+
--
27+
2.21.1 (Apple Git-122.3)

0 commit comments

Comments
 (0)