import { logger } from '../../logger' ; export enum Limit { Commits = 'Commits' , PullRequests = 'PullRequests' , Branches = 'Branches' } interface LimitValue { max : number | null ; current : number ; } const limits = new Map < Limit , LimitValue > ( ) ; export function resetAllLimits ( ) { limits . clear ( ) ; } export function setMaxLimit ( key , val ) { const max = typeof val === 'number' ? Math . max ( 0 , val ) : null ; limits . set ( key , { current : 0 , max } ) ; logger . debug ( `${ key } limit = ${ max }` ) ; } export function incLimitedValue ( key , incBy = 1 ) { const limit = limits . get ( key ) || { max : null , current : 0 } ; limits . set ( key , { ... limit , current : limit . current + incBy , } ) ; } export function isLimitReached ( key ) { const limit = limits . get ( key ) ; if ( ! limit || limit . max === null ) { return false ; } const { max , current } = limit ; return max - current <= 0 ; }