Add ability to reference Maintainers, Developers or Owners from CODEOWNERS
What does this MR do and why?
Add the ability to reference any default role to a code owners file using an @@ prefix.
See the attached screen grab for the result.
Local migration output
Up
main: == [advisory_lock_connection] object_id: 129560, pg_backend_pid: 54209
main: == 20241104130731 AddRoleApproversToApprovalMergeRequestRules: migrating ======
main: -- add_column(:approval_merge_request_rules, :role_approvers, :integer, {:array=>true, :default=>[], :null=>false})
main: -> 0.0132s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute("ALTER TABLE approval_merge_request_rules\nADD CONSTRAINT check_approval_m_r_rules_allowed_role_approvers_valid_entries\nCHECK ( (role_approvers = '{}' OR role_approvers <@ ARRAY[20, 30, 40, 50, 60]) )\nNOT VALID;\n")
main: -> 0.0076s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0012s
main: -- execute("ALTER TABLE approval_merge_request_rules VALIDATE CONSTRAINT check_approval_m_r_rules_allowed_role_approvers_valid_entries;")
main: -> 0.0032s
main: -- execute("RESET statement_timeout")
main: -> 0.0039s
main: == 20241104130731 AddRoleApproversToApprovalMergeRequestRules: migrated (0.1464s)
Down
main: == [advisory_lock_connection] object_id: 129120, pg_backend_pid: 40793
main: == 20241104130731 AddRoleApproversToApprovalMergeRequestRules: reverting ======
main: -- remove_column(:approval_merge_request_rules, :role_approvers)
main: -> 0.0085s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute(" ALTER TABLE approval_merge_request_rules\n DROP CONSTRAINT IF EXISTS check_approval_m_r_rules_allowed_role_approvers_valid_entries\n")
main: -> 0.0083s
main: == 20241104130731 AddRoleApproversToApprovalMergeRequestRules: reverted (0.0598s)
main: == [advisory_lock_connection] object_id: 129120, pg_backend_pid: 40793
Query plan for new ProjectMembers with_roles scope.
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/33170/commands/102470
The scope is used with pluck_user_ids method here
See query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/33170/commands/102472
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
Reference_developers_from_codeowners_file_small
How to set up and validate locally
- Enable the
codeowner_role_approversfeature flag. - Setup a local project with codeowners.
- In the codeowners file specify a file and a role. eg:
README.md @@developer - Make an MR which changes the specified file and notice the list of recommended approvers are developers in the project.
Related to #282438 (closed)
Spike issue #479928 (closed)
Edited by Gavin Hinfey