Add stats field + first_parent/order arguments to repository.commits for list_commits MCP tool
Note
This is not an MCP tool issue itself — it's a GraphQL API prerequisite for #605875 (list_commits MCP tool), found while redirecting that issue's implementation plan from a REST wrap to the existing repository.commits query.
Problem Statement / Use Case
Query.project { repository { commits } } (Resolvers::Repositories::CommitsResolver) covers ref/path/author/committedBefore/committedAfter with cursor pagination, but is missing three things #605875 (list_commits MCP tool) needs to fully replace the REST-backed tool:
with_stats— per-commit line counts (additions/deletions/total).CommitTypeexposes onlydiffs(full patches), which is the opposite of what a commit list wants: cheap counts without pulling patches. The REST commits endpoint haswith_stats(Entities::CommitWithStats).first_parent— follow only the first parent of merge commits.order— topological vs. date ordering.
The model layer already supports the last two: Gitlab::Git::Repository#list_commits (and app/models/repository.rb#list_commits) accept first_parent: and order: — they're just not exposed as resolver arguments. Stats are available via Commit#diff_stats (Gitaly), surfaced in REST but not on CommitType.
Proposed Change
- Add a
statsfield toTypes::Repositories::CommitTypereturning additions/deletions/total (fromCommit#diff_stats), lookahead-gated so it only calls Gitaly when selected. - Add
first_parentandorderarguments toResolvers::Repositories::CommitsResolver, passed through torepository.list_commits(which already accepts them). - (
allfrom the REST tool is lower priority and has different semantics — treat separately / out of scope here unless a concrete need appears.)
Resources
app/graphql/resolvers/repositories/commits_resolver.rb— addfirst_parent/orderarguments;list_commits_argumentsalready forwards**argumentstorepository.list_commits.app/models/repository.rb:199#list_commitsandlib/gitlab/git/repository.rb:1173#list_commits— already takefirst_parent:/order:.app/graphql/types/repositories/commit_type.rb— add thestatsfield (no stats field exists today, onlydiffs).app/models/commit.rb:368#diff_stats(Gitalydiff_stats) — the data source for the stats field;lib/api/entities/commit_stats.rbis the REST shape to mirror (additions/deletions/total).
Implementation Plan
- Add
argument :first_parent, GraphQL::Types::Boolean, required: falseandargument :order, GraphQL::Types::String, required: false(or a small enum) toCommitsResolver, forwarded throughlist_commits_arguments. - Add a
statsfield toCommitType(additions/deletions/total viaCommit#diff_stats), gated on lookahead/selection so a commit list doesn't call Gitaly per node unlessstatsis requested. - Specs: resolver spec for
first_parent/orderfiltering; type spec forstats;spec/graphql/all_queries_spec.rbcoverage once#605875commits its.graphqlfile using the new field/args.