<commit_before>const moment = require('moment');
const tmp = require('tmp-promise');

const branchWorker = require('../branch');

module.exports = {
  writeUpdates,
};

async function writeUpdates(config) {
  let { branches } = config;
  logger.info(`Processing ${branches.length} branch(es)`);
  if (branches.some(upg => upg.isPin)) {
    branches = branches.filter(upg => upg.isPin);
    logger.info(`Processing ${branches.length} "pin" PRs first`);
  }
  const tmpDir = await tmp.dir({ unsafeCleanup: true });
  let prsRemaining = 99;
  if (config.prHourlyLimit) {
    const prList = await platform.getPrList();
    const currentHourStart = moment({
      hour: moment().hour(),
    });
    try {
      prsRemaining =
        config.prHourlyLimit -
        prList.filter(pr => moment(pr.createdAt).isAfter(currentHourStart))
          .length;
      logger.info(`PR creations remaining this hour: ${prsRemaining}`);
    } catch (err) {
      logger.error('Error checking PRs created per hour');
    }
  }
  try {
    for (const branch of branches) {
      const res = await branchWorker.processBranch({
        ...branch,
        tmpDir,
        prHourlyLimitReached: prsRemaining <= 0,
      });
      if (res === 'pr-closed' || res === 'automerged') {
        // Stop procesing other branches because base branch has been changed
        return res;
      }
      prsRemaining -= res === 'pr-created' ? 1 : 0;
    }
    return 'done';
  } finally {
    tmpDir.cleanup();<commit_msg>fix: ignore onboarding branch when calculating pr hourly limit<commit_after>const moment = require('moment');
const tmp = require('tmp-promise');

const branchWorker = require('../branch');

module.exports = {
  writeUpdates,
};

async function writeUpdates(config) {
  let { branches } = config;
  logger.info(`Processing ${branches.length} branch(es)`);
  if (branches.some(upg => upg.isPin)) {
    branches = branches.filter(upg => upg.isPin);
    logger.info(`Processing ${branches.length} "pin" PRs first`);
  }
  const tmpDir = await tmp.dir({ unsafeCleanup: true });
  let prsRemaining = 99;
  if (config.prHourlyLimit) {
    const prList = await platform.getPrList();
    const currentHourStart = moment({
      hour: moment().hour(),
    });
    try {
      prsRemaining =
        config.prHourlyLimit -
        prList.filter(
          pr =>
            pr.branchName !== 'renovate/configure' &&
            moment(pr.createdAt).isAfter(currentHourStart)
        ).length;
      logger.info(`PR creations remaining this hour: ${prsRemaining}`);
    } catch (err) {
      logger.error('Error checking PRs created per hour');
    }
  }
  try {
    for (const branch of branches) {
      const res = await branchWorker.processBranch({
        ...branch,
        tmpDir,
        prHourlyLimitReached: prsRemaining <= 0,
      });
      if (res === 'pr-closed' || res === 'automerged') {
        // Stop procesing other branches because base branch has been changed
        return res;
      }
      prsRemaining -= res === 'pr-created' ? 1 : 0;
    }
    return 'done';
  } finally {
    tmpDir.cleanup();
{'fraction_non_alphanumeric': 0.14009038089089734, 'fraction_numerical': 0.0032278889606197547, 'mean_word_length': 2.77007299270073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3374224', 'n_tokens_mistral': 961, 'n_tokens_neox': 955, 'n_words': 234}