-
Notifications
You must be signed in to change notification settings - Fork 1
/
webapp.js
51 lines (44 loc) · 1.35 KB
/
webapp.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
var api = require('./lib/api');
var parser = require('url');
module.exports = {
listRepos: function (userConfig, done) {
api.get_r(userConfig,"projects",function(err,data){
if(!err){
var repos = JSON.parse(data);
done(null, repos.map(api.parseRepo).filter(function(repo){
return repo.config.scm === 'git';
}));
} else {
console.log(err);
}
});
},
getFile: function (filename, ref, account, config, project, done) {
var id = project.provider.repo_id;
var branch = project.branches[0].name;
// GET /projects/:id/repository/blobs/branch?filepath=filename
var req = "projects/"+id+"/repository/blobs/"+branch+"?filepath="+filename;
api.get(account.config,req, function(err,data){
var content = "";
if(!err && data !== undefined){
content = JSON.parse(data);
}
done(err, content);
});
},
getBranches: function(account, config, project, done) {
var id = project.provider.repo_id;
var req = "projects/"+id+"/repository/branches";
var branches = [];
api.get(account, req, function(err, data){
var content = "";
if(!err && data !== undefined){
content = JSON.parse(data);
content.forEach(function(branch){
branches.push(branch.name);
});
}
done(err, branches);
});
},
};