Skip to content

Commit

Permalink
1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Apr 17, 2022
1 parent b81fcab commit 6874d09
Show file tree
Hide file tree
Showing 300 changed files with 76,067 additions and 43,436 deletions.
4 changes: 2 additions & 2 deletions lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const formatters = {
release: releaseFormatter,
};
function formatEvent(event, payload) {
utils_1.logDebug(JSON.stringify(payload, null, 2));
(0, utils_1.logDebug)(JSON.stringify(payload, null, 2));
let msg = "No further information";
if (event in formatters) {
try {
return formatters[event](payload) || msg;
}
catch (e) {
utils_1.logDebug(`Failed to generate eventDetail for ${event}: ${e}\n${e.stack}`);
(0, utils_1.logDebug)(`Failed to generate eventDetail for ${event}: ${e}\n${e.stack}`);
}
}
return msg;
Expand Down
18 changes: 12 additions & 6 deletions lib/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -42,23 +46,25 @@ function getInputs() {
webhooks.forEach((w, i) => {
core.setSecret(w);
if (w.endsWith('/github')) {
utils_1.logWarning(`webhook ${i + 1}/${webhooks.length} has \`/github\` suffix! This may cause errors.`);
(0, utils_1.logWarning)(`webhook ${i + 1}/${webhooks.length} has \`/github\` suffix! This may cause errors.`);
}
});
const nodetail = utils_1.stob(core.getInput('nodetail'));
const nocontext = nodetail || utils_1.stob(core.getInput('nocontext'));
const noprefix = nodetail || utils_1.stob(core.getInput('noprefix'));
const nodetail = (0, utils_1.stob)(core.getInput('nodetail'));
const nocontext = nodetail || (0, utils_1.stob)(core.getInput('nocontext'));
const noprefix = nodetail || (0, utils_1.stob)(core.getInput('noprefix'));
const inputs = {
webhooks: webhooks,
status: core.getInput('status').trim().toLowerCase(),
description: core.getInput('description').trim(),
title: (core.getInput('title') || core.getInput('job')).trim(),
image: core.getInput('image').trim(),
color: parseInt(core.getInput('color')),
url: core.getInput('url').trim(),
username: core.getInput('username').trim(),
avatar_url: core.getInput('avatar_url').trim(),
nocontext: nocontext,
noprefix: noprefix
noprefix: noprefix,
notimestamp: (0, utils_1.stob)(core.getInput('notimestamp'))
};
if (!inputs.webhooks.length) {
throw new Error("no webhook is given");
Expand Down
43 changes: 26 additions & 17 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -42,18 +46,18 @@ const validate_1 = require("./validate");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
utils_1.logInfo('Getting inputs...');
const inputs = input_1.getInputs();
utils_1.logInfo('Generating payload...');
(0, utils_1.logInfo)('Getting inputs...');
const inputs = (0, input_1.getInputs)();
(0, utils_1.logInfo)('Generating payload...');
const payload = getPayload(inputs);
core_1.startGroup('Dump payload');
utils_1.logInfo(JSON.stringify(payload, null, 2));
core_1.endGroup();
utils_1.logInfo(`Triggering ${inputs.webhooks.length} webhook${inputs.webhooks.length > 1 ? 's' : ''}...`);
(0, core_1.startGroup)('Dump payload');
(0, utils_1.logInfo)(JSON.stringify(payload, null, 2));
(0, core_1.endGroup)();
(0, utils_1.logInfo)(`Triggering ${inputs.webhooks.length} webhook${inputs.webhooks.length > 1 ? 's' : ''}...`);
yield Promise.all(inputs.webhooks.map(w => wrapWebhook(w.trim(), payload)));
}
catch (e) {
utils_1.logError(`Unexpected failure: ${e} (${e.message})`);
(0, utils_1.logError)(`Unexpected failure: ${e} (${e.message})`);
}
});
}
Expand All @@ -65,10 +69,10 @@ function wrapWebhook(webhook, payload) {
}
catch (e) {
if (e.response) {
utils_1.logError(`Webhook response: ${e.response.status}: ${JSON.stringify(e.response.data)}`);
(0, utils_1.logError)(`Webhook response: ${e.response.status}: ${JSON.stringify(e.response.data)}`);
}
else {
utils_1.logError(e);
(0, utils_1.logError)(e);
}
}
});
Expand All @@ -82,16 +86,21 @@ function getPayload(inputs) {
const repoURL = `https://github.com/${owner}/${repo}`;
const validSHA = ((_b = (_a = ctx.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head) === null || _b === void 0 ? void 0 : _b.sha) || sha;
const workflowURL = `${repoURL}/commit/${validSHA}/checks`;
utils_1.logDebug(JSON.stringify(payload));
(0, utils_1.logDebug)(JSON.stringify(payload));
const eventFieldTitle = `Event - ${eventName}`;
const eventDetail = format_1.formatEvent(eventName, payload);
const eventDetail = (0, format_1.formatEvent)(eventName, payload);
let embed = {
color: inputs.color || input_1.statusOpts[inputs.status].color,
timestamp: (new Date()).toISOString()
color: inputs.color || input_1.statusOpts[inputs.status].color
};
if (!inputs.notimestamp) {
embed.timestamp = (new Date()).toISOString();
}
if (inputs.title) {
embed.title = inputs.title;
}
if (inputs.url) {
embed.url = inputs.url;
}
if (inputs.image) {
embed.image = {
url: inputs.image
Expand Down Expand Up @@ -133,9 +142,9 @@ function getPayload(inputs) {
];
}
let discord_payload = {
embeds: [validate_1.fitEmbed(embed)]
embeds: [(0, validate_1.fitEmbed)(embed)]
};
utils_1.logDebug(`embed: ${JSON.stringify(embed)}`);
(0, utils_1.logDebug)(`embed: ${JSON.stringify(embed)}`);
if (inputs.username) {
discord_payload.username = inputs.username;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down
14 changes: 9 additions & 5 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -30,14 +34,14 @@ function fitEmbed(embed) {
if (embed.title) {
const titleLen = embed.title.length;
if (titleLen > constants.MAX_EMBED_TITLE_LENGTH) {
utils_1.logWarning(`embed title must be shorter than ${constants.MAX_EMBED_TITLE_LENGTH}, got ${titleLen}\n ${embed.title}`);
(0, utils_1.logWarning)(`embed title must be shorter than ${constants.MAX_EMBED_TITLE_LENGTH}, got ${titleLen}\n ${embed.title}`);
embed.title = truncStr(embed.title, constants.MAX_EMBED_TITLE_LENGTH);
}
}
if (embed.description) {
const descLen = embed.description.length;
if (descLen > constants.MAX_EMBED_DESCRIPTION_LENGTH) {
utils_1.logWarning(`embed description must be shorter than ${constants.MAX_EMBED_DESCRIPTION_LENGTH}, got ${descLen}\n ${embed.description}`);
(0, utils_1.logWarning)(`embed description must be shorter than ${constants.MAX_EMBED_DESCRIPTION_LENGTH}, got ${descLen}\n ${embed.description}`);
embed.description = truncStr(embed.description, constants.MAX_EMBED_DESCRIPTION_LENGTH);
}
}
Expand All @@ -46,11 +50,11 @@ function fitEmbed(embed) {
const nameLen = field.name.length;
const valueLen = field.value.length;
if (nameLen > constants.MAX_EMBED_FIELD_NAME_LENGTH) {
utils_1.logWarning(`embed field name must be shorter than ${constants.MAX_EMBED_FIELD_NAME_LENGTH}, got ${nameLen}\n ${field.name}`);
(0, utils_1.logWarning)(`embed field name must be shorter than ${constants.MAX_EMBED_FIELD_NAME_LENGTH}, got ${nameLen}\n ${field.name}`);
field.name = truncStr(field.name, constants.MAX_EMBED_FIELD_NAME_LENGTH);
}
if (valueLen > constants.MAX_EMBED_FIELD_VALUE_LENGTH) {
utils_1.logWarning(`embed field value must be shorter than ${constants.MAX_EMBED_FIELD_VALUE_LENGTH}, got ${valueLen}\n ${field.value}`);
(0, utils_1.logWarning)(`embed field value must be shorter than ${constants.MAX_EMBED_FIELD_VALUE_LENGTH}, got ${valueLen}\n ${field.value}`);
field.value = truncStr(field.value, constants.MAX_EMBED_FIELD_VALUE_LENGTH);
}
}
Expand Down
Loading

0 comments on commit 6874d09

Please sign in to comment.