({ fs, gitdir, author, commit })
| 18 | * @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>} |
| 19 | */ |
| 20 | export async function normalizeAuthorObject({ fs, gitdir, author, commit }) { |
| 21 | const timestamp = Math.floor(Date.now() / 1000) |
| 22 | |
| 23 | const defaultAuthor = { |
| 24 | name: await _getConfig({ fs, gitdir, path: 'user.name' }), |
| 25 | email: (await _getConfig({ fs, gitdir, path: 'user.email' })) || '', // author.email is allowed to be empty string |
| 26 | timestamp, |
| 27 | timezoneOffset: new Date(timestamp * 1000).getTimezoneOffset(), |
| 28 | } |
| 29 | |
| 30 | // Populate author object by using properties with this priority: |
| 31 | // (1) provided author object |
| 32 | // -> (2) author of provided commit object |
| 33 | // -> (3) default author |
| 34 | const normalizedAuthor = assignDefined( |
| 35 | {}, |
| 36 | defaultAuthor, |
| 37 | commit ? commit.author : undefined, |
| 38 | author |
| 39 | ) |
| 40 | |
| 41 | if (normalizedAuthor.name === undefined) { |
| 42 | return undefined |
| 43 | } |
| 44 | |
| 45 | return normalizedAuthor |
| 46 | } |
no test coverage detected
searching dependent graphs…