Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'Examples',
' $ conventional-commits-detector',
' $ conventional-commits-detector 10'
],
pkg: pkg
});
let input = cli.input[0];
let sampleCount;
let commits = [];
if (input) {
sampleCount = parseInt(input, 10);
}
gitRawCommits({
from: sampleCount ? 'HEAD~' + sampleCount : null
})
.on('error', (err) => {
console.error(err.message);
process.exit(1);
})
.pipe(through((data, enc, cb) => {
commits.push(data.toString());
cb();
}, () => {
let convention = conventionalCommitsDetector(commits);
console.log(convention);
}));
function mockNoCommits() {
gitRawCommits.mockReset()
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
readable.push(null)
readable.emit('close')
return readable
})
}
function mockGroup(commits) {
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
commits.forEach(commit => {
const {
hash, author, date, subject, body,
} = commit
readable.push(`\n${hash}\n${author}\n${date}\n${subject}\n${body}\n`)
})
readable.push(null)
readable.emit('close')
return readable
})
}
function mockNoCommits() {
gitRawCommits.mockReset()
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
readable.push(null)
readable.emit('close')
return readable
})
}
return new Promise((resolve, reject) => {
gitRawCommits({ format: '%B%n-hash-%n%H', from: tag })
.pipe(commitsParser())
.pipe(concat(function (data) {
const commits = commitsFilter(data)
if (!commits || !commits.length) {
reject(null)
} else {
resolve(commits)
}
}))
})
}
return new Promise((resolve, reject) => {
gitRawCommits({ format: '%B%n-hash-%n%H', from: tag })
.pipe(commitsParser())
.pipe(concat(function (data) {
const commits = commitsFilter(data)
if (!commits || !commits.length) {
reject(null)
} else {
resolve(commits)
}
}))
})
}
return new Promise((resolve, reject) => {
const data = [];
gitRawCommits(options, {cwd: opts.cwd})
.on('data', chunk => data.push(chunk.toString('utf-8')))
.on('error', reject)
.on('end', () => {
resolve(data);
});
});
}