-
Notifications
You must be signed in to change notification settings - Fork 0
/
VCSGetter.js
55 lines (45 loc) · 1.38 KB
/
VCSGetter.js
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
const VCSSource = require('./VCSSource.js');
const VCSGetterConf = require('./VCSGetterConf.js');
const util = require('util');
const { GitTree } = require('./git');
const { TFSClient, TFSFolder } = require('./tfs');
class VCSGetter {
constructor(conf) {
this.conf = new VCSGetterConf(conf);
}
_findTfsCollection(collectionUrl) {
for(let i = 0; i < this.conf.tfs.collections.length; i++) {
if(collectionUrl == this.conf.tfs.collections[i].url || `${collectionUrl}/` == this.conf.tfs.collections[i].url) {
return this.conf.tfs.collections[i];
}
}
throw new Error(`Could not find configuration for collection '${collectionUrl}'`);
}
async get(source) {
let vcsSource;
if(typeof source == 'string') {
vcsSource = new VCSSource({ url: source });
} else {
vcsSource = new VCSSource(source);
}
switch(vcsSource.type) {
case 'git':
const gitTree = new GitTree({
gitTreeSource: vcsSource.source,
gitTreeConf: this.conf.git
});
return await gitTree.get();
case 'tfs':
const tfsClient = new TFSClient({
tfsConf: this.conf.tfs,
tfsCollection: this._findTfsCollection(vcsSource.source.collection)
});
const tfsFolder = new TFSFolder(tfsClient, vcsSource.source.path);
return tfsFolder.get();
break;
default:
throw new Error(`Unexpected vcsSource.type: ${vcsSource.type}`);
}
}
}
module.exports = VCSGetter;