Draft: External merge request approvals
What does this MR do?
- Adds a new database table:
external_approvals
which acts as a join table between theExternalApprovalRule
andMergeRequest
models. (This MR only allows creation of those records, it doesn't infer whether or not an MR has been approved.)
- There are 3 migrations - Table creation, and then two migrations; one for each of the new indices.
- Adds a new REST API endpoint to approve an MR from an external source. It takes two parameters:
-
external_approval_rule_id
- The ID of the external approval rule. -
sha
- The current git sha atHEAD
of the source branch.
[POST] /api/v4/projects/:project_id/merge_requests/:merge_request_iid/external_approve?external_approval_rule_id=???&sha=???
Database Review
Migration 1
Up
== 20210323125809 CreateExternalApprovalTable: migrating ======================
-- create_table(:external_approvals)
-> 0.0130s
-- add_index(:external_approvals, :merge_request_id)
-> 0.0030s
-- add_index(:external_approvals, :external_approval_rule_id)
-> 0.0020s
== 20210323125809 CreateExternalApprovalTable: migrated (0.0182s) =============
Down
== 20210323125809 CreateExternalApprovalTable: reverting ======================
-- drop_table(:external_approvals)
-> 0.0059s
== 20210323125809 CreateExternalApprovalTable: reverted (0.0059s) =============
Migration 2
Up
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: migrating ===========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:external_approvals)
-> 0.0039s
-- execute("ALTER TABLE external_approvals\nADD CONSTRAINT fk_3c93e422b8\nFOREIGN KEY (merge_request_id)\nREFERENCES merge_requests (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0027s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- execute("ALTER TABLE external_approvals VALIDATE CONSTRAINT fk_3c93e422b8;")
-> 0.0101s
-- execute("RESET ALL")
-> 0.0006s
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: migrated (0.0269s) ==
Down
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: reverting ===========
-- remove_foreign_key(:external_approvals, {:column=>:merge_request_id})
-> 0.0045s
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: reverted (0.0119s) ==
Migration 3
Up
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: migrating ==========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:external_approvals)
-> 0.0032s
-- execute("ALTER TABLE external_approvals\nADD CONSTRAINT fk_7dc55a62b2\nFOREIGN KEY (external_approval_rule_id)\nREFERENCES external_approval_rules (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0035s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- execute("ALTER TABLE external_approvals VALIDATE CONSTRAINT fk_7dc55a62b2;")
-> 0.0029s
-- execute("RESET ALL")
-> 0.0006s
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: migrated (0.0203s) =
Down
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: reverting ==========
-- remove_foreign_key(:external_approvals, {:column=>:external_approval_rule_id})
-> 0.0043s
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: reverted (0.0124s) =
Walkthrough & How to test
Walkthrough video: https://www.loom.com/share/a6e88b92ba824d29b29a48be4d14352e
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. (New migration added, despite feature being gated.) -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #267519 (closed)
Edited by Max Woolf