Commit 673971c8 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '6717_add_security_reports_logic-ce' into 'master'

Add pipeline.default_branch? mehod

See merge request gitlab-org/gitlab-ce!22102
parents 2243e4d4 8661a35e
...@@ -627,6 +627,10 @@ module Ci ...@@ -627,6 +627,10 @@ module Ci
end end
end end
def default_branch?
ref == project.default_branch
end
private private
def ci_yaml_from_repo def ci_yaml_from_repo
......
...@@ -1968,4 +1968,34 @@ describe Ci::Pipeline, :mailer do ...@@ -1968,4 +1968,34 @@ describe Ci::Pipeline, :mailer do
end end
end end
end end
describe '#default_branch?' do
let(:default_branch) { 'master'}
subject { pipeline.default_branch? }
before do
allow(project).to receive(:default_branch).and_return(default_branch)
end
context 'when pipeline ref is the default branch of the project' do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, ref: default_branch)
end
it "returns true" do
expect(subject).to be_truthy
end
end
context 'when pipeline ref is not the default branch of the project' do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, ref: 'another_branch')
end
it "returns false" do
expect(subject).to be_falsey
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