-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (55 loc) · 1.46 KB
/
index.js
File metadata and controls
67 lines (55 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var fs = require('fs');
class GitoliteParser {
constructor(){
}
parse(config, cb){
fs.stat(config, (err, stat) => {
if(err && !stat){
this.parseConfig(config, cb);
}else{
if(stat.isFile()){
this.parseFile(config, cb);
}
}
});
}
parseConfig(config, cb){
cb(null, this.splitRepos(config));
}
parseFile(path, cb){
fs.readFile(path, {encoding: 'utf8'}, (err, data) => {
cb(err, this.splitRepos(data));
});
}
parseRepo(repo){
var parts = repo.trim().split(' ');
parts.splice(0, 1);
return parts.join(' ');
}
splitRepos(config){
var repos = [];
var config_lines = config.split('\n');
var repo;
for(var i = 0; i < config_lines.length; i++){
if(config_lines[i].indexOf('repo') > -1){
if(repo){
repos.push(repo);
}
repo = {};
repo['title'] = this.parseRepo(config_lines[i]);
repo['rules'] = [];
}else{
if(config_lines[i].trim().length > 0){
repo['rules'].push(this.parseRule(config_lines[i]));
}
}
}
return repos;
}
parseRule(rule){
var parts = rule.split('=').map((x) => x.trim());
var people = parts[1].split(' ');
return { access: parts[0], keys: people };
}
}
module.exports = new GitoliteParser();