-
Notifications
You must be signed in to change notification settings - Fork 16
/
webapp.js
62 lines (59 loc) · 1.69 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
52
53
54
55
56
57
58
59
60
61
62
'use strict';
var utils = require('./lib');
function sanitizeConfig(config) {
if (!config.auth) return false;
return {
url: config.url,
display_url: config.display_url,
cache: config.cache,
auth: {
type: config.auth.type,
privkey: config.auth.privkey,
pubkey: config.auth.pubkey,
username: config.auth.username,
password: config.auth.password,
},
};
}
module.exports = {
config: {
url: String,
display_url: String,
cache: Boolean,
auth: {
type: { type: String, enum: ['ssh', 'https', 'http'] },
privkey: String,
pubkey: String,
username: String,
password: String,
},
},
getBranches: function (userConfig, config, project, done) {
utils.getBranches(config, project.privkey, done);
},
// native git doesn't have a great way to just get a single file at an arbitrary revision
fastFile: false,
getFile: function (filename, ref, config, project, done) {
done(new Error('not implemented'));
// utils.gitcmd('git archive --remote=' + url + ' ' + (ref.fetch || ref.id) + ' .strider.json', ...);
},
routes: function (app, context) {
app.get('config', context.auth.requireProjectAdmin, function (req, res) {
res.send(req.providerConfig());
});
app.put('config', context.auth.requireProjectAdmin, function (req, res) {
// validate the config
var config = sanitizeConfig(req.body);
req.providerConfig(config, function (err) {
if (err) {
return res.status(500).send({ errors: [err.message] });
}
res.send({
success: true,
message: 'Saved git config!',
config: config,
});
});
});
},
};