Commit 32fe7986 authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Furkan Ayhan

Fix error from invalid sha for `include` files

`External::File::Local` uses the sha from the context when fetching
local include files. If that sha is not valid, an exception is raised by
Gitaly.

This commit fixes that error by catching the Gitaly exception and
returning an appropriate error.

Changelog: fixed
parent 7577206c
......@@ -33,6 +33,10 @@ module Gitlab
def fetch_local_content
context.project.repository.blob_data_at(context.sha, location)
rescue GRPC::InvalidArgument
errors.push("Sha #{context.sha} is not valid!")
nil
end
override :expand_context_attrs
......
......@@ -81,6 +81,16 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local do
expect(local_file.valid?).to be_falsy
end
end
context 'when the given sha is not valid' do
let(:location) { '/lib/gitlab/ci/templates/existent-file.yml' }
let(:sha) { ':' }
it 'returns false and adds an error message stating that included file does not exist' do
expect(local_file).not_to be_valid
expect(local_file.errors).to include("Sha #{sha} is not valid!")
end
end
end
describe '#content' 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