Skip to content
代码片段 群组 项目
未验证 提交 49f9d241 编辑于 作者: Joe Woodward's avatar Joe Woodward 提交者: GitLab
浏览文件

Merge branch 'fix/471717-empty-changelog-config-yaml' into 'master'

Prevent 500 errors when evaluating empty changelog configs

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/166610



Merged-by: default avatarJoe Woodward <jwoodward@gitlab.com>
Approved-by: default avatarNaman Jagdish Gala <ngala@gitlab.com>
Approved-by: default avatarEugie Limpin <elimpin@gitlab.com>
Co-authored-by: default avatarJoe Woodward <j@joewoodward.me>
No related branches found
No related tags found
无相关合并请求
......@@ -38,17 +38,13 @@ class Config
def self.from_git(project, user = nil, path = nil)
config_path = path.presence || DEFAULT_FILE_PATH
yaml = project.repository.changelog_config('HEAD', config_path)
config_yaml = project.repository.changelog_config('HEAD', config_path)
config_hash = YAML.safe_load(config_yaml) if config_yaml.present?
return new(project) if config_hash.nil?
if yaml.present?
begin
from_hash(project, YAML.safe_load(yaml), user)
rescue Psych::Exception
raise Error, "#{config_path} does not contain valid YAML"
end
else
new(project)
end
from_hash(project, config_hash, user)
rescue Psych::Exception
raise Error, "#{config_path} does not contain valid YAML"
end
def self.from_hash(project, hash, user = nil)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Changelog::Config do
RSpec.describe Gitlab::Changelog::Config, feature_category: :source_code_management do
include ProjectForksHelper
let(:project) { build_stubbed(:project) }
......@@ -57,17 +57,34 @@
end
end
context 'when changelog is empty' do
it 'returns the default configuration' do
allow(project.repository)
.to receive(:changelog_config)
.and_return("")
context 'when changelog config is empty' do
subject(:from_git) { described_class.from_git(project) }
shared_examples 'all attributes match the default config' do
let(:default_config) { described_class.new(project) }
let(:attributes) { %i[date_format categories template tag_regex always_credit_user_ids] }
it 'does not modify any attributes from the default config' do
attributes.each do |attribute|
expect(from_git.public_send(attribute)).to eql(default_config.public_send(attribute))
end
end
end
before do
allow(project.repository).to receive(:changelog_config).and_return(changelog_config_content)
end
context 'when changelog config does not contain a header' do
let(:changelog_config_content) { "" }
it_behaves_like 'all attributes match the default config'
end
expect(described_class)
.to receive(:new)
.with(project)
context 'when changelog config contains a header' do
let(:changelog_config_content) { "---\n\n" }
described_class.from_git(project)
it_behaves_like 'all attributes match the default config'
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册