1# frozen_string_literal: true 2 3module ProjectCommitCount 4 include Gitlab::Git::WrapsGitalyErrors 5 6 def commit_count_for(project, default_count: 0, max_count: nil, **exception_details) 7 raw_repo = project.repository&.raw_repository 8 root_ref = raw_repo&.root_ref 9 10 return default_count unless root_ref 11 12 Gitlab::GitalyClient::CommitService.new(raw_repo).commit_count(root_ref, { 13 all: true, # include all branches 14 max_count: max_count # limit as an optimization 15 }) 16 rescue StandardError => e 17 Gitlab::ErrorTracking.track_exception(e, exception_details) 18 19 default_count 20 end 21end 22