Skip to content
Snippets Groups Projects
Select Git revision
  • 18b98a30e3c3aa78b06a5eb7f9a94145c4fc42f5
  • master default protected
  • gh-pages
  • dependabot/npm_and_yarn/eslint-plugin-jsdoc-51.0.3
  • dependabot/npm_and_yarn/nock-14.0.5
  • dependabot/npm_and_yarn/react-19.1.0
  • dependabot/npm_and_yarn/react-dom-19.1.0
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • dependabot/npm_and_yarn/path-to-regexp-8.2.0
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2023-08-01-75858a03
  • server-2023-07-01-02183d8d
  • server-2025-07-01
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
  • server-2024-07-01
  • 4.0.0
  • server-2024-06-01
41 results

prometheus-metrics.js

Blame
  • limits.js 1.68 KiB
    const moment = require('moment');
    
    module.exports = {
      getPrHourlyRemaining,
      getConcurrentPrsRemaining,
      getPrsRemaining,
    };
    
    async function getPrHourlyRemaining(config) {
      if (config.prHourlyLimit) {
        const prList = await platform.getPrList();
        const currentHourStart = moment({
          hour: moment().hour(),
        });
        try {
          const soFarThisHour = prList.filter(
            pr =>
              pr.branchName !== 'renovate/configure' &&
              moment(pr.createdAt).isAfter(currentHourStart)
          ).length;
          const prsRemaining = config.prHourlyLimit - soFarThisHour;
          logger.debug(`PR hourly limit remaining: ${prsRemaining}`);
          return prsRemaining;
        } catch (err) {
          logger.error('Error checking PRs created per hour');
        }
      }
      return 99;
    }
    
    async function getConcurrentPrsRemaining(config, branches) {
      if (config.prConcurrentLimit) {
        logger.debug(`Enforcing prConcurrentLimit (${config.prConcurrentLimit})`);
        let currentlyOpen = 0;
        for (const branch of branches) {
          if (await platform.branchExists(branch.branchName)) {
            currentlyOpen += 1;
          }
        }
        logger.debug(`${currentlyOpen} PRs are currently open`);
        const concurrentRemaining = config.prConcurrentLimit - currentlyOpen;
        logger.debug(`PR concurrent limit remaining: ${concurrentRemaining}`);
        return concurrentRemaining;
      }
      return 99;
    }
    
    async function getPrsRemaining(config, branches) {
      const hourlyRemaining = await module.exports.getPrHourlyRemaining(config);
      const concurrentRemaining = await module.exports.getConcurrentPrsRemaining(
        config,
        branches
      );
      return hourlyRemaining < concurrentRemaining
        ? hourlyRemaining
        : concurrentRemaining;
    }