Commit b105b84e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use head tree (cached) for file search. Also add some tests

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 3b1543cd
No related merge requests found
......@@ -468,7 +468,11 @@ class Repository
end
def gitlab_ci_yml
@gitlab_ci_yml ||= blob_at(head_commit.sha, '.gitlab-ci.yml') unless empty?
return nil if empty?
@gitlab_ci_yml ||= tree(:head).blobs.find do |file|
file.name == '.gitlab-ci.yml'
end
end
def head_commit
......
......@@ -148,6 +148,29 @@ describe Repository, models: true do
end
end
describe "#gitlab_ci_yml" do
before do
TestBlob = Struct.new(:name)
end
it 'returns valid file' do
files = [TestBlob.new('file'), TestBlob.new('.gitlab-ci.yml'), TestBlob.new('copying')]
expect(repository.tree).to receive(:blobs).and_return(files)
expect(repository.gitlab_ci_yml.name).to eq('.gitlab-ci.yml')
end
it 'returns nil if not exists' do
expect(repository.tree).to receive(:blobs).and_return([])
expect(repository.gitlab_ci_yml).to be_nil
end
it 'returns nil for empty repository' do
expect(repository).to receive(:empty?).and_return(true)
expect(repository.gitlab_ci_yml).to be_nil
end
end
describe :add_branch do
context 'when pre hooks were successful' do
it 'should run without errors' do
......
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