Add support for group-level Duo Code Review custom instructions
What does this MR do and why?
This merge request adds support for GitLab Duo Code Review to inherit custom review instructions from groups, not just individual projects.
Previously, code review instructions could only be defined at the project level. Now, groups can set up template projects with review instructions that automatically apply to all projects within that group and its subgroups. This creates a hierarchy where instructions from higher-level groups are combined with project-specific instructions.
This code is in use yet and a follow up MR will introduce an API endpoint do Duo Workflow Service can fetch these instructions for DAP mode.
The same will apply for the classic mode, where ReviewMergeRequest will have to be updated.
References
Related to #595535 (closed)
How to set up and validate locally
- Add custom instructions to a project
- Create a merge request under that project
- In a Rails console, fetch the project and merge_request and run
Gitlab::Duo::CodeReview::CustomInstructionsResolver.new(project).execute(merge_request)- Make sure instructions apply to the files (extensions) in the merge request you just created
- This should return the projects instructions only
- Create a second project under the same group and add more instructions
- This second project will serve as a template for custom instructions for all projects under that group
- Configure the group template:
project.group.create_namespace_template_setting(duo_template_project: duo_template_project)- Where
duo_template_projectis the project you created on step 4)
- Where
- Enable
duo_code_review_group_level_instructionsfeature flag:::Feature.enable(:duo_code_review_group_level_instructions, project) - Fetch the instructions again:
Gitlab::Duo::CodeReview::CustomInstructionsResolver.new(project).execute(merge_request)
pry(main)> Gitlab::Duo::CodeReview::CustomInstructionsResolver.new(project).execute(merge_request)
=> [#<Gitlab::Duo::CodeReview::CustomInstruction:0x0000000146a023b8
@exclude_patterns=[],
@include_patterns=["**/*.go"],
@instructions="1. Make any suggestions using Shakespeare conversation style",
@location="http://gdk.test:3000/gitlab-duo/duo-subgroup/duo-template/-/blob/main/.gitlab/duo/mr-review-instructions.yaml",
@name="Go files">]Database
Query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/50595/commands/150093
Unfortunately there are no groups with a Duo template project just yet.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.