Create CommitsFinder class for Commits API
## Summary Create a new `CommitsFinder` class following the established pattern used by `BranchesFinder`, `TagsFinder`, and `TreeFinder` for git object pagination. ## Parent Issue This is part of #595504 (Epic: Refactor Commits API to use standard keyset pagination patterns) ## Background The Commits API currently has ~90 lines of inline pagination logic. To align with GitLab's patterns and improve testability, we need to extract this into a Finder class. ## Proposed Implementation ### File: `app/finders/commits_finder.rb` ```ruby # frozen_string_literal: true class CommitsFinder include Gitlab::Utils::StrongMemoize attr_reader :project, :current_user, :params def initialize(project, current_user, params = {}) @project = project @current_user = current_user @params = params end def execute(gitaly_pagination: false) return [] unless project.repository_exists? if gitaly_pagination execute_with_gitaly_pagination else execute_with_offset_pagination end end private def execute_with_gitaly_pagination validate_keyset_params! ref = params[:all] ? '--all' : (params[:ref_name] || project.default_branch) project.repository.list_commits( ref: ref, author: params[:author], committed_before: params[:until], committed_after: params[:since], pagination_params: { page_token: params[:page_token], limit: limit } ) end def execute_with_offset_pagination # Existing offset pagination logic end def validate_keyset_params! unsupported = [] unsupported << 'path' if params[:path].present? unsupported << 'first_parent' if params[:first_parent] unsupported << 'order' if params[:order] != 'default' unsupported << 'trailers' if params[:trailers] unsupported << 'follow' if params[:follow] raise ArgumentError, "#{unsupported.first} not supported with keyset pagination" if unsupported.any? end def limit per_page = params[:per_page].to_i per_page = Kaminari.config.default_per_page if per_page <= 0 [per_page, Kaminari.config.max_per_page].min end end ``` ## Acceptance Criteria - [ ] Create `app/finders/commits_finder.rb` with `execute(gitaly_pagination:)` method - [ ] Support both offset and keyset pagination modes - [ ] Validate unsupported parameters for keyset mode - [ ] Add comprehensive unit tests in `spec/finders/commits_finder_spec.rb` - [ ] Follow patterns from `BranchesFinder` and `TagsFinder` ## Reference Implementations - `app/finders/branches_finder.rb` - `app/finders/tags_finder.rb` - `app/finders/repositories/tree_finder.rb` ## References - Parent epic: #595504 - Original MR: !229705
issue