doc/development/merge_request_concepts/mergeability_framework.md
The initial work started with the better defined mergeability framework
Originally, the mergeability knowledge was spread throughout the backend and frontend. This work was to consolidate some of the mergeability criteria into the same location in the backend. This allows the frontend to simply consume the API and display the error.
When adding a new merge check, we must make a few choices:
After we answer these questions, we can create the new check.
The mergeability checks live under app/services/merge_requests/mergeability/.
To create a new check, we can use this as a base:
# frozen_string_literal: true
module MergeRequests
module Mergeability
class CheckCiStatusService < CheckBaseService
identifier :ci_must_pass # Identifier used to state which check failed
description 'Checks whether CI has passed' # Description of the check returned through GraphQL
def execute
# If the merge check is behind a setting, we return inactive if the setting is false
return inactive unless merge_request.only_allow_merge_if_pipeline_succeeds?
if merge_request.mergeable_ci_state?
success
else
failure
end
end
def skip?
# Here we can check for the param or return false if its not skippable
# Skippablility of an MR is related to merge when checks pass functionality
params[:skip_ci_check].present?
end
# If we return true here, we need to create the method def cache_key and provide
# an appropriate cache key that will invalidate correctly.
def cacheable?
false
end
end
end
end
Add the new check in the def mergeable_state_checks method.
Add the new check to the GraphQL enum app/graphql/types/merge_requests/detailed_merge_status_enum.rb.
Update the GraphQL documentation with bundle exec rake gitlab:graphql:compile_docs.
Update the API documentation in doc/api/merge_requests.md.
Update the frontend to support the new message: app/assets/javascripts/vue_merge_request_widget/components/checks/message.vue.
false.def cacheable? method to return true,
and in that case, we need to create another method def cache_key to set the
cache key for the particular check. Cache invalidation can often be tricky,
and we must consider all the edge cases in the cache key. If we keep the timing
around 10-20 ms, then caching is not needed.app/services/merge_requests/mergeability/logger.rb
class, which can then be viewed in Kibana.def mergeable?, and DetailedMergeStatusService.RunChecksService class which handles the iterating
of the mergeability checks, caching and instrumentation.When we want to add the check to the Merge When Checks Pass feature, we must:
skipped_auto_merge_checks.