1 | 'use strict';
|
2 |
|
3 | function FetchSummary (raw) {
|
4 | this.raw = raw;
|
5 |
|
6 | this.remote = null;
|
7 | this.branches = [];
|
8 | this.tags = [];
|
9 | }
|
10 |
|
11 | FetchSummary.parsers = [
|
12 | [
|
13 | /From (.+)$/, function (fetchSummary, matches) {
|
14 | fetchSummary.remote = matches[0];
|
15 | }
|
16 | ],
|
17 | [
|
18 | /\* \[new branch\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
|
19 | fetchSummary.branches.push({
|
20 | name: matches[0],
|
21 | tracking: matches[1]
|
22 | });
|
23 | }
|
24 | ],
|
25 | [
|
26 | /\* \[new tag\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
|
27 | fetchSummary.tags.push({
|
28 | name: matches[0],
|
29 | tracking: matches[1]
|
30 | });
|
31 | }
|
32 | ]
|
33 | ];
|
34 |
|
35 | FetchSummary.parse = function (data) {
|
36 | var fetchSummary = new FetchSummary(data);
|
37 |
|
38 | String(data)
|
39 | .trim()
|
40 | .split('\n')
|
41 | .forEach(function (line) {
|
42 | var original = line.trim();
|
43 | FetchSummary.parsers.some(function (parser) {
|
44 | var parsed = parser[0].exec(original);
|
45 | if (parsed) {
|
46 | parser[1](fetchSummary, parsed.slice(1));
|
47 | return true;
|
48 | }
|
49 | });
|
50 | });
|
51 |
|
52 | return fetchSummary;
|
53 | };
|
54 |
|
55 | module.exports = FetchSummary;
|