Browse Source

style: Fix lint errors

Changelog: None
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
change-dependabot-prefix
Ole Petter 3 years ago
parent
commit
e48602f1cd
No known key found for this signature in database GPG Key ID: 399DBE0F4D4B02EB
  1. 16
      scripts/linkbot/common.js
  2. 44
      scripts/linkbot/monitor-rpi.js

16
scripts/linkbot/common.js

@ -1,18 +1,18 @@
const fs = require('fs') const fs = require('fs');
const updateURLLink = (newLine, target) => { const updateURLLink = (newLine, target) => {
try { try {
const data = fs.readFileSync('../test/run-tests.sh', 'utf8') const data = fs.readFileSync('../test/run-tests.sh', 'utf8')
.replace(RegExp(`## Auto-update\n${target}=.*`), `## Auto-update\n${newLine}`) .replace(RegExp(`## Auto-update\n${target}=.*`), `## Auto-update\n${newLine}`);
fs.writeFile('../test/run-tests.sh', data, (err, data) => { fs.writeFile('../test/run-tests.sh', data, (err, data) => {
if (err) { if (err) {
console.error(err) console.error(err);
} }
}) });
} catch (err) { } catch (err) {
console.error(err) console.error(err);
process.exit(1) process.exit(1);
} }
} };
module.exports = { module.exports = {
updateURLLink updateURLLink
} };

44
scripts/linkbot/monitor-rpi.js

@ -1,40 +1,40 @@
const jsdom = require("jsdom"); const jsdom = require("jsdom");
const { JSDOM } = jsdom; const { JSDOM } = jsdom;
const fs = require('fs') const fs = require('fs');
const { updateURLLink } = require('./common'); const { updateURLLink } = require('./common');
const target = "RASPBIAN_IMAGE_URL" const target = "RASPBIAN_IMAGE_URL";
// Read the input file, and parse the variable input // Read the input file, and parse the variable input
try { try {
const data = fs.readFileSync('../test/run-tests.sh', 'utf8') const data = fs.readFileSync('../test/run-tests.sh', 'utf8')
.split('\n') .split('\n')
.filter(line => line.match(`${target}=.*`)) .filter(line => line.match(`${target}=.*`));
var line = data[0] var line = data[0];
console.log(line) console.log(line);
var reg = "raspbian_lite-(?<date>[0-9]{4}-[0-9]{2}-[0-9]{1,2})/(?<updated>[0-9]{4}-[0-9]{2}-[0-9]{1,2}).*$" var reg = "raspbian_lite-(?<date>[0-9]{4}-[0-9]{2}-[0-9]{1,2})/(?<updated>[0-9]{4}-[0-9]{2}-[0-9]{1,2}).*$";
var m = line.match(".*=\"(?<url>[a-zA-Z-://\._]*)(?<imageName>raspbian_lite-[0-9]{4}-[0-9]{2}-[0-9]{1,2})/(?<updated>[0-9]{4}-[0-9]{2}-[0-9]{1,2}).*$") var m = line.match(".*=\"(?<url>[a-zA-Z-://\._]*)(?<imageName>raspbian_lite-[0-9]{4}-[0-9]{2}-[0-9]{1,2})/(?<updated>[0-9]{4}-[0-9]{2}-[0-9]{1,2}).*$");
console.log(m) console.log(m);
var url = m.groups.url var url = m.groups.url;
var imageName = m.groups.imageName var imageName = m.groups.imageName;
var updated = m.groups.updated var updated = m.groups.updated;
} catch (err) { } catch (err) {
console.error(err) console.error(err);
process.exit(1) process.exit(1);
} }
function getNewRaspbian(url) { function getNewRaspbian(url) {
console.log("getNewRaspbian") console.log("getNewRaspbian");
console.log(`${url}`) console.log(`${url}`);
return JSDOM.fromURL(url, {}).then(dom => { return JSDOM.fromURL(url, {}).then(dom => {
var document = dom.window.document; var document = dom.window.document;
var refs = document.getElementsByTagName("a"); var refs = document.getElementsByTagName("a");
var test = Array.from(refs) var test = Array.from(refs)
.filter(ref => ref.textContent.match(("raspbian-.*-lite.*\.zip$"))) .filter(ref => ref.textContent.match(("raspbian-.*-lite.*\.zip$")))
.reduce((acc, element) => { .reduce((acc, element) => {
acc.push(element.textContent.match("raspbian-.*-lite.*\.zip$").input) acc.push(element.textContent.match("raspbian-.*-lite.*\.zip$").input);
return acc return acc;
}, [])[0] }, [])[0];
return `${target}=\"${url}/${test}\"`; return `${target}=\"${url}/${test}\"`;
}); });
} }
@ -63,15 +63,15 @@ JSDOM.fromURL(url, {}).then(dom => {
} }
return bl - al; return bl - al;
}); });
var matchOn = matches[0].input.split("/")[0] var matchOn = matches[0].input.split("/")[0];
if (matchOn !== imageName) { if (matchOn !== imageName) {
// We also need to extract the new image name from the index folder, as // We also need to extract the new image name from the index folder, as
// dated folders contain images with different dates in them o_O // dated folders contain images with different dates in them o_O
console.error("We've got a new release! \\o/"); console.error("We've got a new release! \\o/");
var newVar = getNewRaspbian(`${url}${matches[0].input.split(" ")[0].split("/").slice(0, -1)}`) var newVar = getNewRaspbian(`${url}${matches[0].input.split(" ")[0].split("/").slice(0, -1)}`)
.then(res => { .then(res => {
console.log(`New release: ${res}`) console.log(`New release: ${res}`);
updateURLLink(res, target) updateURLLink(res, target);
}) });
} }
}); });

Loading…
Cancel
Save