Commit 16b40461 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'sse-config-refactor-grpc-calls' into 'master'

Optimize and refactor ConfigService and GeneratedConfig

See merge request gitlab-org/gitlab!43480
parents 8be28faf 6ab094ba
...@@ -58,7 +58,7 @@ module StaticSiteEditor ...@@ -58,7 +58,7 @@ module StaticSiteEditor
def load_generated_config def load_generated_config
Gitlab::StaticSiteEditor::Config::GeneratedConfig.new( Gitlab::StaticSiteEditor::Config::GeneratedConfig.new(
project.repository, repository,
ref, ref,
params.fetch(:path), params.fetch(:path),
params[:return_url] params[:return_url]
...@@ -75,7 +75,7 @@ module StaticSiteEditor ...@@ -75,7 +75,7 @@ module StaticSiteEditor
end end
def yaml_from_repo def yaml_from_repo
project.repository.blob_data_at(ref, static_site_editor_config_file) repository.blob_data_at(ref, static_site_editor_config_file)
rescue GRPC::NotFound rescue GRPC::NotFound
# Return nil in the case of a GRPC::NotFound exception, so the default config will be used. # Return nil in the case of a GRPC::NotFound exception, so the default config will be used.
# Allow any other unexpected exception will be tracked and re-raised. # Allow any other unexpected exception will be tracked and re-raised.
......
...@@ -4,8 +4,6 @@ module Gitlab ...@@ -4,8 +4,6 @@ module Gitlab
module StaticSiteEditor module StaticSiteEditor
module Config module Config
class GeneratedConfig class GeneratedConfig
SUPPORTED_EXTENSIONS = %w[.md].freeze
def initialize(repository, ref, path, return_url) def initialize(repository, ref, path, return_url)
@repository = repository @repository = repository
@ref = ref @ref = ref
...@@ -35,8 +33,12 @@ module Gitlab ...@@ -35,8 +33,12 @@ module Gitlab
delegate :project, to: :repository delegate :project, to: :repository
def supported_extensions
%w[.md].freeze
end
def commit_id def commit_id
repository.commit(ref)&.id if ref repository.commit(ref)&.id
end end
def supported_content? def supported_content?
...@@ -50,7 +52,7 @@ module Gitlab ...@@ -50,7 +52,7 @@ module Gitlab
def extension_supported? def extension_supported?
return true if path.end_with?('.md.erb') && Feature.enabled?(:sse_erb_support, project) return true if path.end_with?('.md.erb') && Feature.enabled?(:sse_erb_support, project)
SUPPORTED_EXTENSIONS.any? { |ext| path.end_with?(ext) } supported_extensions.any? { |ext| path.end_with?(ext) }
end end
def file_exists? def file_exists?
......
...@@ -132,5 +132,11 @@ RSpec.describe Gitlab::StaticSiteEditor::Config::GeneratedConfig do ...@@ -132,5 +132,11 @@ RSpec.describe Gitlab::StaticSiteEditor::Config::GeneratedConfig do
it { is_expected.to include(return_url: nil) } it { is_expected.to include(return_url: nil) }
end end
context 'when a commit for the ref cannot be found' do
let(:ref) { 'nonexistent-ref' }
it { is_expected.to include(commit_id: nil) }
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