-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from yoouyeon/main
[engine] getCommitRaws 함수 개선
- Loading branch information
Showing
5 changed files
with
143 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const COMMIT_SEPARATOR = "4itc2s8hH-oA64s08h19"; | ||
export const GIT_LOG_SEPARATOR = "I9M-0XOzvHlYPegVPpzb"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { getCommitMessageType } from "./commit.util"; | ||
import getCommitRaws from "./parser"; | ||
import { COMMIT_SEPARATOR, GIT_LOG_SEPARATOR } from "./constant"; | ||
import getCommitRaws from "./parser"; | ||
import type { CommitRaw, DifferenceStatistic } from "./types"; | ||
|
||
describe("commit message type", () => { | ||
|
@@ -34,113 +35,114 @@ describe("commit message type", () => { | |
}); | ||
}); | ||
|
||
describe('getCommitRaws', () => { | ||
const testCommitLines = [ | ||
"commit a b (HEAD)", | ||
"commit a b (HEAD -> main, origin/main, origin/HEAD)", | ||
"commit a b (HEAD, tag: v1.0.0)", | ||
"commit a b (HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0)", | ||
"commit a b (HEAD, tag: v2.0.0, tag: v1.4)" | ||
describe("getCommitRaws", () => { | ||
const testAuthorCommitter = [ | ||
"John Park", | ||
"[email protected]", | ||
"Sun Sep 4 20:17:59 2022 +0900", | ||
"John Park 2", | ||
"[email protected]", | ||
"Sun Sep 5 20:17:59 2022 +0900", | ||
]; | ||
|
||
const expectedBranches = [ | ||
['HEAD'], | ||
['HEAD', 'main', 'origin/main', 'origin/HEAD'], | ||
['HEAD'], | ||
['HEAD', 'main', 'origin/main', 'origin/HEAD'], | ||
['HEAD'] | ||
const testRefs = [ | ||
"HEAD", | ||
"HEAD -> main, origin/main, origin/HEAD", | ||
"HEAD, tag: v1.0.0", | ||
"HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0", | ||
"HEAD, tag: v2.0.0, tag: v1.4", | ||
]; | ||
|
||
const expectedTags = [ | ||
[], | ||
[], | ||
['v1.0.0'], | ||
['v2.0.0'], | ||
['v2.0.0', 'v1.4'] | ||
const testCommitHash = ["a", "b"]; | ||
|
||
const testCommitMessage = "commit message"; | ||
|
||
const testCommitLines = testRefs.map((ref) => | ||
[...testCommitHash, ref, ...testAuthorCommitter, testCommitMessage].join(GIT_LOG_SEPARATOR) | ||
); | ||
|
||
const expectedBranches = [ | ||
["HEAD"], | ||
["HEAD", "main", "origin/main", "origin/HEAD"], | ||
["HEAD"], | ||
["HEAD", "main", "origin/main", "origin/HEAD"], | ||
["HEAD"], | ||
]; | ||
|
||
const expectedTags = [[], [], ["v1.0.0"], ["v2.0.0"], ["v2.0.0", "v1.4"]]; | ||
|
||
const testCommitFileChanges = [ | ||
"10\t0\ta.ts\n1\t0\tREADME.md", | ||
"3\t3\ta.ts", | ||
"4\t0\ta.ts", | ||
"0\t6\ta.ts\n2\t0\tb.ts\n3\t3\tc.ts" | ||
"0\t6\ta.ts\n2\t0\tb.ts\n3\t3\tc.ts", | ||
]; | ||
|
||
const expectedFileChanged:DifferenceStatistic[] = [ | ||
const expectedFileChanged: DifferenceStatistic[] = [ | ||
{ | ||
totalInsertionCount: 11, | ||
totalDeletionCount: 0, | ||
fileDictionary: { | ||
'a.ts': { insertionCount: 10, deletionCount: 0 }, | ||
'README.md': { insertionCount: 1, deletionCount: 0 }, | ||
} | ||
"a.ts": { insertionCount: 10, deletionCount: 0 }, | ||
"README.md": { insertionCount: 1, deletionCount: 0 }, | ||
}, | ||
}, | ||
{ | ||
totalInsertionCount: 3, | ||
totalDeletionCount: 3, | ||
fileDictionary: { 'a.ts': { insertionCount: 3, deletionCount: 3 } } | ||
fileDictionary: { "a.ts": { insertionCount: 3, deletionCount: 3 } }, | ||
}, | ||
{ | ||
totalInsertionCount: 4, | ||
totalDeletionCount: 0, | ||
fileDictionary: { 'a.ts': { insertionCount: 4, deletionCount: 0 } } | ||
fileDictionary: { "a.ts": { insertionCount: 4, deletionCount: 0 } }, | ||
}, | ||
{ | ||
totalInsertionCount: 5, | ||
totalDeletionCount: 9, | ||
fileDictionary: { | ||
'a.ts': { insertionCount: 0, deletionCount: 6 }, | ||
'b.ts': { insertionCount: 2, deletionCount: 0 }, | ||
'c.ts': { insertionCount: 3, deletionCount: 3 }, | ||
} | ||
} | ||
"a.ts": { insertionCount: 0, deletionCount: 6 }, | ||
"b.ts": { insertionCount: 2, deletionCount: 0 }, | ||
"c.ts": { insertionCount: 3, deletionCount: 3 }, | ||
}, | ||
}, | ||
]; | ||
|
||
const commonExpectatedResult: CommitRaw={ | ||
const commonExpectatedResult: CommitRaw = { | ||
sequence: 0, | ||
id: 'a', | ||
parents: ['b'], | ||
branches: ['HEAD'], | ||
id: "a", | ||
parents: ["b"], | ||
branches: ["HEAD"], | ||
tags: [], | ||
author: { name: 'John Park', email: '[email protected]' }, | ||
authorDate: new Date('Sun Sep 4 20:17:59 2022 +0900'), | ||
committer: { name: 'John Park', email: '[email protected]' }, | ||
committerDate: new Date('Sun Sep 4 20:17:59 2022 +0900'), | ||
message: 'commit message', | ||
author: { name: testAuthorCommitter[0], email: testAuthorCommitter[1] }, | ||
authorDate: new Date(testAuthorCommitter[2]), | ||
committer: { name: testAuthorCommitter[3], email: testAuthorCommitter[4] }, | ||
committerDate: new Date(testAuthorCommitter[5]), | ||
message: testCommitMessage, | ||
differenceStatistic: { | ||
totalInsertionCount: 0, | ||
totalDeletionCount: 0, | ||
fileDictionary: {}, | ||
}, | ||
commitMessageType: "" | ||
commitMessageType: "", | ||
}; | ||
|
||
testCommitLines.forEach((mockLog, index) => { | ||
it(`should parse gitlog to commitRaw(branch, tag)`, () => { | ||
const mock = `${mockLog} | ||
Author: John Park <[email protected]> | ||
AuthorDate: Sun Sep 4 20:17:59 2022 +0900 | ||
Commit: John Park <[email protected]> | ||
CommitDate: Sun Sep 4 20:17:59 2022 +0900 | ||
\n\tcommit message | ||
`; | ||
const result = getCommitRaws(mock); | ||
const expectedResult = { ...commonExpectatedResult, branches: expectedBranches[index], tags: expectedTags[index] }; | ||
|
||
const result = getCommitRaws(COMMIT_SEPARATOR + mockLog); | ||
const expectedResult = { | ||
...commonExpectatedResult, | ||
branches: expectedBranches[index], | ||
tags: expectedTags[index], | ||
}; | ||
|
||
expect(result).toEqual([expectedResult]); | ||
}); | ||
}); | ||
|
||
testCommitFileChanges.forEach((mockLog, index) => { | ||
it(`should parse gitlog to commitRaw(file changed)`, () => { | ||
const mock = `commit a b (HEAD) | ||
Author: John Park <[email protected]> | ||
AuthorDate: Sun Sep 4 20:17:59 2022 +0900 | ||
Commit: John Park <[email protected]> | ||
CommitDate: Sun Sep 4 20:17:59 2022 +0900 | ||
\n\tcommit message | ||
\n${mockLog} | ||
`; | ||
const mock = `${COMMIT_SEPARATOR}${testCommitLines[0]}\n${mockLog}`; | ||
const result = getCommitRaws(mock); | ||
const expectedResult = { ...commonExpectatedResult, differenceStatistic: expectedFileChanged[index] }; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.