This instance will be upgraded to Heptapod 0.25.0 (final) on 2021-09-22 at 15:00 UTC+2 (a few minutes of down time)

Commit eb212e46 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Removing redundant code from MergeRequest::RefreshService

With the early detection for topics now done in `PostReceive`,
we don't need the "detection from source" that has been there
since Heptapod 0.12.

Also, we don't need to trigger deletion for the topic GitLab
branch: it's been pruned already by Mercurial, same as it will
when we go native.

--HG--
branch : heptapod-stable
parent e5b0cd22f33e
......@@ -66,36 +66,12 @@ def hg_git?
@project.vcs_type == 'hg_git'
end
def hg_refresh_manually_merged(merge_request, real_source_sha)
recorded_source_sha = merge_request.diff_head_sha
return if recorded_source_sha == real_source_sha
old_diff_refs = merge_request.diff_refs
# base should not have changed if target is a Mercurial named
# branch (TODO one day we'll have MRs between topics)
new_diff = MergeRequestDiff.create(
merge_request_id: merge_request.id,
head_commit_sha: real_source_sha,
base_commit_sha: old_diff_refs.base_sha,
start_commit_sha: old_diff_refs.start_sha,
)
new_diff.save_git_content
new_diff_refs = merge_request.diff_refs
merge_request.update_diff_discussion_positions(
old_diff_refs: old_diff_refs,
new_diff_refs: new_diff_refs,
current_user: @current_user)
end
# Collect open merge requests that target same branch we push into
# and close if push to master include last commit from merge request
# We need this to close(as merged) merge requests that were merged into
# target branch manually
# rubocop: disable CodeReuse/ActiveRecord
def post_merge_manually_merged
mercurial = project.vcs_type == "hg_git" # TODO graft commit from 0.8?
commit_ids = @commits.map(&:id)
merge_requests = @project.merge_requests.opened
.preload(:latest_merge_request_diff)
......@@ -118,47 +94,13 @@ def post_merge_manually_merged
else
merge_request.head_source_sha
end
merged = commit_ids.include?(source_sha) &&
merge_request.merge_request_diff.state != 'empty'
hg_refresh_manually_merged(merge_request, source_sha) if hg_git? && merged
merged
end
is_topic = @push.branch_name.start_with?('topic/')
if hg_git? && is_topic
# we need to treat merge requests of which the branch is the source
# as well, because if the source branch is processed first,
# then it'll go to next step if not merged, i.e. reload_diff, which
# makes the diff empty on rebase/publish.
merge_requests.concat(
@project.merge_requests.opened
.preload(:latest_merge_request_diff)
.where(source_branch: @push.branch_name).to_a
.select(&:diff_head_commit)
.select do |merge_request|
real_target_sha = merge_request.target_branch_sha
merged = @project.repository.ancestor?(@push.newrev, real_target_sha)
hg_refresh_manually_merged(merge_request, @push.newrev) if merged
merged
end
)
commit_ids.include?(source_sha) &&
merge_request.merge_request_diff.state != 'empty'
end
for mr in merge_requests
Rails.logger.info("#{logprefix} marking MR id=#{mr.id} iid=#{mr.id} as merged")
end
if merge_requests.empty?
if is_topic
named_branch_name = 'branch/' + @push.branch_name.split('/')[1..-2].join('/')
named_branch_sha = @project.repository.find_branch(named_branch_name)&.target
if named_branch_sha.nil?
Rails.logger.warn("#{logprefix} could not find GitLab branch #{named_branch_name}")
else
if @project.repository.ancestor?(@push.newrev, named_branch_sha)
Rails.logger.info("#{logprefix} removing GitLab branch for published "\
"topic with no Merge Request")
DeleteBranchService.new(@project, current_user).execute(@push.branch_name, ignore_git_error: true)
end
end
end
Rails.logger.info("#{logprefix} no merge detected")
end
......@@ -170,7 +112,7 @@ def post_merge_manually_merged
# to work with Mercurial and publication of topics, and would be very
# clumsy anyway compared to what can be done with revsets.
# The feature is in itself interesting - we could provide it directly
commit_analyze_enabled = !mercurial && Feature.enabled?(:branch_push_merge_commit_analyze, @project, default_enabled: true)
commit_analyze_enabled = !project.mercurial? && Feature.enabled?(:branch_push_merge_commit_analyze, @project, default_enabled: true)
if commit_analyze_enabled
analyzer = Gitlab::BranchPushMergeCommitAnalyzer.new(
@commits.reverse,
......@@ -179,7 +121,7 @@ def post_merge_manually_merged
end
merge_requests.each do |merge_request|
if commit_analyze_enabled && !analyzer.nil?
if commit_analyze_enabled
merge_request.merge_commit_sha = analyzer.get_merge_commit(merge_request.diff_head_sha)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment