Skip to content

Adding backend support for summarizing a new merge request

Add backend endpoint for AI summary on a new MR

What does this MR do and why?

This MR adds the backend component for a new AI-powered feature to the merge request creation screen that automatically summarizes the changes in the merge request in a few sentences. This summary will help reviewers quickly understand the purpose and impact of the changes, making the review process more efficient.

MR acceptance checklist

  • Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Make sure your local AI settings are on! https://docs.gitlab.com/ee/development/ai_features/
  2. Enable the :add_ai_summary_for_new_mr feature flag in the rails console: Feature.enable(:add_ai_summary_for_new_mr)
  3. Go to your local GraphiQL instance (might be located at https://gdk.test:3443/-/graphql-explorer)
  4. Get a project ID from one of your local projects
  5. Find a branch to use as a comparison
  6. Try to run the following GraphQL query:
mutation {
  aiAction(
    input: {
      summarizeNewMergeRequest: {
    	  resourceId: "gid://gitlab/Project/[PROJECT ID NUMBER]",
        sourceBranch: "[COMPARISON BRANCH]"
        targetBranch: "main"
      }
    }
  ){
    requestId
    errors
    clientMutationId
  }
}
  1. Give a slight smile and nod approvingly.

Changes

  • Add a new mutation summarizeNewMergeRequest to the GraphQL API.
  • Add a new service Llm::SummarizeNewMergeRequestService to handle the mutation.
  • Add a new template Gitlab::Llm::Templates::SummarizeNewMergeRequest to generate the prompt for the AI model.
  • Add a new completions worker Gitlab::Llm::VertexAi::Completions::SummarizeNewMergeRequest to handle the completion request.
  • Add a new response modifier Gitlab::Llm::VertexAi::ResponseModifiers::Predictions to modify the response from the AI model.
  • Add a new subscription Gitlab::Llm::GraphqlSubscriptionResponseService to publish the response from the AI model to the GraphQL subscription.
  • Add a new policy ProjectPolicy#summarize_new_merge_request to control access to the new feature.
  • Add a new feature flag add_ai_summary_for_new_mr to control the availability of the new feature.
  • Add a new documentation page to explain the new feature.

Related issues


This description was generated for revision 84b31900 using AI

Edited by Gary Holtz

Merge request reports