Move automatic duo code review availability out of models
What does this MR do and why?
This continues moving Duo Code Review logic out of Project, Namespace and ApplicationSetting, which are omniscient classes. It follows !266280 (merged).
auto_duo_code_review_settings_available? used to have its own rules. Over time those rules moved into the shared Duo Code Review availability check, and the method became a one-line alias on each model. This MR removes it from the models. Callers now use Gitlab::Duo::CodeReview.automatic_review_available?(container), a thin wrapper around available? on the availability classes. The wrapper keeps the intent clear at call sites such as the merge request auto-review hook.
The MR also adds a shared base class for the project, namespace and instance availability classes. It holds the container and the "GitLab Duo features are on" guard.
Behavior does not change.
References
Related #636674
Screenshots or screen recordings
Not applicable. No UI change.
How to set up and validate locally
The settings and the automatic review must work exactly as they do on master.
- Make sure your GDK has an active Duo Enterprise add-on, and GitLab Duo is on for the
gitlab-duogroup. - Go to
gitlab-duo/test> Settings > Merge requests. The Duo Code Review settings show. Turn on automatic reviews and save. - Create a merge request in
gitlab-duo/test. Duo is added as a reviewer and posts a review. - Go to the
gitlab-duogroup > Settings > General > Merge requests. The Duo Code Review settings show. - Go to Admin > Settings > General. The Duo Code Review settings show.
- Check the REST API:
It returns
curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/projects/gitlab-duo%2Ftest" | jq '.auto_duo_code_review_enabled'true. - Turn off GitLab Duo for the
gitlab-duogroup (Settings > GitLab Duo). Reload the pages from steps 2 and 4: the Duo Code Review settings no longer show, and the API field from step 6 is gone. Create another merge request: Duo is not added as a reviewer.
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.