UNPKG

798 BJavaScriptView Raw
1
2module.exports = BranchDeletion;
3
4function BranchDeletion (branch, hash) {
5 this.branch = branch;
6 this.hash = hash;
7 this.success = hash !== null;
8}
9
10BranchDeletion.deleteSuccessRegex = /(\S+)\s+\(\S+\s([^\)]+)\)/;
11BranchDeletion.deleteErrorRegex = /^error[^']+'([^']+)'/;
12
13BranchDeletion.parse = function (data, asArray) {
14 var result;
15 var branchDeletions = data.trim().split('\n').map(function (line) {
16 if (result = BranchDeletion.deleteSuccessRegex.exec(line)) {
17 return new BranchDeletion(result[1], result[2]);
18 }
19 else if (result = BranchDeletion.deleteErrorRegex.exec(line)) {
20 return new BranchDeletion(result[1], null);
21 }
22 })
23 .filter(Boolean);
24
25 return asArray ? branchDeletions : branchDeletions.pop();
26};