forked from RoboPhred/concourse-svn-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.js
75 lines (58 loc) · 2.05 KB
/
check.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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
"use strict"
const exec = require("child_process").exec;
const xml2js = require("xml2js");
const shared = require("./shared");
const success = shared.success;
const fail = shared.fail;
const hide = shared.hide;
process.stdin.on("data", stdin => {
const data = JSON.parse(stdin);
const source = data.source || {};
const repository = source.repository || null;
const username = source.username || null;
const password = source.password || null;
const trustCert = source["trust_server_cert"];
if (!repository) {
fail(new Error("source.repository must be provided"));
}
let revision = null;
if (typeof data.version === 'object' && data.version != null) {
const revisionType = typeof data.version.revision;
if (revisionType === 'string' || revisionType === 'number') {
revision = String(data.version.revision);
}
}
let cmdLine = "svn log --non-interactive --no-auth-cache --xml";
if (username) {
// TODO: escape quotes in username
cmdLine += ' --username "' + username + '"';
}
if (password) {
// TODO: escape quotes in password
const passwdCmd = '--password "' + password + '"';
cmdLine += ' ' + passwdCmd;
hide(passwdCmd, '--password "*****"');
}
if (trustCert) {
cmdLine += ' --trust-server-cert';
}
if (revision) {
// TODO: Check targetVersion format. Escape quotes
cmdLine += ' -r ' + revision + ':HEAD';
}
// TODO: encode
cmdLine += ' "' + repository + '"';
exec(cmdLine, (err, stdout, stderr) => {
if (err) fail(err);
const parser = new xml2js.Parser({
explicitRoot: false
});
parser.parseString(stdout, (err, info) => {
if (err) fail(err);
const entries = info.logentry;
const versions = entries.map(x => x['$']).sort((a, b) => Number(a.revision) - Number(b.revision));
success(versions);
});
});
});