Files
dynamic-badges-action/index.js

96 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 12:40:48 +02:00
const http = require('http');
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
const labelColor = core.getInput('label-color');
const color = core.getInput('color');
2020-08-15 13:25:03 +02:00
const isError = core.getInput('is-error');
const namedLogo = core.getInput('named-logo');
const logoSvg = core.getInput('logo-svg');
const logoColor = core.getInput('logo-color');
const logoWidth = core.getInput('logo-width');
const logoPosition = core.getInput('logo-position');
const style = core.getInput('style');
const cacheSeconds = core.getInput('cache-seconds');
2020-08-15 12:33:06 +02:00
if (labelColor != undefined) {
description.labelColor = labelColor;
}
if (color != undefined) {
description.labelColor = color;
}
2020-08-15 13:25:03 +02:00
if (isError != undefined) {
description.isError = isError;
}
if (namedLogo != undefined) {
description.namedLogo = namedLogo;
}
if (logoSvg != undefined) {
description.logoSvg = logoSvg;
}
if (logoColor != undefined) {
description.logoColor = logoColor;
}
if (logoWidth != undefined) {
description.logoWidth = logoWidth;
}
if (logoPosition != undefined) {
description.logoPosition = logoPosition;
}
if (style != undefined) {
description.style = style;
}
if (cacheSeconds != undefined) {
description.cacheSeconds = cacheSeconds;
}
2020-08-15 12:33:06 +02:00
let data = {files: {}};
2020-08-15 13:25:03 +02:00
data.files[core.getInput('badge-name')] = {
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',
path: '/gists/' + core.getInput('gist-id'),
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + core.getInput('auth'),
}
},
res => {
console.log('foooo!');
let body = '';
2020-08-15 12:48:07 +02:00
2020-08-15 13:25:03 +02:00
res.on('data', data => {
body += data;
});
2020-08-15 12:48:07 +02:00
2020-08-15 13:25:03 +02:00
res.on('end', () => {
console.log(body);
});
});
2020-08-15 12:48:07 +02:00
req.write(JSON.stringify(data));
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
}