Use head tree (cached) for file search. Also add some tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
3b1543cd15
commit
b105b84e3a
2 changed files with 28 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue