UNPKG

1.32 kBJavaScriptView Raw
1
2module.exports = ListLogSummary;
3
4/**
5 * The ListLogSummary is returned as a response to getting `git().log()` or `git().stashList()`
6 *
7 * @constructor
8 */
9function ListLogSummary (all) {
10 this.all = all;
11 this.latest = all.length && all[0] || null;
12 this.total = all.length;
13}
14
15/**
16 * Detail for each of the log lines
17 * @type {ListLogLine[]}
18 */
19ListLogSummary.prototype.all = null;
20
21/**
22 * Most recent entry in the log
23 * @type {ListLogLine}
24 */
25ListLogSummary.prototype.latest = null;
26
27/**
28 * Number of items in the log
29 * @type {number}
30 */
31ListLogSummary.prototype.total = 0;
32
33function ListLogLine (line, fields) {
34 for (var k = 0; k < fields.length; k++) {
35 this[fields[k]] = line[k];
36 }
37}
38
39ListLogSummary.COMMIT_BOUNDARY = '------------------------ >8 ------------------------';
40
41ListLogSummary.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};