Files
dynamic-badges-action/index.js

58 lines
1.3 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 12:33:06 +02:00
const auth = core.getInput('auth');
const gistId = core.getInput('gist-id');
const badgeName = core.getInput('badge-name');
const label = core.getInput('label');
const message = core.getInput('message');
const labelColor = core.getInput('label-color');
const color = core.getInput('color');
let description = {schemaVersion: 1, label: label, message: message};
if (labelColor != undefined) {
description.labelColor = labelColor;
}
if (color != undefined) {
description.labelColor = color;
}
let data = {files: {}};
2020-08-15 12:37:02 +02:00
data.files[badgeName] = {content: JSON.stringify(description)};
2020-08-15 12:33:06 +02:00
2020-08-15 12:54:49 +02:00
console.log(JSON.stringify(data));
console.log(gistId);
2020-08-15 12:48:07 +02:00
const options = {
host: 'api.github.com',
path: '/gists/' + gistId,
2020-08-15 12:54:49 +02:00
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + auth,
}
2020-08-15 12:48:07 +02:00
};
const callback = (response) => {
let str = '';
response.on('data', (chunk) => {
str += chunk;
});
response.on('end', () => {
console.log(str);
});
};
const req = http.request(options, callback);
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) {
core.setFailed(error.message);
}