Add diverging commits endpoint

Summary

Add GET /projects/:id/repository/diverging_commits, a REST endpoint that returns how many commits two refs have diverged by (behind/ahead). It also generalizes DivergingCommitCountsService so the endpoint can compute counts for arbitrary refs while the internal branches UI controller keeps its cached, branch-name-scoped path.

Closes #599031 (closed)

What does this MR do?

  • Adds a public diverging_counts(from, to, max_count:) method on DivergingCommitCountsService that computes counts directly (no caching), so arbitrary caller-supplied refs are never written to the shared diverging_commit_counts_* cache namespace. The existing call(branch) path keeps its Redis caching, keyed by branch name.
  • Adds the API endpoint implementation, presenting through Entities::DivergingCommitCount.
  • Gates it behind the repository_diverging_commits_api feature flag (beta, disabled by default; 404 when off) and marks it route_setting :lifecycle, :experiment. Available on all tiers — not license-gated.
  • Requires the read_commit permission, constrains from/to length, validates max_count as non-negative, and rate limits via project_repositories_diverging_commits.
  • Includes request and service specs.
  • Includes OpenAPI documentation (v2 and v3).
Edited by John Cai

Merge request reports

Loading