Files
dynamic-badges-action/index.js

89 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-08-15 12:02:21 +02:00
const core = require('@actions/core');
2020-08-15 13:30:05 +02:00
const http = require('https');
2020-08-15 12:02:21 +02:00
try {
2020-08-15 13:25:03 +02:00
let description = {
schemaVersion: 1,
label: core.getInput('label'),
message: core.getInput('message')
};
2020-08-15 12:33:06 +02:00
2020-08-15 20:51:58 +02:00
const labelColor = core.getInput('labelColor');
const color = core.getInput('color');
const isError = core.getInput('isError');
const namedLogo = core.getInput('namedLogo');
const logoSvg = core.getInput('logoSvg');
const logoColor = core.getInput('logoColor');
const logoWidth = core.getInput('logoWidth');
2020-08-15 20:46:27 +02:00
const logoPosition = core.getInput('logoPosition');
2020-08-15 20:51:58 +02:00
const style = core.getInput('style');
2020-08-15 20:46:27 +02:00
const cacheSeconds = core.getInput('cacheSeconds');
2020-08-15 12:33:06 +02:00
2020-08-15 13:40:04 +02:00
if (labelColor != '') {
2020-08-15 12:33:06 +02:00
description.labelColor = labelColor;
}
2020-08-15 13:40:04 +02:00
if (color != '') {
2020-08-15 13:59:15 +02:00
description.color = color;
2020-08-15 12:33:06 +02:00
}
2020-08-15 13:40:04 +02:00
if (isError != '') {
2020-08-15 13:25:03 +02:00
description.isError = isError;
}
2020-08-15 13:40:04 +02:00
if (namedLogo != '') {
2020-08-15 13:25:03 +02:00
description.namedLogo = namedLogo;
}
2020-08-15 13:40:04 +02:00
if (logoSvg != '') {
2020-08-15 13:25:03 +02:00
description.logoSvg = logoSvg;
}
2020-08-15 13:40:04 +02:00
if (logoColor != '') {
2020-08-15 13:25:03 +02:00
description.logoColor = logoColor;
}
2020-08-15 13:40:04 +02:00
if (logoWidth != '') {
description.logoWidth = parseInt(logoWidth);
2020-08-15 13:25:03 +02:00
}
2020-08-15 13:40:04 +02:00
if (logoPosition != '') {
2020-08-15 13:25:03 +02:00
description.logoPosition = logoPosition;
}
2020-08-15 13:40:04 +02:00
if (style != '') {
2020-08-15 13:25:03 +02:00
description.style = style;
}
2020-08-15 13:40:04 +02:00
if (cacheSeconds != '') {
description.cacheSeconds = parseInt(cacheSeconds);
2020-08-15 13:25:03 +02:00
}
2020-08-15 20:53:49 +02:00
let data = JSON.stringify({
files: {[core.getInput('filename')]: {content: JSON.stringify(description)}}
});
2020-08-15 12:48:07 +02:00
2020-08-15 13:25:03 +02:00
const req = http.request(
{
host: 'api.github.com',
2020-08-15 20:46:27 +02:00
path: '/gists/' + core.getInput('gistID'),
2020-08-15 13:30:05 +02:00
method: 'POST',
2020-08-15 13:25:03 +02:00
headers: {
'Content-Type': 'application/json',
2020-08-15 13:30:05 +02:00
'Content-Length': data.length,
2020-08-15 13:35:31 +02:00
'User-Agent': 'Schneegans',
2020-08-15 13:25:03 +02:00
'Authorization': 'token ' + core.getInput('auth'),
}
},
res => {
let body = '';
2020-08-15 20:51:58 +02:00
res.on('data', data => body += data);
res.on('end', () => console.log('result:' + body));
2020-08-15 13:25:03 +02:00
});
2020-08-15 12:48:07 +02:00
2020-08-15 13:30:05 +02:00
req.write(data);
2020-08-15 12:48:07 +02:00
req.end();
2020-08-15 12:33:06 +02:00
2020-08-15 12:02:21 +02:00
} catch (error) {
2020-08-15 13:25:03 +02:00
core.setFailed(error);
2020-08-15 12:02:21 +02:00
}