Resolve review instructions with TemplateProjectResolver
What does this MR do and why?
Duo Code Review custom instructions are read from the instance, group, and project layers. That lookup had its own copy of the logic that risk assessment now gets from Gitlab::Duo::TemplateProjectResolver. The copy had some issues:
- A project that is also its group's (or the instance's) template project had its instructions sent twice.
- A YAML mistake in a customer's instructions file was reported to error tracking as an application error.
This MR moves custom instructions to the shared resolver, with a parser for .gitlab/duo/mr-review-instructions.yaml. A file that is not valid YAML, or that has no list of instructions, is skipped and logged as a warning instead of being sent to error tracking. The other layers still apply. Other errors in a file are still sent to error tracking, as before.
The order of group layers is now root group first, the same as risk assessment. Only a top-level group can set a Duo template project, so this does not change what users see.
References
Gitlab::Duo::TemplateProjectResolverwas added for risk assessment in !271468 (merged).
Screenshots or screen recordings
Not applicable: there is no UI change.
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.
-
Make sure the
gitlab-duogroup has no Duo template project: in Settings > General > GitLab Duo features > Customize code review, the Source project is empty. -
In
gitlab-duo/test, add.gitlab/duo/mr-review-instructions.yamlon the default branch:instructions: - name: Project Ruby rule fileFilters: ["**/*.rb"] instructions: Check that every new public Ruby method has a spec. -
Open an MR in
gitlab-duo/testthat adds a Ruby file, for exampleapp/models/ci_check_one.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 onlyProject Ruby rule. The review comments for the rule start withAccording to custom instructions in 'Project Ruby rule'. -
Create a project
gitlab-duo/review-templatewith.gitlab/duo/mr-review-instructions.yamlon its default branch:instructions: - name: Group Ruby rule fileFilters: ["**/*.rb"] instructions: Check that every new Ruby class has a short class comment. -
In
gitlab-duo, go to Settings > General > GitLab Duo features > Customize code review, selectgitlab-duo/review-templateas the Source project, and select Save changes. -
Open a new MR in
gitlab-duo/testthat adds another Ruby file, and addGitLabDuoas a reviewer. -
When the review finishes, open its session.
custom_instructions_summarylistsGroup Ruby ruleandProject Ruby rule, and the MR has review comments for both rules.
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.