import { lazyInject } from "../../../inversify.config" ; import BaseScmCalculatorService from "./BaseScmCalculatorService" ; import SonarQubeApiScm from "../SonarQubeApiScm" ; import ComponentStatusStore from "../../../stores/ComponentStatusStore" ; export default class ScmCommitsCalculatorService extends BaseScmCalculatorService { @ lazyInject ( "ComponentStatusStore" ) private readonly componentStatusStore ! : ComponentStatusStore ; public calcNumberOfCommits ( measures ) { measures = measures . filter ( this . isAfterLeakPeriod . bind ( this ) ) ; const groupByCommits = this . groupBy ( measures , ( item ) => { return item . lastCommitRevision ; } ) ; return groupByCommits . size ; } private isAfterLeakPeriod ( item ) { if ( this . componentStatusStore . leakPeriodDate ) { return ( new Date ( item . lastCommit ) . getTime ( ) >= this . componentStatusStore . leakPeriodDate . getTime ( ) ) ; } else { return true ; } } }