Commit 6ab094ba authored by Chad Woolley's avatar Chad Woolley Committed by Mayra Cabrera

Remove usage of constant

Unnecessary usage of constants is a documented antipattern.  See
https://bit.ly/30eeD8R
parent cd6219aa
......@@ -58,7 +58,7 @@ module StaticSiteEditor
def load_generated_config
Gitlab::StaticSiteEditor::Config::GeneratedConfig.new(
project.repository,
repository,
ref,
params.fetch(:path),
params[:return_url]
......@@ -75,7 +75,7 @@ module StaticSiteEditor
end
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
# 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.
......
......@@ -4,8 +4,6 @@ module Gitlab
module StaticSiteEditor
module Config
class GeneratedConfig
SUPPORTED_EXTENSIONS = %w[.md].freeze
def initialize(repository, ref, path, return_url)
@repository = repository
@ref = ref
......@@ -35,8 +33,12 @@ module Gitlab
delegate :project, to: :repository
def supported_extensions
%w[.md].freeze
end
def commit_id
repository.commit(ref)&.id if ref
repository.commit(ref)&.id
end
def supported_content?
......@@ -50,7 +52,7 @@ module Gitlab
def extension_supported?
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
def file_exists?
......
......@@ -132,5 +132,11 @@ RSpec.describe Gitlab::StaticSiteEditor::Config::GeneratedConfig do
it { is_expected.to include(return_url: nil) }
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
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