Skip to content

Commit 4274607

Browse files
committed
fix: rationalize parsePush.getCommitData in response to review
1 parent 041b6c7 commit 4274607

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ const getCommitData = (contents: CommitContent[]) => {
5959
.chain(contents)
6060
.filter({ type: 1 })
6161
.map((x) => {
62-
console.log({ x });
62+
console.debug({ x });
6363

6464
const formattedContent = x.content.split('\n');
65-
console.log({ formattedContent });
65+
console.debug({ formattedContent });
6666

6767
const parts = formattedContent.filter((part) => part.length > 0);
68-
console.log({ parts });
68+
console.debug({ parts });
6969

7070
if (!parts || parts.length < 5) {
7171
throw new Error('Invalid commit data');
@@ -75,51 +75,50 @@ const getCommitData = (contents: CommitContent[]) => {
7575
.find((t) => t.split(' ')[0] === 'tree')
7676
?.replace('tree', '')
7777
.trim();
78-
console.log({ tree });
78+
console.debug({ tree });
7979

8080
const parentValue = parts.find((t) => t.split(' ')[0] === 'parent');
81-
console.log({ parentValue });
81+
console.debug({ parentValue });
8282

8383
const parent = parentValue
8484
? parentValue.replace('parent', '').trim()
8585
: '0000000000000000000000000000000000000000';
86-
console.log({ parent });
86+
console.debug({ parent });
8787

88-
const author = parts
88+
const authorStr = parts
8989
.find((t) => t.split(' ')[0] === 'author')
9090
?.replace('author', '')
9191
.trim();
92-
console.log({ author });
93-
94-
const committer = parts
92+
// handle email-like author string: "UserName <[email protected]> 1746612538 +0100"
93+
const author = authorStr?.split('<')[0].trim();
94+
// slice to trim start and end from `<[email protected]>`
95+
const authorEmail = authorStr?.split(' ').reverse()[2].slice(1, -1);
96+
console.debug({ authorStr, author, authorEmail });
97+
98+
// handle email-like committer string: "UserName <[email protected]> 1746612538 +0100"
99+
const committerStr = parts
95100
.find((t) => t.split(' ')[0] === 'committer')
96101
?.replace('committer', '')
97102
.trim();
98-
console.log({ committer });
103+
const committer = committerStr?.split('<')[0].trim();
104+
const committerArr = committerStr?.split(' ').reverse() ?? [];
105+
const commitTimestamp = committerArr[1];
106+
// slice to trim start and end from `<[email protected]>`
107+
const committerEmail = committerArr[2]?.slice(1, -1);
108+
console.debug({ committerStr, committer, committerEmail, commitTimestamp });
99109

100110
const indexOfMessages = formattedContent.indexOf('');
101-
console.log({ indexOfMessages });
102-
103111
const message = formattedContent
104112
.slice(indexOfMessages + 1)
105113
.join(' ')
106114
.trim();
107-
console.log({ message });
108-
109-
const commitTimestamp = committer?.split(' ').reverse()[1];
110-
console.log({ commitTimestamp });
111-
112-
const authorEmail = author?.split(' ').reverse()[2].slice(1, -1);
113-
console.log({ authorEmail });
114-
115-
const committerEmail = committer?.split(' ').reverse()[2].slice(1, -1);
116-
console.log({ committerEmail });
115+
console.debug({ indexOfMessages, message });
117116

118117
console.log({
119118
tree,
120119
parent,
121-
author: author?.split('<')[0].trim(),
122-
committer: committer?.split('<')[0].trim(),
120+
author,
121+
committer,
123122
commitTimestamp,
124123
message,
125124
authorEmail,
@@ -142,8 +141,8 @@ const getCommitData = (contents: CommitContent[]) => {
142141
return {
143142
tree,
144143
parent,
145-
author: author.split('<')[0].trim(),
146-
committer: committer.split('<')[0].trim(),
144+
author,
145+
committer,
147146
commitTimestamp,
148147
message,
149148
authorEmail,

0 commit comments

Comments
 (0)