5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-08 08:26:55 +00:00
commitlint-github-action/src/gitCommits.js
Wagner Santos 51913c302c style: add eslint to the project
The config is based on airbnb shared config, with some rules that work better with the project.
2021-02-18 14:43:25 -03:00

43 lines
951 B
JavaScript

const dargs = require('dargs')
const execa = require('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
}
module.exports = gitCommits