Skip to content

Commit

Permalink
fix(plugin-utils): missing commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Jan 10, 2023
1 parent fc70666 commit 1acc033
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/plugins/utils/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,24 @@ export const getCurrentCommit = async () => {
export const getCommitMessage = async (commitHash: string) => {
try {
return await simpleGit()
.log({ from: commitHash, n: 1 })
.then((stats) => {
if (!stats.latest) {
throw new Error('No commit found')
}

return stats.latest.message.replace(/\n.*/g, '').substring(0, 255)
.show([commitHash, '--format=%s'])
.then((commitMessage: string) => {
return commitMessage.replace(/\n.*/g, '').substring(0, 255)
})
} catch {
return undefined
try {
// in github action, the commit maybe not in local
console.info(`Fetching commit '${commitHash}' information from origin.`)
await simpleGit().fetch(['origin', commitHash, '--depth', '1'])

return await simpleGit()
.show([commitHash, '--format=%s'])
.then((commitMessage: string) => {
return commitMessage.replace(/\n.*/g, '').substring(0, 255)
})
} catch {
return undefined
}
}
}

Expand Down

0 comments on commit 1acc033

Please sign in to comment.