Skip to content
Snippets Groups Projects
Verified Commit 58842041 authored by Marc Shaw's avatar Marc Shaw :two: Committed by GitLab
Browse files

Do not run a pipeline when pushing a branch deletion

MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/170893
parent 84196305
No related branches found
No related tags found
2 merge requests!171309Draft: Fetch issues / MRs / epics count in the sidebar with GraphQL,!170893Resolve "Pipelines are triggered on branch delete"
......@@ -51,8 +51,13 @@ def create_events
EventCreateService.new.push(project, current_user, event_push_data)
end
def removing_ref?
Gitlab::Git.blank_ref?(newrev)
end
def create_pipelines
return unless params.fetch(:create_pipelines, true)
return if removing_ref?
response = Ci::CreatePipelineService
.new(project, current_user, pipeline_params)
......
......@@ -18,6 +18,8 @@ def execute
private
alias_method :removing_branch?, :removing_ref?
def hook_name
:push_hooks
end
......@@ -225,10 +227,6 @@ def updating_branch?
!creating_branch? && !removing_branch?
end
def removing_branch?
Gitlab::Git.blank_ref?(newrev)
end
def creating_default_branch?
creating_branch? && default_branch?
end
......
......@@ -4,6 +4,8 @@ module Git
class TagHooksService < ::Git::BaseHooksService
private
alias_method :removing_tag?, :removing_ref?
def hook_name
:tag_push_hooks
end
......@@ -22,7 +24,7 @@ def event_message
def tag
strong_memoize(:tag) do
next if Gitlab::Git.blank_ref?(newrev)
next if removing_tag?
tag_name = Gitlab::Git.ref_name(ref)
tag = project.repository.find_tag(tag_name)
......
......@@ -28,16 +28,6 @@
allow(project.repository).to receive(:commit).with("master").and_return(nil)
end
context 'deleted branch' do
let(:newrev) { blankrev }
it 'handles when remote branch exists' do
expect(project.repository).to receive(:commit).with("refs/remotes/upstream/master").and_return(sample_commit)
subject.execute
end
end
context 'ElasticSearch indexing', :elastic, :clean_gitlab_redis_shared_state, feature_category: :global_search do
before do
stub_ee_application_setting(elasticsearch_indexing?: true)
......
......@@ -290,6 +290,17 @@ def commits_count
expect(subject.execute[:status]).to eq(:success)
end
context 'when the newrev is blank' do
let(:newrev) { Gitlab::Git::SHA1_BLANK_SHA }
it 'does not create a pipeline and returns success' do
expect(Ci::CreatePipelineService)
.not_to receive(:new)
expect(subject.execute[:status]).to eq(:success)
end
end
end
context "and there are errors" do
......
......@@ -128,7 +128,8 @@ def multiple_changes(change, count)
it 'creates pipeline for branches and tags' do
subject.execute
expect(Ci::Pipeline.pluck(:ref)).to contain_exactly('create', 'update', 'delete')
# We don't run a pipeline for a deletion
expect(Ci::Pipeline.pluck(:ref)).to contain_exactly('create', 'update')
end
it "creates exactly #{described_class::PIPELINE_PROCESS_LIMIT} pipelines" do
......@@ -150,7 +151,8 @@ def multiple_changes(change, count)
end
it 'creates all pipelines' do
expect { subject.execute }.to change { Ci::Pipeline.count }.by(changes.count)
# We don't run a pipeline for a deletion
expect { subject.execute }.to change { Ci::Pipeline.count }.by(changes.count - 1)
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment