CommitList GraphQL query
Spike completed in [Spike] Investigate potential architecture for ... (#535989 - closed)
We need to create a new graphql query to return a list of commit similar to the commits_controller
The controller uses two different RPCs. If a search term has been passed it uses the CommitsByMessage RPC. If no search term has been passed we use FindCommits.
We have updated the FindCommits RPC to allow passing a
The message_regex which we can use to search for the commits.FindCommits RPC is deprecated so we are using the ListCommits RPC now, however, that does not support path currently.
For the first iteration we would like parity with the existing filters:
-
search->message_regex authorref-
(path is currently unsupported)path committed_beforecommitted_after
We also need to be able to paginate using an offset and limit. The offset should be marked as experimental as we'll be switching to cursor based pagination in the near future.
Proposal
Replicate the logic from the commits controller but modify it to only use the FindCommits RPC now that it can support search
def set_commits
limit = permitted_params[:limit].to_i
@limit = limit > 0 ? limit : COMMITS_DEFAULT_LIMIT # limit can only ever be a positive number
@offset = (permitted_params[:offset] || 0).to_i
search = permitted_params[:search]
author = permitted_params[:author]
committed_before = convert_date_to_epoch(permitted_params[:committed_before])
committed_after = convert_date_to_epoch(permitted_params[:committed_after])
# fully_qualified_ref is available in some situations from ExtractsRef
ref = @fully_qualified_ref || @ref
@commits =
if search.present?
@repository.find_commits_by_message(search, ref, @path, @limit, @offset)
else
options = {
path: @path,
limit: @limit,
offset: @offset
}
options[:author] = author if author.present?
options[:before] = committed_before if committed_before.present?
options[:after] = committed_after if committed_after.present?
@repository.commits(ref, **options)
end
@commits.load_tags
@commits.each(&:lazy_author) # preload authors
@commits = @commits.with_markdown_cache.with_latest_pipeline(ref)
@commits = set_commits_for_rendering(@commits)
end