Fix bug of coverage check approval rules
What does this MR do and why?
Close #416354 (closed)
Jihu issue: https://jihulab.com/gitlab-cn/gitlab/-/issues/3958
What
This MR is used to repair: Coverage check approval rule requires approval, even though code coverage increased.
Cause of the problem: #416354 (comment 1715358627)
How to fix
- Pipelines in MR are divided into two categories:
Base Pipeline
andHead Pipeline
.
taking the "feature -> master" branch as an example.
Base Pipeline
is the pipeline of on master branch when MR is created
Head Pipeline
is the pipeline of the latest sha of the feature branch - Now when the status of
Head Pipeline
is updated (for example, from running to complete), the Approval rules of MR will be updated. - The current MR adds a new logic: when the status of the
Base Pipeline
is updated, the Approval rules of the MR are also updated.
SQL Changes
Ruby> pipeline.merge_requests_as_base_pipeline
Project Load (1.9ms) SELECT "projects"."id", "projects"."name", "projects"."path", "projects"."description", "projects"."created_at", "projects"."updated_at", "projects"."creator_id", "projects"."namespace_id", "projects"."last_activity_at", "projects"."import_url", "projects"."visibility_level", "projects"."archived", "projects"."avatar", "projects"."merge_requests_template", "projects"."star_count", "projects"."merge_requests_rebase_enabled", "projects"."import_type", "projects"."import_source", "projects"."approvals_before_merge", "projects"."reset_approvals_on_push", "projects"."merge_requests_ff_only_enabled", "projects"."issues_template", "projects"."mirror", "projects"."mirror_last_update_at", "projects"."mirror_last_successful_update_at", "projects"."mirror_user_id", "projects"."shared_runners_enabled", "projects"."runners_token", "projects"."build_allow_git_fetch", "projects"."build_timeout", "projects"."mirror_trigger_builds", "projects"."pending_delete", "projects"."public_builds", "projects"."last_repository_check_failed", "projects"."last_repository_check_at", "projects"."only_allow_merge_if_pipeline_succeeds", "projects"."has_external_issue_tracker", "projects"."repository_storage", "projects"."repository_read_only", "projects"."request_access_enabled", "projects"."has_external_wiki", "projects"."ci_config_path", "projects"."lfs_enabled", "projects"."description_html", "projects"."only_allow_merge_if_all_discussions_are_resolved", "projects"."repository_size_limit", "projects"."printing_merge_request_link_enabled", "projects"."auto_cancel_pending_pipelines", "projects"."service_desk_enabled", "projects"."cached_markdown_version", "projects"."delete_error", "projects"."last_repository_updated_at", "projects"."disable_overriding_approvers_per_merge_request", "projects"."storage_version", "projects"."resolve_outdated_diff_discussions", "projects"."remote_mirror_available_overridden", "projects"."only_mirror_protected_branches", "projects"."pull_mirror_available_overridden", "projects"."jobs_cache_index", "projects"."external_authorization_classification_label", "projects"."mirror_overwrites_diverged_branches", "projects"."pages_https_only", "projects"."external_webhook_token", "projects"."packages_enabled", "projects"."merge_requests_author_approval", "projects"."pool_repository_id", "projects"."runners_token_encrypted", "projects"."bfg_object_map", "projects"."detected_repository_languages", "projects"."merge_requests_disable_committers_approval", "projects"."require_password_to_approve", "projects"."max_pages_size", "projects"."max_artifacts_size", "projects"."pull_mirror_branch_prefix", "projects"."remove_source_branch_after_merge", "projects"."marked_for_deletion_at", "projects"."marked_for_deletion_by_user_id", "projects"."autoclose_referenced_issues", "projects"."suggestion_commit_message", "projects"."project_namespace_id", "projects"."hidden", "projects"."organization_id" FROM "projects" WHERE "projects"."id" = 18 LIMIT 1 /*application:console,db_config_name:main,console_hostname:MacBook-Pro-6.local,console_username:deer,line:/ee/app/models/ee/ci/pipeline.rb:283:in `merge_requests_as_base_pipeline'*/
MergeRequest Load (1.1ms) SELECT "merge_requests".* FROM "merge_requests" WHERE "merge_requests"."target_project_id" = 18 AND "merge_requests"."state_id" = 1 AND "merge_requests"."id" IN (SELECT "merge_request_diffs"."merge_request_id" FROM "merge_request_diffs" WHERE "merge_request_diffs"."project_id" = 18 AND "merge_request_diffs"."base_commit_sha" = '1036e657ebcb85b01f4e1fed01602e6923d74545') /*application:console,db_config_name:main,console_hostname:MacBook-Pro-6.local,console_username:deer,line:bin/rails:4:in `<main>'*/
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
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
-
Enable Feature flag:
::Feature.enable(:update_approval_rules_for_related_mrs)
-
Enable Coverage-check in settings
-
Configure
.gitlab-ci.yml
, set test coverage to 10%, and set job rules to manualtest: script: - echo "Hello, World!" - echo 'Code coverage 10.0%' coverage: '/Code coverage \d+\.\d+/' when: manual
-
Trigger a
main
branch pipeline, do not manually execute the job -
Create a new branch
feature
, increase the test coverage to 20%, create an MR of feature -> main, and execute the feature job manually -
You can see that the Coverage-check on the MR page requires approval
-
Manually execute the pipeline of the
main
branch. You can see that the Coverage-check no longer requires approval✨