Skip to content

Commit 4958c8a

Browse files
author
bear
committed
fix: result为空的时候报错
1 parent c8c721b commit 4958c8a

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

.picklogrc.devops.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ module.exports = {
33
{
44
name: 'Changes',
55
regExp: /[\u4e00-\u9fa5]/,
6-
}
6+
},
77
],
88
parse(commits){
9-
let output = '';
9+
const feats = []
10+
const fixs = []
11+
const others = []
1012

1113
commits.forEach((log) => {
1214
log.results.forEach((result) => {
13-
output += `${result.filter.name}:\n`;
14-
1515
result.commits.forEach((commit) => {
16-
output += `- ${commit.s} ${commit.an}\n`;
16+
const logText = `- ${commit.s} ${commit.an}`
17+
18+
if (/feat/.test(commit.s)) {
19+
feats.push(logText)
20+
} else if (/fix/.test(commit.s)) {
21+
fixs.push(logText)
22+
} else {
23+
others.push(logText)
24+
}
1725
});
1826
});
1927
});
2028

21-
return output;
29+
return `${feats.join('\n')}\n\n${fixs.join('\n')}\n\n${others.join('\n')}`;
2230
}
2331
};

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Picklog
22
====
3-
[![Build Status](https://travis-ci.org/BearJ/picklog.svg?branch=master)](https://travis-ci.org/BearJ/picklog)
43
[![npm version](https://img.shields.io/npm/v/picklog.svg)](https://www.npmjs.org/package/picklog)
54

65
根据你设置的filter,提取出你需要的log,从而生成changelog。可以生成`JSON``markdown`

bin/robot-report.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const picklog = require('../index');
4+
5+
const lastCommit = fs.readFileSync(path.resolve('.lastcommit'), 'utf8').trim();
6+
7+
picklog({
8+
gitLogArgs: `...${lastCommit}`,
9+
config: '.picklogrc.devops.js',
10+
}).then((text) => {
11+
console.log(text);
12+
});

src/lib/PrettyFormats.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ module.exports = {
4646
arg: `--pretty=${Object.values(format).join(SPLIT)}${END}`,
4747

4848
parse(result) {
49+
if (!result) return [];
50+
4951
const keys = Object.keys(format);
5052
const commitsStr = result.trim();
5153
if (!commitsStr.length) return [];

0 commit comments

Comments
 (0)