-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(engine): extract functions from csm (#274)
* refactor: extract functions from csm * refactor: use map function * refactor: add dict types * refactor: move functions related with pr * refactor: rename function name * refactor: use pr in buildCSMNodeWithPullRequest * chore: disable vulnerabilities check
- Loading branch information
Showing
9 changed files
with
193 additions
and
163 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
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
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,78 @@ | ||
import { CommitNode, CommitRaw, PullRequest } from "./types"; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const convertPRCommitsToCommitNodes = ( | ||
baseCommit: CommitRaw, | ||
pr: PullRequest | ||
): CommitNode[] => | ||
pr.commitDetails.data.map((commitDetail) => { | ||
const { | ||
sha, | ||
parents, | ||
commit: { author, committer, message }, | ||
files, | ||
} = commitDetail; | ||
|
||
let totalInsertionCount = 0; | ||
let totalDeletionCount = 0; | ||
const fileDictionary = | ||
files?.reduce((dict, f) => { | ||
totalInsertionCount += f.additions; | ||
totalDeletionCount += f.deletions; | ||
return { | ||
...dict, | ||
[f.filename]: { | ||
insertionCount: f.additions, | ||
deletionCount: f.deletions, | ||
}, | ||
}; | ||
}, {}) ?? {}; | ||
|
||
const prCommitRaw: CommitRaw = { | ||
sequence: -1, // ignore | ||
id: sha, | ||
parents: parents.map((p) => p.sha), | ||
branches: [], // ignore | ||
tags: [], // ignore | ||
author: { | ||
name: author?.name ?? "", | ||
email: author?.email ?? "", | ||
}, | ||
authorDate: author?.date ? new Date(author.date) : baseCommit.authorDate, | ||
committer: { | ||
name: committer?.name ?? "", | ||
email: committer?.email ?? "", | ||
}, | ||
committerDate: committer?.date | ||
? new Date(committer.date) | ||
: baseCommit.committerDate, | ||
message, | ||
differenceStatistic: { | ||
fileDictionary, | ||
totalInsertionCount, | ||
totalDeletionCount, | ||
}, | ||
commitMessageType: "", | ||
}; | ||
|
||
return { commit: prCommitRaw } as CommitNode; | ||
}); | ||
|
||
export const convertPRDetailToCommitRaw = ( | ||
baseCommit: CommitRaw, | ||
pr: PullRequest | ||
): CommitRaw => { | ||
const { | ||
data: { title, body, additions, deletions }, | ||
} = pr.detail; | ||
|
||
return { | ||
...baseCommit, | ||
message: `${title}\n\n${body}`, | ||
differenceStatistic: { | ||
fileDictionary: {}, | ||
totalInsertionCount: additions, | ||
totalDeletionCount: deletions, | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.