Adds ability to externally respond to status checks
What does this MR do?
- Adds a new database table:
external_status_checks
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.
Note: A future MR will be coming to rename ExternalApprovalRule
to ExternalStatusCheck
. This will happen before the feature is released.
[POST] /api/v4/projects/:project_id/merge_requests/:merge_request_iid/status_checks?external_approval_rule_id=???&sha=???
Database Review
Migration 1
Up
== 20210323125809 CreateExternalApprovalTable: migrating ======================
-- create_table(:status_check_responses)
-> 0.0198s
-- add_index(:status_check_responses, :merge_request_id)
-> 0.0037s
-- add_index(:status_check_responses, :external_approval_rule_id)
-> 0.0026s
== 20210323125809 CreateExternalApprovalTable: migrated (0.0263s) =============
Down
== 20210323125809 CreateExternalApprovalTable: reverting ======================
-- drop_table(:status_check_responses)
-> 0.0049s
== 20210323125809 CreateExternalApprovalTable: reverted (0.0049s) =============
Migration 2
Up
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: migrating ===========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:status_check_responses)
-> 0.0029s
-- execute("ALTER TABLE status_check_responses\nADD CONSTRAINT fk_f3953d86c6\nFOREIGN KEY (merge_request_id)\nREFERENCES merge_requests (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0041s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- execute("ALTER TABLE status_check_responses VALIDATE CONSTRAINT fk_f3953d86c6;")
-> 0.0206s
-- execute("RESET ALL")
-> 0.0007s
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: migrated (0.0383s) ==
Down
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: reverting ===========
-- remove_foreign_key(:status_check_responses, {:column=>:merge_request_id})
-> 0.0057s
== 20210323130831 AddFirstExternalApprovalRuleForeignKey: reverted (0.0150s) ==
Migration 3
Up
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: migrating ==========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:status_check_responses)
-> 0.0021s
-- execute("ALTER TABLE status_check_responses\nADD CONSTRAINT fk_116e7e7369\nFOREIGN KEY (external_approval_rule_id)\nREFERENCES external_approval_rules (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0022s
-- execute("ALTER TABLE status_check_responses VALIDATE CONSTRAINT fk_116e7e7369;")
-> 0.0048s
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: migrated (0.0135s) =
Down
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: reverting ==========
-- remove_foreign_key(:status_check_responses, {:column=>:external_approval_rule_id})
-> 0.0213s
== 20210323131543 AddSecondExternalApprovalRuleForeignKey: reverted (0.0319s) =
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