From 874de00766024bb0605dac659e64127d589adf86 Mon Sep 17 00:00:00 2001 From: Siddharth Asthana Date: Wed, 8 Oct 2025 01:24:09 +0530 Subject: [PATCH] Add committer avatar and profile URL fields to GraphQL API This adds three new fields to the CommitType GraphQL API to support displaying committer information with avatar and profile links in the UI: - committerAvatarUrl: Returns the committer's GitLab avatar or Gravatar URL - committerWebUrl: Returns the committer's GitLab profile URL (null for non-GitLab users) - committer: Returns the User object for the committer (null for non-GitLab users) The resolvers check if the committer email matches a GitLab user and return their profile information, falling back to Gravatar URLs for non-GitLab users. This provides the data needed for the frontend to display clickable committer avatars and links. This is the backend portion of the feature. Frontend changes will follow in a separate MR to ensure multiversion compatibility during rolling deployments. Related to https://gitlab.com/gitlab-org/gitlab/-/issues/551775 Changelog: added Signed-off-by: Siddharth Asthana --- app/graphql/types/repositories/commit_type.rb | 23 +++++++++++++++++++ doc/api/graphql/reference/_index.md | 3 +++ .../types/repositories/commit_type_spec.rb | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/graphql/types/repositories/commit_type.rb b/app/graphql/types/repositories/commit_type.rb index 1c6a6d22162cb2..e822dcaac88fa7 100644 --- a/app/graphql/types/repositories/commit_type.rb +++ b/app/graphql/types/repositories/commit_type.rb @@ -65,10 +65,19 @@ class CommitType < BaseObject field :committer_name, type: GraphQL::Types::String, null: true, description: "Name of the committer." + field :committer_avatar_url, type: GraphQL::Types::String, null: true, + description: 'Avatar URL of the committer.' + + field :committer_web_url, type: GraphQL::Types::String, null: true, + description: 'Web URL of the committer.' + # models/commit lazy loads the author by email field :author, type: Types::UserType, null: true, description: 'Author of the commit.' + field :committer, type: Types::UserType, null: true, + description: 'Committer of the commit.' + field :diffs, [Types::DiffType], null: true, calls_gitaly: true, description: 'Diffs contained within the commit. ' \ 'This field can only be resolved for 10 diffs in any single request.' do @@ -93,6 +102,20 @@ def diffs def author_gravatar GravatarService.new.execute(object.author_email, 40) end + + def committer_avatar_url + if object.committer + object.committer.avatar_url + elsif object.committer_email + GravatarService.new.execute(object.committer_email, 40) + end + end + + def committer_web_url + return unless object.committer + + Gitlab::Routing.url_helpers.user_url(object.committer) + end end end end diff --git a/doc/api/graphql/reference/_index.md b/doc/api/graphql/reference/_index.md index cabfdeb803db7a..5219c7ece153ae 100644 --- a/doc/api/graphql/reference/_index.md +++ b/doc/api/graphql/reference/_index.md @@ -26757,8 +26757,11 @@ Represents a summary of the compared codequality report. | `authorName` | [`String`](#string) | Commit authors name. | | `authoredDate` | [`Time`](#time) | Timestamp of when the commit was authored. | | `committedDate` | [`Time`](#time) | Timestamp of when the commit was committed. | +| `committer` | [`UserCore`](#usercore) | Committer of the commit. | +| `committerAvatarUrl` | [`String`](#string) | Avatar URL of the committer. | | `committerEmail` | [`String`](#string) | Email of the committer. | | `committerName` | [`String`](#string) | Name of the committer. | +| `committerWebUrl` | [`String`](#string) | Web URL of the committer. | | `description` | [`String`](#string) | Description of the commit message. | | `descriptionHtml` | [`String`](#string) | GitLab Flavored Markdown rendering of `description`. | | `diffs` | [`[Diff!]`](#diff) | Diffs contained within the commit. This field can only be resolved for 10 diffs in any single request. | diff --git a/spec/graphql/types/repositories/commit_type_spec.rb b/spec/graphql/types/repositories/commit_type_spec.rb index bc6da8931d3c67..d96cf719b6b733 100644 --- a/spec/graphql/types/repositories/commit_type_spec.rb +++ b/spec/graphql/types/repositories/commit_type_spec.rb @@ -14,7 +14,8 @@ :id, :sha, :short_id, :title, :full_title, :full_title_html, :description, :description_html, :message, :title_html, :authored_date, :author_name, :author_email, :author_gravatar, :author, :diffs, :web_url, :web_path, - :pipelines, :signature_html, :signature, :committer_name, :committer_email, :committed_date, + :pipelines, :signature_html, :signature, :committer_name, :committer_email, :committer_avatar_url, + :committer_web_url, :committer, :committed_date, :name ) end -- GitLab