Browse Source

Merge pull request #500 from oleorhagen/prettier

style(linkbot): Add a prettier config
4.0.x
oleorhagen 2 years ago
committed by GitHub
parent
commit
dc91bd4cb1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      scripts/linkbot/.prettierrc.json
  2. 8
      scripts/linkbot/common.js
  3. 2
      scripts/linkbot/monitor-bb-sd.js
  4. 4
      scripts/linkbot/monitor-bb.js
  5. 2
      scripts/linkbot/monitor-raspbian-os.js
  6. 4
      scripts/linkbot/monitor-rpi.js
  7. 2
      scripts/linkbot/monitor-ub-server.js

7
scripts/linkbot/.prettierrc.json

@ -0,0 +1,7 @@
{
"printWidth": 160,
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid",
"quoteProps": "preserve"
}

8
scripts/linkbot/common.js

@ -5,13 +5,13 @@ export const fileTypes = {
testRunner: {
key: 'testRunner',
path: '../test/run-tests.sh',
matcher: (target) => (line) => line.match(`${target}=.*`),
matcher: target => line => line.match(`${target}=.*`),
replacer: ({ newLine, target }) => [RegExp(`## Auto-update\n${target}=.*`), `## Auto-update\n${newLine}`]
},
ciFile: {
key: 'ciFile',
path: '../../.gitlab-ci.yml',
matcher: (target) => (line) => line.match(`${target}: .*`),
matcher: target => line => line.match(`${target}: .*`),
replacer: ({ targetName, targetUrl, newName, newUrl }) => [
RegExp(` *## Auto-update\n *${targetUrl}:.*\n *${targetName}: .*`),
` ## Auto-update\n ${targetUrl}: "${newUrl}"\n ${targetName}: ${newName}`
@ -22,7 +22,7 @@ export const fileTypes = {
export const updateURLLink = (updatedValues, fileType = fileTypes.testRunner.key) => {
try {
const data = fs.readFileSync(fileTypes[fileType].path, 'utf8').replace(...fileTypes[fileType].replacer(updatedValues));
fs.writeFile(fileTypes[fileType].path, data, (err) => {
fs.writeFile(fileTypes[fileType].path, data, err => {
if (err) {
console.error(err);
}
@ -46,7 +46,7 @@ export const getCurrentTestData = (target, matcher, fileType = fileTypes.testRun
};
export const getLinksByMatch = (url, matcher) =>
JSDOM.fromURL(url, {}).then((dom) => {
JSDOM.fromURL(url, {}).then(dom => {
const refs = dom.window.document.getElementsByTagName('a');
return Array.from(refs).reduce((accu, element) => {
const match = element.textContent.match(matcher);

2
scripts/linkbot/monitor-bb-sd.js

@ -4,7 +4,7 @@ const reg = 'bone-debian-(?<version>[0-9]+.[0-9]+)-iot-armhf-(?<date>[0-9]{4}-[0
export const target = 'BBB_DEBIAN_SDCARD_IMAGE_URL';
export const checkForUpdates = ({ url, imageName }) =>
getLinksByMatch(url, reg).then(async (links) => {
getLinksByMatch(url, reg).then(async links => {
// The bone-debian setup has two parts which needs comparing:
// * The release-version: i.e., 10.3
// * The date: i.e., 2020-04-06

4
scripts/linkbot/monitor-bb.js

@ -4,14 +4,14 @@ const reg = '[0-9]{4}-[0-9]{2}-[0-9]{1,2}/';
export const target = 'BBB_DEBIAN_EMMC_IMAGE_URL';
export const checkForUpdates = ({ url, latestDate }) =>
getLinksByMatch(url, reg).then(async (links) => {
getLinksByMatch(url, reg).then(async links => {
const matches = links.sort((a, b) => Date.parse(b.element.textContent) - Date.parse(a.element.textContent));
const date = matches[0].element.textContent;
if (date === latestDate) {
return;
}
const consoleLinks = await getLinksByMatch(matches[0].link, 'bullseye-minimal-arm64');
const result = await getLinksByMatch(consoleLinks[0].link, 'bbai64-debian.*.img.xz$').then((links) => `${target}=\"${links[0].link}\"`);
const result = await getLinksByMatch(consoleLinks[0].link, 'bbai64-debian.*.img.xz$').then(links => `${target}=\"${links[0].link}\"`);
return { newLine: result };
});

2
scripts/linkbot/monitor-raspbian-os.js

@ -4,7 +4,7 @@ const reg = 'raspios_lite_armhf-(?<date>[0-9]{4}-[0-9]{2}-[0-9]{1,2})/.*';
export const target = 'RASPBIAN_URL';
export const checkForUpdates = ({ url, imageName: currentImageName }) =>
getLinksByMatch(url, reg).then(async (links) => {
getLinksByMatch(url, reg).then(async links => {
const { link, match } = links.sort((a, b) => Date.parse(b.match.groups.date) - Date.parse(a.match.groups.date))[0];
const matchOn = match.input.split('/')[0];
if (matchOn === currentImageName) {

4
scripts/linkbot/monitor-rpi.js

@ -4,7 +4,7 @@ const reg = 'raspbian_lite-(?<date>[0-9]{4}-[0-9]{2}-[0-9]{1,2})/';
export const target = 'RASPBIAN_IMAGE_URL';
export const checkForUpdates = ({ url, imageName }) =>
getLinksByMatch(url, reg).then(async (links) => {
getLinksByMatch(url, reg).then(async links => {
const matches = links.sort((a, b) => Date.parse(b.match.groups.date) - Date.parse(a.match.groups.date));
const { link, match } = matches[0];
const matchOn = match.input.split('/')[0];
@ -14,7 +14,7 @@ export const checkForUpdates = ({ url, imageName }) =>
// 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
console.error("We've got a new release! \\o/");
const newLink = await getLinksByMatch(link, 'raspbian-.*-lite.*.zip$').then((links) => `${target}=\"${links[0].link}\"`);
const newLink = await getLinksByMatch(link, 'raspbian-.*-lite.*.zip$').then(links => `${target}=\"${links[0].link}\"`);
console.log(`New release: ${newLink}`);
return { newLine: newLink };
});

2
scripts/linkbot/monitor-ub-server.js

@ -7,7 +7,7 @@ const getReleaseName = (release, minor) => `${release}.04${minor ? `.${minor}` :
// Get the release image url from the releases (sub)-page
export const checkForUpdates = async ({ url, release }) => {
const releasedVersion = await getLinksByMatch(url, reg).then((links) => {
const releasedVersion = await getLinksByMatch(url, reg).then(links => {
const matches = links.sort((a, b) => {
if (b.match.groups.release === a.match.groups.release) {
return parseInt(b.match.groups.minor) - parseInt(a.match.groups.minor);

Loading…
Cancel
Save