Format with prettier

This commit is contained in:
Simon Schneegans
2023-10-07 19:31:13 +02:00
parent d5f166a320
commit 5ab7837fab

100
index.js
View File

@@ -4,23 +4,23 @@
// Copyright: (c) 2020 Simon Schneegans // // Copyright: (c) 2020 Simon Schneegans //
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
import core from '@actions/core'; import core from "@actions/core";
import { makeBadge } from 'badge-maker'; import { makeBadge } from "badge-maker";
const gistUrl = new URL(core.getInput('gistID'), core.getInput('host')); const gistUrl = new URL(core.getInput("gistID"), core.getInput("host"));
// This uses the method above to update a gist with the given data. The user agent is // This uses the method above to update a gist with the given data. The user agent is
// required as defined in https://developer.github.com/v3/#user-agent-required // required as defined in https://developer.github.com/v3/#user-agent-required
async function updateGist(body) { async function updateGist(body) {
const headers = new Headers([ const headers = new Headers([
['Content-Type', 'application/json'], ["Content-Type", "application/json"],
['Content-Length', body.length], ["Content-Length", body.length],
['User-Agent', 'Schneegans'], ["User-Agent", "Schneegans"],
['Authorization', `token ${core.getInput('auth')}`], ["Authorization", `token ${core.getInput("auth")}`],
]); ]);
const response = await fetch(gistUrl, { const response = await fetch(gistUrl, {
method: 'POST', method: "POST",
headers, headers,
body, body,
}); });
@@ -34,7 +34,7 @@ async function updateGist(body) {
return; return;
} }
console.log('Success!'); console.log("Success!");
} }
// We wrap the entire action in a try / catch block so we can set it to "failed" if // We wrap the entire action in a try / catch block so we can set it to "failed" if
@@ -44,27 +44,27 @@ try {
// and message attributes are always required. All others are optional and added to the // and message attributes are always required. All others are optional and added to the
// content object only if they are given to the action. // content object only if they are given to the action.
let data = { let data = {
label: core.getInput('label'), label: core.getInput("label"),
message: core.getInput('message'), message: core.getInput("message"),
}; };
const filename = core.getInput('filename'); const filename = core.getInput("filename");
const isSvgFile = filename.endsWith('.svg'); const isSvgFile = filename.endsWith(".svg");
if (!isSvgFile) { if (!isSvgFile) {
data.schemaVersion = 1; data.schemaVersion = 1;
} }
// Compute the message color based on the given inputs. // Compute the message color based on the given inputs.
const color = core.getInput('color'); const color = core.getInput("color");
const valColorRange = core.getInput('valColorRange'); const valColorRange = core.getInput("valColorRange");
const minColorRange = core.getInput('minColorRange'); const minColorRange = core.getInput("minColorRange");
const maxColorRange = core.getInput('maxColorRange'); const maxColorRange = core.getInput("maxColorRange");
const invertColorRange = core.getInput('invertColorRange'); const invertColorRange = core.getInput("invertColorRange");
const colorRangeSaturation = core.getInput('colorRangeSaturation'); const colorRangeSaturation = core.getInput("colorRangeSaturation");
const colorRangeLightness = core.getInput('colorRangeLightness'); const colorRangeLightness = core.getInput("colorRangeLightness");
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') { if (minColorRange != "" && maxColorRange != "" && valColorRange != "") {
const max = parseFloat(maxColorRange); const max = parseFloat(maxColorRange);
const min = parseFloat(minColorRange); const min = parseFloat(minColorRange);
let val = parseFloat(valColorRange); let val = parseFloat(valColorRange);
@@ -73,75 +73,75 @@ try {
if (val > max) val = max; if (val > max) val = max;
let hue = 0; let hue = 0;
if (invertColorRange == '') { if (invertColorRange == "") {
hue = Math.floor(((val - min) / (max - min)) * 120); hue = Math.floor(((val - min) / (max - min)) * 120);
} else { } else {
hue = Math.floor(((max - val) / (max - min)) * 120); hue = Math.floor(((max - val) / (max - min)) * 120);
} }
let sat = 100; let sat = 100;
if (colorRangeSaturation != '') { if (colorRangeSaturation != "") {
sat = parseFloat(colorRangeSaturation); sat = parseFloat(colorRangeSaturation);
} }
let lig = 40; let lig = 40;
if (colorRangeLightness != '') { if (colorRangeLightness != "") {
lig = parseFloat(colorRangeLightness); lig = parseFloat(colorRangeLightness);
} }
data.color = 'hsl(' + hue + ', ' + sat + '%, ' + lig + '%)'; data.color = "hsl(" + hue + ", " + sat + "%, " + lig + "%)";
} else if (color != '') { } else if (color != "") {
data.color = color; data.color = color;
} }
// Get all optional attributes and add them to the content object if given. // Get all optional attributes and add them to the content object if given.
const labelColor = core.getInput('labelColor'); const labelColor = core.getInput("labelColor");
const isError = core.getInput('isError'); const isError = core.getInput("isError");
const namedLogo = core.getInput('namedLogo'); const namedLogo = core.getInput("namedLogo");
const logoSvg = core.getInput('logoSvg'); const logoSvg = core.getInput("logoSvg");
const logoColor = core.getInput('logoColor'); const logoColor = core.getInput("logoColor");
const logoWidth = core.getInput('logoWidth'); const logoWidth = core.getInput("logoWidth");
const logoPosition = core.getInput('logoPosition'); const logoPosition = core.getInput("logoPosition");
const style = core.getInput('style'); const style = core.getInput("style");
const cacheSeconds = core.getInput('cacheSeconds'); const cacheSeconds = core.getInput("cacheSeconds");
if (labelColor != '') { if (labelColor != "") {
data.labelColor = labelColor; data.labelColor = labelColor;
} }
if (!isSvgFile && isError != '') { if (!isSvgFile && isError != "") {
data.isError = isError; data.isError = isError;
} }
if (!isSvgFile && namedLogo != '') { if (!isSvgFile && namedLogo != "") {
data.namedLogo = namedLogo; data.namedLogo = namedLogo;
} }
if (!isSvgFile && logoSvg != '') { if (!isSvgFile && logoSvg != "") {
data.logoSvg = logoSvg; data.logoSvg = logoSvg;
} }
if (!isSvgFile && logoColor != '') { if (!isSvgFile && logoColor != "") {
data.logoColor = logoColor; data.logoColor = logoColor;
} }
if (!isSvgFile && logoWidth != '') { if (!isSvgFile && logoWidth != "") {
data.logoWidth = parseInt(logoWidth); data.logoWidth = parseInt(logoWidth);
} }
if (!isSvgFile && logoPosition != '') { if (!isSvgFile && logoPosition != "") {
data.logoPosition = logoPosition; data.logoPosition = logoPosition;
} }
if (style != '') { if (style != "") {
data.style = style; data.style = style;
} }
if (!isSvgFile && cacheSeconds != '') { if (!isSvgFile && cacheSeconds != "") {
data.cacheSeconds = parseInt(cacheSeconds); data.cacheSeconds = parseInt(cacheSeconds);
} }
let content = ''; let content = "";
if (isSvgFile) { if (isSvgFile) {
content = makeBadge(data); content = makeBadge(data);
@@ -155,16 +155,16 @@ try {
// If "forceUpdate" is set to true, we can simply update the gist. If not, we have to // If "forceUpdate" is set to true, we can simply update the gist. If not, we have to
// get the gist data and compare it to the new value before. // get the gist data and compare it to the new value before.
if (core.getBooleanInput('forceUpdate')) { if (core.getBooleanInput("forceUpdate")) {
updateGist(body); updateGist(body);
} else { } else {
// Get the old gist. // Get the old gist.
fetch(gistUrl, { fetch(gistUrl, {
method: 'GET', method: "GET",
headers: new Headers([ headers: new Headers([
['Content-Type', 'application/json'], ["Content-Type", "application/json"],
['User-Agent', 'Schneegans'], ["User-Agent", "Schneegans"],
['Authorization', `token ${core.getInput('auth')}`], ["Authorization", `token ${core.getInput("auth")}`],
]), ]),
}) })
.then((response) => { .then((response) => {