Allow subgroups to set a Duo template project
What does this MR do and why?
Only a top-level group can pick the project that holds Duo Code Review custom instructions and exclusion rules. Teams that own a subgroup, but not the top-level group, have to copy the same .gitlab/duo/mr-review-instructions.yaml into every project, and every rule change means editing all of those files.
With this MR, a subgroup Owner can pick a Duo template project too. The project must be in the subgroup or one of its subgroups, so a subgroup cannot pull instructions from a parent or sibling group. Code Review already reads the template project of every parent group, so a subgroup's instructions are added after its parents' and never replace them. Exclusion rules from a subgroup's template project apply the same way.
The epic also proposes a cap on the total size of instructions from all group levels. That cap is not part of this MR.
References
- Closes gitlab-org#22329 (closed)
- Top-level only since !231941 (merged)
- Custom instructions moved to the shared layer lookup in !277014 (merged)
Screenshots or screen recordings
| Before | After |
|---|---|
| A subgroup's Settings > General > GitLab Duo features has no Customize code review section | ![]() |
How to set up and validate locally
Use a GDK with GitLab Duo set up for gitlab-duo/test, so that Duo Code Review runs when you add GitLabDuo as a reviewer.
-
In
gitlab-duo, create a subgroupreview-teamwith two projects:review-templateandapp. -
In
review-template, add.gitlab/duo/mr-review-instructions.yamlon the default branch:instructions: - name: Subgroup rule fileFilters: ["**/*.rb"] instructions: Check that every new Ruby class has a short class comment.In
app, add the same file with a project rule:instructions: - name: Project rule fileFilters: ["**/*.rb"] instructions: Check that every new public Ruby method has a spec. -
Go to
review-team's Settings > General > GitLab Duo features > Customize code review. The Source project list has onlyreview-team/appandreview-team/review-template. Selectreview-templateand select Save changes. -
Open an MR in
review-team/appthat adds a Ruby file, for exampleapp/models/widget.rbwith a class that has one public method. AddGitLabDuoas a reviewer. -
When the review finishes, open the review session from the MR's "started review session" note. In the session's review context,
custom_instructions_summarylists the instructions ofgitlab-duo's template project first (if it has one), thenSubgroup rule, thenProject rule. The MR has review comments that start withAccording to custom instructions in 'Subgroup rule'andAccording to custom instructions in 'Project rule'. -
Try to set a project outside the subgroup:
curl -s -X PUT -H "PRIVATE-TOKEN: $TOKEN" -H 'Content-Type: application/json' -d '{"duo_template_project_id": <gitlab-duo/test id>}' "http://gdk.test:3000/api/v4/groups/<review-team id>"It returns
400withDuo template project does not belong to this group.
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.
