<commit_before>#!/usr/bin/env node
/* eslint no-console: 0 */
/* eslint max-len: 0 */
import path from 'path';
import _ from 'lodash';
import GitHub from 'github';
import program from 'commander';
import pkg from './package.json';

program
    .version(pkg.version)
    .option('-T, --token <token>', 'OAuth2 token')
    .option('-o, --owner <owner>', 'owner')
    .option('-r, --repo <repo>', 'repo')
    .option('-t, --tag <tag>', 'tag')
    .option('-n, --name <name>', 'name')
    .option('-b, --body <body>', 'body', false)
    .parse(process.argv);

const github = new GitHub({
    version: '3.0.0',
    timeout: 5000,
    headers: {
        'user-agent': 'GitHub-Release-App'
    }
});
const files = program.args;

github.authenticate({
    type: 'oauth',
    token: program.token || process.env.GITHUB_TOKEN
});

const listReleases = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.listReleases(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const createRelease = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.createRelease(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const editRelease = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.editRelease(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const listAssets = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.listAssets(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const deleteAsset = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.deleteAsset(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const uploadAsset = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.uploadAsset(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const main = async () => {
    const { owner, repo, tag, name, body } = program;

    try {
        console.log('> releases#listReleases');
        let releases = await listReleases({
            owner: owner,
            repo: repo
        });
        console.log('releases=%d', releases.length);

        let release = _.find(releases, { tag_name: tag });
        if (!release) {
            console.log('> releases#createRelease');
            release = await createRelease({
                owner: owner,
                repo: repo,
                tag_name: tag,
                name: name || tag,
                body: body || ''
            });
            console.log('ok', release);
        } else if (release.body !== body) {
            console.log('> releases#editRelease');
            let releaseOptions = {
                owner: owner,
                repo: repo,
                id: release.id,
                tag_name: tag,
                name: name || tag
            };
            if (body) {
                releaseOptions.body = body || '';
            }
            release = await editRelease(releaseOptions);
            console.log('ok', release);
        }

        console.log('> releases#listAssets');
        let assets = await listAssets({
            owner: owner,
            repo: repo,
            id: release.id
        });
        console.log('assets=%d', assets.length);

        assets = _.filter(assets, (asset) => {
            // Example:
            // 'cnc-1.1.0-latest-08c256a-linux-x64.tar.gz'
            // ["cnc-1.1.0-latest-08c256a-linux-x64.tar.gz", "cnc", "1.1.0-latest-08c256a", "linux", "x64", "tar.gz"]
            const pattern = new RegExp(/([a-zA-Z0-9][a-zA-Z0-9\-]*)\-(\d+\.\d+\.\d+(?:\-[a-zA-Z0-9][a-zA-Z0-9\-]*)?)(?:\-(linux|osx|win32))(?:\-([a-zA-Z0-9_\-]+)\.(.*))/);<commit_msg>Rename win32 to win<commit_after>#!/usr/bin/env node
/* eslint no-console: 0 */
/* eslint max-len: 0 */
import path from 'path';
import _ from 'lodash';
import GitHub from 'github';
import program from 'commander';
import pkg from './package.json';

program
    .version(pkg.version)
    .option('-T, --token <token>', 'OAuth2 token')
    .option('-o, --owner <owner>', 'owner')
    .option('-r, --repo <repo>', 'repo')
    .option('-t, --tag <tag>', 'tag')
    .option('-n, --name <name>', 'name')
    .option('-b, --body <body>', 'body', false)
    .parse(process.argv);

const github = new GitHub({
    version: '3.0.0',
    timeout: 5000,
    headers: {
        'user-agent': 'GitHub-Release-App'
    }
});
const files = program.args;

github.authenticate({
    type: 'oauth',
    token: program.token || process.env.GITHUB_TOKEN
});

const listReleases = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.listReleases(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const createRelease = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.createRelease(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const editRelease = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.editRelease(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const listAssets = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.listAssets(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const deleteAsset = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.deleteAsset(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const uploadAsset = (options) => {
    return new Promise((resolve, reject) => {
        github.releases.uploadAsset(options, (err, res) => {
            err ? reject(err) : resolve(res);
        });
    });
};

const main = async () => {
    const { owner, repo, tag, name, body } = program;

    try {
        console.log('> releases#listReleases');
        let releases = await listReleases({
            owner: owner,
            repo: repo
        });
        console.log('releases=%d', releases.length);

        let release = _.find(releases, { tag_name: tag });
        if (!release) {
            console.log('> releases#createRelease');
            release = await createRelease({
                owner: owner,
                repo: repo,
                tag_name: tag,
                name: name || tag,
                body: body || ''
            });
            console.log('ok', release);
        } else if (release.body !== body) {
            console.log('> releases#editRelease');
            let releaseOptions = {
                owner: owner,
                repo: repo,
                id: release.id,
                tag_name: tag,
                name: name || tag
            };
            if (body) {
                releaseOptions.body = body || '';
            }
            release = await editRelease(releaseOptions);
            console.log('ok', release);
        }

        console.log('> releases#listAssets');
        let assets = await listAssets({
            owner: owner,
            repo: repo,
            id: release.id
        });
        console.log('assets=%d', assets.length);

        assets = _.filter(assets, (asset) => {
            // Example:
            // 'cnc-1.1.0-latest-08c256a-linux-x64.tar.gz'
            // ["cnc-1.1.0-latest-08c256a-linux-x64.tar.gz", "cnc", "1.1.0-latest-08c256a", "linux", "x64", "tar.gz"]
            const pattern = new RegExp(/([a-zA-Z0-9][a-zA-Z0-9\-]*)\-(\d+\.\d+\.\d+(?:\-[a-zA-Z0-9][a-zA-Z0-9\-]*)?)(?:\-(linux|osx|win))(?:\-([a-zA-Z0-9_\-]+)\.(.*))/);
{'fraction_non_alphanumeric': 0.18437737763124523, 'fraction_numerical': 0.013187927973624143, 'mean_word_length': 1.9081858407079646, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3779721', 'n_tokens_mistral': 2571, 'n_tokens_neox': 2448, 'n_words': 520}