1 |
|
2 | module.exports = ListLogSummary;
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function ListLogSummary (all) {
|
10 | this.all = all;
|
11 | this.latest = all.length && all[0] || null;
|
12 | this.total = all.length;
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | ListLogSummary.prototype.all = null;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | ListLogSummary.prototype.latest = null;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | ListLogSummary.prototype.total = 0;
|
32 |
|
33 | function ListLogLine (line, fields) {
|
34 | for (var k = 0; k < fields.length; k++) {
|
35 | this[fields[k]] = line[k];
|
36 | }
|
37 | }
|
38 |
|
39 | ListLogSummary.COMMIT_BOUNDARY = '------------------------ >8 ------------------------';
|
40 |
|
41 | ListLogSummary.parse = function (text, splitter, fields) {
|
42 | fields = fields || ['hash', 'date', 'message', 'author_name', 'author_email'];
|
43 | return new ListLogSummary(
|
44 | text
|
45 | .trim()
|
46 | .split(ListLogSummary.COMMIT_BOUNDARY + '\n')
|
47 | .map(function (item) {
|
48 | return item.replace(ListLogSummary.COMMIT_BOUNDARY, '')
|
49 | })
|
50 | .filter(Boolean)
|
51 | .map(function (item) {
|
52 | return new ListLogLine(item.trim().split(splitter), fields);
|
53 | })
|
54 | );
|
55 | };
|