<commit_before>import _ from 'lodash';
import GG from '@solomid/node-gg';
import semverSort from 'semver-compare';
import { outputLog } from '../log';
import config from '../config';

if (!process.env.KEY_CHAMPIONGG) {
  console.log('No championgg key defined.');
  throw new Error('No championgg key defined.');
}

function getPatch(apiKey) {
  const gg = GG.init(apiKey);

  return new Promise((resolve, reject) => {
    gg.statistics.general({
      // elo: 'PLATINUM,DIAMOND,MASTER,CHALLENGER'
    }, (err, data) => {
      if (err) {
        reject(err);
      } else {
        const patchList = _.map(data, 'patch').sort(semverSort).reverse();
        resolve(patchList[0]);
      }
    });
  });
}

function getChampionsRolesList(apiKey) {
  const gg = GG.init(apiKey);

  return new Promise((resolve, reject) => {
    gg.champions.all({
      // elo: 'PLATINUM,DIAMOND,MASTER,CHALLENGER'
      champData: 'hashes',
    }, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
}

const getDatas = () => new Promise(async (resolve, reject) => {
  // Get the patch version
  outputLog('[ChampionGG] Retrieving the patch version ...');
  const patchVersion = await getPatch(config.key.championgg);
  outputLog(`[ChampionGG] Retrieving the patch version : done ! (${patchVersion})`);

  // Get the champions
  outputLog('[ChampionGG] Retrieving the champions roles and item sets ...');
  let champRoles = await getChampionsRolesList(config.key.championgg);
  outputLog('[ChampionGG] Retrieving the champions roles and item sets : done !');

  if (config.env === 'test') {<commit_msg>fix(#17): missing item sets<commit_after>import _ from 'lodash';
import GG from '@solomid/node-gg';
import semverSort from 'semver-compare';
import { outputLog } from '../log';
import config from '../config';

if (!process.env.KEY_CHAMPIONGG) {
  console.log('No championgg key defined.');
  throw new Error('No championgg key defined.');
}

function getPatch(apiKey) {
  const gg = GG.init(apiKey);

  return new Promise((resolve, reject) => {
    gg.statistics.general({
      // elo: 'PLATINUM,DIAMOND,MASTER,CHALLENGER'
    }, (err, data) => {
      if (err) {
        reject(err);
      } else {
        const patchList = _.map(data, 'patch').sort(semverSort).reverse();
        resolve(patchList[0]);
      }
    });
  });
}

function getChampionsRolesList(apiKey) {
  const gg = GG.init(apiKey);

  return new Promise((resolve, reject) => {
    gg.champions.all({
      // elo: 'PLATINUM,DIAMOND,MASTER,CHALLENGER'
      champData: 'hashes',
      // Limiting to 1000 because the default value is 100
      limit: 1000,
    }, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
}

const getDatas = () => new Promise(async (resolve, reject) => {
  // Get the patch version
  outputLog('[ChampionGG] Retrieving the patch version ...');
  const patchVersion = await getPatch(config.key.championgg);
  outputLog(`[ChampionGG] Retrieving the patch version : done ! (${patchVersion})`);

  // Get the champions
  outputLog('[ChampionGG] Retrieving the champions roles and item sets ...');
  let champRoles = await getChampionsRolesList(config.key.championgg);
  outputLog('[ChampionGG] Retrieving the champions roles and item sets : done !');

  if (config.env === 'test') {
{'fraction_non_alphanumeric': 0.15475487300649735, 'fraction_numerical': 0.004430005906674543, 'mean_word_length': 3.265743073047859, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '782708', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1117, 'n_words': 270}