Skip to content

On MR merge, save a list of compliance violations that occurred at the point of merging

What does this MR do and why?

This MR adds a new service worker to the EE PostMergeService so when an MR is merged, we will asynchronously review the merged MR for any compliance violations and save these to the merge_requests_compliance_violations table. These saved violations will be used by #347325 (closed).

We add a new feature flag so we can easily incrementally roll this out or roll this back to protect the merge process.

During testing it became apparent that the initial assumptions on data locations were incorrect so I have had to update the violation classes with:

  • Updated ApprovedByCommitter and ApprovedByMergeRequestAuthor to use approved_by_users rather than approver_users
  • Updated ApprovedByInsufficientUsers to use the merge request metrics data if it exists

How to set up and validate locally

  1. Enable the feature flag compliance_violations_graphql_type: echo "Feature.enable(:compliance_violations_graphql_type)" | bundle exec rails c
  2. Go to a projects general settings and make sure Prevent approval by author. is unticked under the Merge request approvals section
  3. Edit a file in the project and create a new merge request
  4. Use the merge requests author to approve the merge request and then merge it
  5. Wait for merging to be completed
  6. Check the merge_request_compliance_violations table to see it has been filled with three violations (reasons 0, 1 and 2) for your merge request
    • Use a database GUI
    • In your terminal enter gdk psql and then run the following query: SELECT * FROM merge_requests_compliance_violations;

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #347324 (closed)

Edited by Robert Hunt

Merge request reports