Commit 2f7563a6 authored by Mark Chao's avatar Mark Chao

Guard with feature flag

parent c6c53d1c
...@@ -66,13 +66,18 @@ module MergeRequests ...@@ -66,13 +66,18 @@ module MergeRequests
return if merge_requests.empty? return if merge_requests.empty?
analyzer = Gitlab::BranchPushMergeCommitAnalyzer.new( commit_analyze_enabled = Feature.enabled?(:branch_push_merge_commit_analyze, @project, default_enabled: true)
@commits.reverse, if commit_analyze_enabled
relevant_commit_ids: merge_requests.map(&:diff_head_sha) analyzer = Gitlab::BranchPushMergeCommitAnalyzer.new(
) @commits.reverse,
relevant_commit_ids: merge_requests.map(&:diff_head_sha)
)
end
merge_requests.each do |merge_request| merge_requests.each do |merge_request|
merge_request.merge_commit_sha = analyzer.get_merge_commit(merge_request.diff_head_sha) if commit_analyze_enabled
merge_request.merge_commit_sha = analyzer.get_merge_commit(merge_request.diff_head_sha)
end
MergeRequests::PostMergeService MergeRequests::PostMergeService
.new(merge_request.target_project, @current_user) .new(merge_request.target_project, @current_user)
......
...@@ -654,20 +654,44 @@ describe MergeRequests::RefreshService do ...@@ -654,20 +654,44 @@ describe MergeRequests::RefreshService do
subject { service.execute(oldrev, newrev, 'refs/heads/merge-commit-analyze-before') } subject { service.execute(oldrev, newrev, 'refs/heads/merge-commit-analyze-before') }
it "updates merge requests' merge_commits" do context 'feature enabled' do
expect(Gitlab::BranchPushMergeCommitAnalyzer).to receive(:new).and_wrap_original do |original_method, commits| before do
expect(commits.map(&:id)).to eq(%w{646ece5cfed840eca0a4feb21bcd6a81bb19bda3 29284d9bcc350bcae005872d0be6edd016e2efb5 5f82584f0a907f3b30cfce5bb8df371454a90051 8a994512e8c8f0dfcf22bb16df6e876be7a61036 689600b91aabec706e657e38ea706ece1ee8268f db46a1c5a5e474aa169b6cdb7a522d891bc4c5f9}) stub_feature_flags(branch_push_merge_commit_analyze: true)
end
it "updates merge requests' merge_commits" do
expect(Gitlab::BranchPushMergeCommitAnalyzer).to receive(:new).and_wrap_original do |original_method, commits|
expect(commits.map(&:id)).to eq(%w{646ece5cfed840eca0a4feb21bcd6a81bb19bda3 29284d9bcc350bcae005872d0be6edd016e2efb5 5f82584f0a907f3b30cfce5bb8df371454a90051 8a994512e8c8f0dfcf22bb16df6e876be7a61036 689600b91aabec706e657e38ea706ece1ee8268f db46a1c5a5e474aa169b6cdb7a522d891bc4c5f9})
original_method.call(commits)
end
subject
merge_request.reload
merge_request_side_branch.reload
original_method.call(commits) expect(merge_request.merge_commit.id).to eq('646ece5cfed840eca0a4feb21bcd6a81bb19bda3')
expect(merge_request_side_branch.merge_commit.id).to eq('29284d9bcc350bcae005872d0be6edd016e2efb5')
end end
end
context 'when feature is disabled' do
before do
stub_feature_flags(branch_push_merge_commit_analyze: false)
end
it "does not trigger analysis" do
expect(Gitlab::BranchPushMergeCommitAnalyzer).not_to receive(:new)
subject subject
merge_request.reload merge_request.reload
merge_request_side_branch.reload merge_request_side_branch.reload
expect(merge_request.merge_commit.id).to eq('646ece5cfed840eca0a4feb21bcd6a81bb19bda3') expect(merge_request.merge_commit).to eq(nil)
expect(merge_request_side_branch.merge_commit.id).to eq('29284d9bcc350bcae005872d0be6edd016e2efb5') expect(merge_request_side_branch.merge_commit).to eq(nil)
end
end end
end end
end 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