<commit_before>var fs = require('fs');
var http = require('https');
var utils = require('../utils');
var rmdirSync = require('../utils/rmdir');
var CHECKED_DIR = require('../constants').CHECKED_DIR;
var multiloaderPromise = require('../utils/multiLoader');

var pull_request_handler = function (data) {
    var result = {};
    console.log('GitHub Action is: ', data.action);
    if (['synchronize', 'opened', 'reopened'].indexOf(data.action) >= -1) {
        result = {
            after_commit_hash: data.pull_request.head.sha,
            owner: data.repository.owner.login,
            repository: data.repository.name,
            author: data.pull_request.user.login,
            diff_url: data.pull_request.diff_url,
            results: {},
            extra_results: {},
            pr_number: data.number,
        }
        // Get differences
        utils.getGitHubFilePromise(`https://api.github.com/repos/${result.owner}/${result.repository}/pulls/${result.pr_number}`, 'application/vnd.github.v3.diff')
            .then(fileData => {
                // Check PEP8, ESLint
                const filesToCheck = utils.getFilesFromDiff(fileData).map(file => file.to);
                const onlyJsFileList = filesToCheck.filter(utils.regExpFilter(/.js/));
                console.log('Go to checked next files: ', onlyJsFileList);
                const onlyJsFiles = onlyJsFileList.map(file => Object({
                    owner: result.owner,
                    repository: result.repository,
                    sha: result.after_commit_hash,
                    filename: file,
                }));
                fs.mkdir(CHECKED_DIR, () => {
                    multiloaderPromise(onlyJsFiles)
                        .then(() => {
                            console.log('Processing ESLint report');
                            const report = utils.checkEslint([`${CHECKED_DIR}/`]);
                            console.log('Report successfuly created');
                            const comment = utils.prepareComment(report, result.author);
                            const commentText = comment.header + comment.body;
                            console.log('Comment is ready: ', comment);
                            // Send Message
                            // const commentRequestOptions = {
                            //     protocol: 'https:',
                            //     host: 'api.github.com',
                            //     method: 'POST',
                            //     path: `/repos/${result.owner}/${result.repository}/issues/${result.pr_number}/comments`,
                            //     headers: utils.getGitHubHeaders(),
                            // }
                            // var req = http.request(commentRequestOptions, res => {
                            //     res.on('end', rmdirSync(CHECKED_DIR));
                            // });
                            // req.write(JSON.stringify({ body: commentText }));
                            // req.end();
                        });
                });
            })
            .catch(e => console.error(`Error: ${e}`));
    }
    return result;
}

module.exports.pull_request_handler = pull_request_handler; <commit_msg>Fourth test run<commit_after>var fs = require('fs');
var http = require('https');
var utils = require('../utils');
var rmdirSync = require('../utils/rmdir');
var CHECKED_DIR = require('../constants').CHECKED_DIR;
var multiloaderPromise = require('../utils/multiLoader');

var pull_request_handler = function (data) {
    var result = {};
    console.log('GitHub Action is: ', data.action);
    if (['synchronize', 'opened', 'reopened'].indexOf(data.action) >= -1) {
        result = {
            after_commit_hash: data.pull_request.head.sha,
            owner: data.repository.owner.login,
            repository: data.repository.name,
            author: data.pull_request.user.login,
            diff_url: data.pull_request.diff_url,
            results: {},
            extra_results: {},
            pr_number: data.number,
        }
        // Get differences
        utils.getGitHubFilePromise(`https://api.github.com/repos/${result.owner}/${result.repository}/pulls/${result.pr_number}`, 'application/vnd.github.v3.diff')
            .then(fileData => {
                // Check PEP8, ESLint
                const filesToCheck = utils.getFilesFromDiff(fileData).map(file => file.to);
                const onlyJsFileList = filesToCheck.filter(utils.regExpFilter(/.js/));
                console.log('Go to checked next files: ', onlyJsFileList);
                const onlyJsFiles = onlyJsFileList.map(file => Object({
                    owner: result.owner,
                    repository: result.repository,
                    sha: result.after_commit_hash,
                    filename: file,
                }));
                fs.mkdir(CHECKED_DIR, () => {
                    multiloaderPromise(onlyJsFiles)
                        .then(() => {
                            console.log('Processing ESLint report');
                            const report = utils.checkEslint([`${CHECKED_DIR}/`]);
                            console.log('Report successfuly created');
                            const comment = utils.prepareComment(report, result.author);
                            const commentText = comment.header + comment.body;
                            // Send Message
                            const commentRequestOptions = {
                                protocol: 'https:',
                                host: 'api.github.com',
                                method: 'POST',
                                path: `/repos/${result.owner}/${result.repository}/issues/${result.pr_number}/comments`,
                                headers: utils.getGitHubHeaders(),
                            }
                            var req = http.request(commentRequestOptions, res => {
                                res.on('end', rmdirSync(CHECKED_DIR));
                            });
                            req.write(JSON.stringify({ body: commentText }));
                            req.end();
                        });
                });
            })
            .catch(e => console.error(`Error: ${e}`));
    }
    return result;
}

module.exports.pull_request_handler = pull_request_handler; 
{'fraction_non_alphanumeric': 0.12648716343143393, 'fraction_numerical': 0.000939261114589856, 'mean_word_length': 1.4302015975656144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004466', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1577, 'n_words': 270}