5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 08:06:54 +00:00
commitlint-github-action/src/gitCommits.js
wagoid 5463926c07 feat: update dependencies that needed to switch to ESM syntax
Some packages were updated to versions that now use ECMAScript modules,
so this repo was updated to use ES modules using Node.js built-in support.

Update was done using the great guide from @sindresorhus:
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
2021-07-07 15:17:00 -03:00

43 lines
939 B
JavaScript

import dargs from 'dargs'
import execa from 'execa'
const commitDelimiter = '--------->commit---------'
const hashDelimiter = '--------->hash---------'
const format = `%H${hashDelimiter}%B%n${commitDelimiter}`
const buildGitArgs = (gitOpts) => {
const { from, to, ...otherOpts } = gitOpts
const formatArg = `--format=${format}`
const fromToArg = [from, to].filter(Boolean).join('..')
const gitArgs = ['log', formatArg, fromToArg]
return gitArgs.concat(
dargs(gitOpts, {
includes: Object.keys(otherOpts),
}),
)
}
const gitCommits = async (gitOpts) => {
const args = buildGitArgs(gitOpts)
const { stdout } = await execa('git', args, {
cwd: process.cwd(),
})
const commits = stdout.split(`${commitDelimiter}\n`).map((messageItem) => {
const [hash, message] = messageItem.split(hashDelimiter)
return {
hash,
message,
}
})
return commits
}
export default gitCommits