<commit_before>'use strict';

const {exec} = require('child_process');
const {promisify} = require('util');

const execon = require('execon');
const tryToCatch = require('try-to-catch');
const rendy = require('rendy');
const shortdate = require('shortdate');
const readPackage = require('read-pkg-up');
const gitTempl = 'git log {{ version }}..HEAD --pretty=format:"- %s" --grep {{ category }}\\(| sed "s/{{ category }}(/(/g"';

const changelog = promisify(_changelog);

module.exports = async (versionNew) => {
    const [error, {packageJson} = {}] = await tryToCatch(readPackage);
    
    if (error)
        throw `error reading package.json: ${error.message}`;
    
    return await changelog(versionNew, packageJson);
};

function _changelog(versionNew, packageJson, callback) {
    const isV = /^v/.test(versionNew);
    const version = `v${packageJson.version}`;
    
    const gitFix = rendy(gitTempl, {
        category: 'fix' ,
        version,
    });
    
    const gitFeature = rendy(gitTempl, {
        category: 'feature',
        version,
    });
    
    if (!isV && versionNew)
        versionNew = 'v' + versionNew;
    
    execon.parallel([
        execon.with(exec, gitFix),
        execon.with(exec, gitFeature),
    ], (error, fixData, featureData) => {
        if (error)
            return callback(error);
        
        const DATA = 0;
        const STD_ERR = 1;
        const stderr = fixData[STD_ERR] || featureData[STD_ERR];
        
        if (stderr)
            return callback(Error(stderr));
        
        let head = shortdate();
        let data = '';
        
        if (versionNew)
            head += ', ' + versionNew;
        
        head += '\n\n';
        
        const fix = fixData[DATA];
        const feature = featureData[DATA];
        
        if (fix || feature) {
            data = head;
            
            if (fix) {
                data += 'fix:' + '\n';
                data += fix + '\n\n';
            }
            
            if (feature) {
                data += 'feature:' + '\n';
                data += feature + '\n\n';
            }
        }
        
        if (!data)
            return callback(Error('No new feature and fix commits from ' + version));
        
        callback(null, data);
    });
}
<commit_msg>fix(changelog) \n\n -> \n<commit_after>'use strict';

const {exec} = require('child_process');
const {promisify} = require('util');

const execon = require('execon');
const tryToCatch = require('try-to-catch');
const rendy = require('rendy');
const shortdate = require('shortdate');
const readPackage = require('read-pkg-up');
const gitTempl = 'git log {{ version }}..HEAD --pretty=format:"- %s" --grep {{ category }}\\(| sed "s/{{ category }}(/(/g"';

const changelog = promisify(_changelog);

module.exports = async (versionNew) => {
    const [error, {packageJson} = {}] = await tryToCatch(readPackage);
    
    if (error)
        throw `error reading package.json: ${error.message}`;
    
    return await changelog(versionNew, packageJson);
};

function _changelog(versionNew, packageJson, callback) {
    const isV = /^v/.test(versionNew);
    const version = `v${packageJson.version}`;
    
    const gitFix = rendy(gitTempl, {
        category: 'fix' ,
        version,
    });
    
    const gitFeature = rendy(gitTempl, {
        category: 'feature',
        version,
    });
    
    if (!isV && versionNew)
        versionNew = 'v' + versionNew;
    
    execon.parallel([
        execon.with(exec, gitFix),
        execon.with(exec, gitFeature),
    ], (error, fixData, featureData) => {
        if (error)
            return callback(error);
        
        const DATA = 0;
        const STD_ERR = 1;
        const stderr = fixData[STD_ERR] || featureData[STD_ERR];
        
        if (stderr)
            return callback(Error(stderr));
        
        let head = shortdate();
        let data = '';
        
        if (versionNew)
            head += ', ' + versionNew;
        
        head += '\n';
        
        const fix = fixData[DATA];
        const feature = featureData[DATA];
        
        if (fix || feature) {
            data = head;
            
            if (fix) {
                data += 'fix:' + '\n';
                data += fix + '\n';
            }
            
            if (feature) {
                data += 'feature:' + '\n';
                data += feature + '\n';
            }
        }
        
        if (!data)
            return callback(Error('No new feature and fix commits from ' + version));
        
        callback(null, data);
    });
}

{'fraction_non_alphanumeric': 0.14793926247288502, 'fraction_numerical': 0.0008676789587852494, 'mean_word_length': 1.813300793166565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3575154', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1370, 'n_words': 330}