semantic-release-presets
Version:
Semantic release presets and plugins for various projects.
24 lines (20 loc) • 973 B
JavaScript
/* eslint-disable-next-line no-useless-escape */
const urlPattern = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)
let webhookUrl = '';
/**
* A method to verify that the user has given us a teams webhook url to post to
*/
export default async (pluginConfig, context) => {
const { env } = context;
const { webhookUrl: webhookUrlOption } = pluginConfig;
const { TEAMS_WEBHOOK_URL: webhookUrlVariable, TEAMS_WEBHOOK_DISABLED } = env;
const errors = [];
webhookUrl = webhookUrlOption || webhookUrlVariable;
if (!TEAMS_WEBHOOK_DISABLED && (!webhookUrl || webhookUrl.length === 0 || urlPattern.test(webhookUrl) === false)) {
errors.push('Invalid WebHook URL');
}
// Throw any errors we accumulated during the validation
if (errors.length > 0) {
throw new Error(errors.join('\n'));
}
};