diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-07-02 05:01:36 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-07-08 10:36:32 +0300 |
commit | f8d6f7322ea43ff7844d006885db9f0c36ad7cc9 (patch) | |
tree | b1177546270245395ca30479ada1e75da903a4a9 /app/models/merge_request.rb | |
parent | c03f23c48311f0663458bbed33131fa3a6c80842 (diff) |
Fix race condition on merge train ref generation
Today, Pipelines for merge train run on `refs/merge`,
however, this causes a race condition that it can be
overwritten by CheckMergeabilityService.
This patch fixes the problem by generating `refs/train`
for those pipelines.
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index e96e26cc773..53977748c30 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1127,6 +1127,19 @@ class MergeRequest < ApplicationRecord "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/merge" end + def train_ref_path + "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/train" + end + + def cleanup_refs(only: :all) + target_refs = [] + target_refs << ref_path if %i[all head].include?(only) + target_refs << merge_ref_path if %i[all merge].include?(only) + target_refs << train_ref_path if %i[all train].include?(only) + + project.repository.delete_refs(*target_refs) + end + def self.merge_request_ref?(ref) ref.start_with?("refs/#{Repository::REF_MERGE_REQUEST}/") end |