Commit a1d4bec0 authored by Furkan Ayhan's avatar Furkan Ayhan

Merge branch 'aw-log-grpc-invalid-argument-in-ci-config-resolver' into 'master'

Track SHA values that raise exceptions in CI lint

See merge request gitlab-org/gitlab!81174
parents adf0163f fdf7bc7a
...@@ -38,6 +38,8 @@ module Resolvers ...@@ -38,6 +38,8 @@ module Resolvers
.validate(content, dry_run: dry_run) .validate(content, dry_run: dry_run)
response(result).merge(merged_yaml: result.merged_yaml) response(result).merge(merged_yaml: result.merged_yaml)
rescue GRPC::InvalidArgument => error
Gitlab::ErrorTracking.track_and_raise_exception(error, sha: sha)
end end
private private
......
...@@ -6,16 +6,24 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -6,16 +6,24 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
include GraphqlHelpers include GraphqlHelpers
describe '#resolve' do describe '#resolve' do
before do let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let_it_be(:sha) { nil }
let_it_be(:content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
end
let(:ci_lint) do
ci_lint_double = instance_double(::Gitlab::Ci::Lint) ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_return(fake_result) allow(ci_lint_double).to receive(:validate).and_return(fake_result)
allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint_double) ci_lint_double
end end
let_it_be(:user) { create(:user) } before do
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint)
let_it_be(:sha) { nil } end
subject(:response) do subject(:response) do
resolve(described_class, resolve(described_class,
...@@ -33,10 +41,6 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -33,10 +41,6 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
) )
end end
let_it_be(:content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
end
it 'lints the ci config file and returns the merged yaml file' do it 'lints the ci config file and returns the merged yaml file' do
expect(response[:status]).to eq(:valid) expect(response[:status]).to eq(:valid)
expect(response[:merged_yaml]).to eq(content) expect(response[:merged_yaml]).to eq(content)
...@@ -74,5 +78,23 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -74,5 +78,23 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
expect(response[:errors]).to eq(['Invalid configuration format']) expect(response[:errors]).to eq(['Invalid configuration format'])
end end
end end
context 'with an invalid SHA' do
let_it_be(:sha) { ':' }
let(:ci_lint) do
ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_raise(GRPC::InvalidArgument)
ci_lint_double
end
it 'logs the invalid SHA to Sentry' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception)
.with(GRPC::InvalidArgument, sha: ':')
response
end
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