feat: add mirror support

This commit is contained in:
Richard Steinbrück
2020-04-05 16:26:31 +02:00
parent 79bc1c28ad
commit 1b34539e65
4 changed files with 144 additions and 48 deletions

View File

@ -91,6 +91,42 @@ function fillServers(template) {
JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password));
}
function fillMirror(template, id, name, mirrorOf, url) {
const mirrorXml = template.createElement('mirror');
if (!id || !name || !mirrorOf || !url) {
core.setFailed('mirrors must contain id, name, mirrorOf and url');
return;
}
const idXml = createElementWithText(template, 'id', id);
mirrorXml.appendChild(idXml);
const nameXml = createElementWithText(template, 'name', name);
mirrorXml.appendChild(nameXml);
const mirrorOfXml = createElementWithText(template, 'mirrorOf', mirrorOf);
mirrorXml.appendChild(mirrorOfXml);
const urlXml = createElementWithText(template, 'url', url);
mirrorXml.appendChild(urlXml);
const mirrorsXml = template.getElementsByTagName('mirrors')[0];
mirrorsXml.appendChild(mirrorXml);
}
function fillMirrors(template) {
const mirrors = core.getInput('mirrors');
if (!mirrors) {
return;
}
JSON.parse(mirrors).forEach((mirror) => fillMirror(template, mirror.id, mirror.name, mirror.mirrorOf, mirror.url));
}
function isInputTrue(inputName) {
const val = core.getInput(inputName);
return val && val.toLocaleLowerCase() == 'true';
@ -157,6 +193,7 @@ function generate() {
}
const templateXml = getSettingsTemplate();
fillMirrors(templateXml);
fillServers(templateXml);
fillServerForGithub(templateXml);
fillProperties(templateXml);
@ -184,6 +221,7 @@ function cleanup() {
module.exports = {
getSettingsTemplate,
writeSettings,
fillMirrors,
fillServers,
fillServerForGithub,
fillProperties,