1 | const gitLogParser = require('git-log-parser');
|
2 | const getStream = require('get-stream');
|
3 | const debug = require('debug')('semantic-release:get-commits');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = async ({cwd, env, lastRelease: {gitHead}, logger}) => {
|
13 | if (gitHead) {
|
14 | debug('Use gitHead: %s', gitHead);
|
15 | } else {
|
16 | logger.log('No previous release found, retrieving all commits');
|
17 | }
|
18 |
|
19 | Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
20 | const commits = (await getStream.array(
|
21 | gitLogParser.parse({_: `${gitHead ? gitHead + '..' : ''}HEAD`}, {cwd, env: {...process.env, ...env}})
|
22 | )).map(commit => {
|
23 | commit.message = commit.message.trim();
|
24 | commit.gitTags = commit.gitTags.trim();
|
25 | return commit;
|
26 | });
|
27 | logger.log(`Found ${commits.length} commits since last release`);
|
28 | debug('Parsed commits: %o', commits);
|
29 | return commits;
|
30 | };
|