<commit_before>import chalk from 'chalk';
import * as dotenv from 'dotenv';
import * as os from 'os';
import { join } from 'path';
import * as request from 'request';

import { extractReleaseNotes } from './extract-release-notes';
import { CHANGELOG_FILE_NAME } from './stage-release';


const HTTP_CODE_OK = 200;

const platform = os.platform();

export function notify(tag, version) {
    if (!verifyNotificationPossibility()) {
        return;
    }

    const result = dotenv.config();

    const url = result.parsed.MATTERMOST_ENDPOINT_URL;
    const channel = result.parsed.MATTERMOST_CHANNEL;

    let headers = { 'Content-Type': 'application/x-www-form-urlencoded' };

    let body = `payload={
        "channel": "${channel}",
        "username": "Wall-e",
        "short": false,
        "text": " #### [![Mosaic Logo](https://i.ibb.co/fQNPgv6/logo-png-200.png =32x32)osaic](https://github.com/positive-js/mosaic/tree/${tag}) was published.
${prepareChangeLog(version)}"
}`;

    if (platform === 'win32') {
        headers = { 'Content-Type': 'application/json' };

        body = `{
            \"channel\": \"${channel}\",
            \"username\": \"Wall-e\",
            \"short\": false,
            \"text\": \" #### [![Mosaic Logo](https://i.ibb.co/fQNPgv6/logo-png-200.png =32x32)osaic](https://github.com/positive-js/mosaic/tree/${tag}) was published.
    ${prepareChangeLog(version)}\"
}`;
    }

    request.post({
        url,
        headers,
        body
    }, (error, response) => {
        if (error || response.statusCode !== HTTP_CODE_OK) {
            // tslint:disable-next-line:no-console
            console.error(chalk.red(`  ✘   Could not post notification in Mattermost.`));

            return;
        }

        console.info(chalk.green(`  ✓   Notification is posted in Mattermost.`));
    });
}

export function verifyNotificationPossibility() {
    const result = dotenv.config();

    return !result.error && result.parsed.MATTERMOST_ENDPOINT_URL && result.parsed.MATTERMOST_CHANNEL;
}

function prepareChangeLog(version) {
    const changelogPath = join(join(__dirname, '../../'), CHANGELOG_FILE_NAME);
    const extractedReleaseNotes = extractReleaseNotes(changelogPath, version);

    return extractedReleaseNotes.releaseNotes.replace(/"/g, '\\\"');
}<commit_msg>chore: updated notify script for win<commit_after>import chalk from 'chalk';
import * as dotenv from 'dotenv';
import { join } from 'path';
import * as request from 'request';

import { extractReleaseNotes } from './extract-release-notes';
import { CHANGELOG_FILE_NAME } from './stage-release';


const HTTP_CODE_OK = 200;

export function notify(tag, version) {
    if (!verifyNotificationPossibility()) {
        return;
    }

    const result = dotenv.config();

    const url = result.parsed.MATTERMOST_ENDPOINT_URL;
    const channel = result.parsed.MATTERMOST_CHANNEL;

    const headers = { 'Content-Type': 'application/json' };
    const body = {
        channel: `${channel}`,
        username: "Wall-e",
        short: false,
        text: "#### [![Mosaic Logo](https://i.ibb.co/fQNPgv6/logo-png-200.png =32x32)osaic](https://github.com/positive-js/mosaic/tree/${tag}) was published. \n " + prepareChangeLog(version)
    };

    request.post({
        url,
        headers,
        body: JSON.stringify(body)
    }, (error, response) => {
        if (error || response.statusCode !== HTTP_CODE_OK) {
            // tslint:disable-next-line:no-console
            console.error(chalk.red(`  ✘   Could not post notification in Mattermost.`));

            return;
        }

        console.info(chalk.green(`  ✓   Notification is posted in Mattermost.`));
    });
}

export function verifyNotificationPossibility() {
    const result = dotenv.config();

    return !result.error && result.parsed.MATTERMOST_ENDPOINT_URL && result.parsed.MATTERMOST_CHANNEL;
}

function prepareChangeLog(version) {
    const changelogPath = join(join(__dirname, '../../'), CHANGELOG_FILE_NAME);
    const extractedReleaseNotes = extractReleaseNotes(changelogPath, version);

    return extractedReleaseNotes.releaseNotes.replace(/"/g, '');
}
{'fraction_non_alphanumeric': 0.1540318686624819, 'fraction_numerical': 0.00772573635924674, 'mean_word_length': 3.0538160469667317, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '223111', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1272, 'n_words': 262}