You've already forked dynamic-badges-action
📝 Add some comments
This commit is contained in:
40
index.js
40
index.js
@@ -2,12 +2,18 @@ const core = require('@actions/core');
|
|||||||
const http = require('https');
|
const http = require('https');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let description = {
|
|
||||||
|
// This object will be stringified and uploaded to the gist. The
|
||||||
|
// schemaVersion, label and message attributes are always required. All others
|
||||||
|
// are optional and added to the content object only if they are given to the
|
||||||
|
// action.
|
||||||
|
let content = {
|
||||||
schemaVersion: 1,
|
schemaVersion: 1,
|
||||||
label: core.getInput('label'),
|
label: core.getInput('label'),
|
||||||
message: core.getInput('message')
|
message: core.getInput('message')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get all optional attributes and add them to the content object if given.
|
||||||
const labelColor = core.getInput('labelColor');
|
const labelColor = core.getInput('labelColor');
|
||||||
const color = core.getInput('color');
|
const color = core.getInput('color');
|
||||||
const isError = core.getInput('isError');
|
const isError = core.getInput('isError');
|
||||||
@@ -20,49 +26,53 @@ try {
|
|||||||
const cacheSeconds = core.getInput('cacheSeconds');
|
const cacheSeconds = core.getInput('cacheSeconds');
|
||||||
|
|
||||||
if (labelColor != '') {
|
if (labelColor != '') {
|
||||||
description.labelColor = labelColor;
|
content.labelColor = labelColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color != '') {
|
if (color != '') {
|
||||||
description.color = color;
|
content.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError != '') {
|
if (isError != '') {
|
||||||
description.isError = isError;
|
content.isError = isError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namedLogo != '') {
|
if (namedLogo != '') {
|
||||||
description.namedLogo = namedLogo;
|
content.namedLogo = namedLogo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoSvg != '') {
|
if (logoSvg != '') {
|
||||||
description.logoSvg = logoSvg;
|
content.logoSvg = logoSvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoColor != '') {
|
if (logoColor != '') {
|
||||||
description.logoColor = logoColor;
|
content.logoColor = logoColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoWidth != '') {
|
if (logoWidth != '') {
|
||||||
description.logoWidth = parseInt(logoWidth);
|
content.logoWidth = parseInt(logoWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoPosition != '') {
|
if (logoPosition != '') {
|
||||||
description.logoPosition = logoPosition;
|
content.logoPosition = logoPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style != '') {
|
if (style != '') {
|
||||||
description.style = style;
|
content.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheSeconds != '') {
|
if (cacheSeconds != '') {
|
||||||
description.cacheSeconds = parseInt(cacheSeconds);
|
content.cacheSeconds = parseInt(cacheSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = JSON.stringify({
|
// For the POST request, the above content is set as file contents for the
|
||||||
files: {[core.getInput('filename')]: {content: JSON.stringify(description)}}
|
// given filename.
|
||||||
|
const request = JSON.stringify({
|
||||||
|
files: {[core.getInput('filename')]: {content: JSON.stringify(content)}}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Perform the actual request. The user agent is required as defined in
|
||||||
|
// https://developer.github.com/v3/#user-agent-required
|
||||||
const req = http.request(
|
const req = http.request(
|
||||||
{
|
{
|
||||||
host: 'api.github.com',
|
host: 'api.github.com',
|
||||||
@@ -70,7 +80,7 @@ try {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Content-Length': data.length,
|
'Content-Length': request.length,
|
||||||
'User-Agent': 'Schneegans',
|
'User-Agent': 'Schneegans',
|
||||||
'Authorization': 'token ' + core.getInput('auth'),
|
'Authorization': 'token ' + core.getInput('auth'),
|
||||||
}
|
}
|
||||||
@@ -81,7 +91,7 @@ try {
|
|||||||
res.on('end', () => console.log('result:' + body));
|
res.on('end', () => console.log('result:' + body));
|
||||||
});
|
});
|
||||||
|
|
||||||
req.write(data);
|
req.write(request);
|
||||||
req.end();
|
req.end();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user