<commit_before>/* eslint-disable max-len */
import GitHubApi from 'github';
import dataStorage from '../storage/dataStorage';
import notifications from '../services/notifications';

const github = GitHubApi();
github.authenticate({
  type: 'oauth',
  key: process.env.CLIENT_ID,
  secret: process.env.CLIENT_SECRET
});

function getContributors(repositories) {
  const promises = [];
  repositories.forEach((repo) => {
    promises.push(new Promise((resolve, reject) => {
      github.repos.getContributors({ owner: repo.owner.login, repo: repo.name, page: 1, per_page: 5 }, (err, res) => {
        if (err) {
          reject();
        } else {
          resolve({ contributors: res.data });
        }
      });
    }));
  });

  return promises;
}

function computeRecommendedPeople(id) {
  const repositories = dataStorage.getGithubUserInterestingRepositories(id);
  const contributors = [];
  Promise.all(getContributors(repositories)).then((values) => {
    values.forEach((value) => {
      value.contributors.forEach((contributor) => {
        contributors.push(contributor);
      });
    });

    const responseContributors = [];
    for (let i = 0; i < (contributors.length > 5 ? 5 : contributors.length); i++) {
      const random = Math.floor(Math.random() * (contributors.length - 1));
      let contributorToPush = contributors[random];
      let k = 1;
      while (responseContributors.some(c => c.login === contributorToPush.login)) {
        contributorToPush = contributors[random + k < contributors.length - 1 ? random + k : random - k];
        k++;
      }

      responseContributors.push(contributorToPush);
    }
    notifications.sendInterestingPeople(id, responseContributors);
  }).catch((error) => {
    console.log(error);
  });
}

export default { computeRecommendedPeople };<commit_msg>Big with people without repos fixed<commit_after>/* eslint-disable max-len */
import GitHubApi from 'github';
import dataStorage from '../storage/dataStorage';
import notifications from '../services/notifications';

const github = GitHubApi();
github.authenticate({
  type: 'oauth',
  key: process.env.CLIENT_ID,
  secret: process.env.CLIENT_SECRET
});

function getContributors(repositories) {
  const promises = [];
  repositories.forEach((repo) => {
    if (Object.keys(repo).length > 0) {
      promises.push(new Promise((resolve, reject) => {
        github.repos.getContributors({ owner: repo.owner.login, repo: repo.name, page: 1, per_page: 5 }, (err, res) => {
          if (err) {
            reject();
          } else {
            resolve({ contributors: res.data });
          }
        });
      }));
    }
  });

  return promises;
}

function computeRecommendedPeople(id) {
  const repositories = dataStorage.getGithubUserInterestingRepositories(id);
  const contributors = [];
  if (repositories.length === 0) {
    notifications.sendInterestingPeople(id, []);
  } else {
    Promise.all(getContributors(repositories)).then((values) => {
      values.forEach((value) => {
        value.contributors.forEach((contributor) => {
          contributors.push(contributor);
        });
      });

      const responseContributors = [];
      for (let i = 0; i < (contributors.length > 5 ? 5 : contributors.length); i++) {
        const random = Math.floor(Math.random() * (contributors.length - 1));
        let contributorToPush = contributors[random];
        let k = 1;
        while (responseContributors.some(c => c.login === contributorToPush.login)) {
          contributorToPush = contributors[random + k < contributors.length - 1 ? random + k : random - k];
          k++;
        }

        responseContributors.push(contributorToPush);
      }
      notifications.sendInterestingPeople(id, responseContributors);
    }).catch((error) => {
      console.log(error);
    });
  }
}

export default { computeRecommendedPeople };
{'fraction_non_alphanumeric': 0.1448900388098318, 'fraction_numerical': 0.004657179818887452, 'mean_word_length': 3.1171458998935035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '7310864', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1099, 'n_words': 231}