Mergeability framework
The initial work started with the
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 To create a new check, we can use this as a base:
When we want to add the check to the Merge When Checks Pass feature, we must:
Add a new check
app/services/merge_requests/mergeability/
.
# 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 approriate cache key that will invalidate correctly.
def cacheable?
false
end
end
end
end
def mergeable_state_checks
method.
app/graphql/types/merge_requests/detailed_merge_status_enum.rb
.
bundle exec rake gitlab:graphql:compile_docs
.
doc/api/merge_requests.md
.
app/assets/javascripts/vue_merge_request_widget/components/checks/message.vue
.
Considerations
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.
How the classes work together
def mergeable?
, and DetailedMergeStatusService
.
RunChecksService
class which handles the iterating
of the mergeability checks, caching and instrumentation.
Merge when checks pass
skipped_mergeable_checks
.
Future work