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

Fix edge case when the version is a pre-release

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/452171

**Problem**

Previous changes https://gitlab.com/gitlab-org/gitlab/-/issues/441804 to
Changelog API logic introduced a bug to the version detection.

Before we allowed to provide any valid semantic version as a `version`
value. But now it rejects versions with pre-release identifier.

**Solution**

Fix the bug and permit versions with a pre-release as a `version`
argument.
上级 ea52cf03
No related branches found
No related tags found
无相关合并请求
...@@ -35,13 +35,18 @@ def execute(new_version) ...@@ -35,13 +35,18 @@ def execute(new_version)
tags = {} tags = {}
# Custom regex matcher extracts versions from repository tags # Custom regex matcher extracts versions from repository tags
# This format is defined by the user and applied to repository tags only
# https://docs.gitlab.com/ee/user/project/changelogs.html#customize-the-tag-format-when-extracting-versions
custom_regex_matcher = matcher(@regex) custom_regex_matcher = matcher(@regex)
if Feature.enabled?(:update_changelog_logic, @project) if Feature.enabled?(:update_changelog_logic, @project)
# Default regex macher extracts the user provided version # Default regex macher extracts the user provided version
# The regex is different here, because it must match API documentation requirements
# https://gitlab.com/gitlab-org/gitlab/-/blob/44ab4e5bccdea01642b2f42bcccef706409ebfec/doc/api/repositories.md#L338
default_regex_matcher = matcher(Gitlab::Changelog::Config::DEFAULT_TAG_REGEX) default_regex_matcher = matcher(Gitlab::Changelog::Config::DEFAULT_TAG_REGEX)
requested_version = extract_version(new_version, default_regex_matcher) version_components = default_regex_matcher.match(new_version)
requested_version = assemble_version(version_components)
unless requested_version unless requested_version
raise Gitlab::Changelog::Error, raise Gitlab::Changelog::Error,
...@@ -54,7 +59,16 @@ def execute(new_version) ...@@ -54,7 +59,16 @@ def execute(new_version)
versions = [requested_version] versions = [requested_version]
@project.repository.tags.each do |tag| @project.repository.tags.each do |tag|
version = extract_version(tag.name, custom_regex_matcher) version_components = custom_regex_matcher.match(tag.name)
next unless version_components
# When using this class for generating changelog data for a range of
# commits, we want to compare against the tag of the last _stable_
# release; not some random RC that came after that
next if version_components[:pre]
version = assemble_version(version_components)
next unless version next unless version
...@@ -84,15 +98,9 @@ def matcher(regex) ...@@ -84,15 +98,9 @@ def matcher(regex)
) )
end end
def extract_version(string, version_matcher) # Builds a version string based on regex matcher's output
matches = version_matcher.match(string) def assemble_version(matches)
return if matches.blank?
return unless matches
# When using this class for generating changelog data for a range of
# commits, we want to compare against the tag of the last _stable_
# release; not some random RC that came after that.
return if matches[:pre]
major = matches[:major] major = matches[:major]
minor = matches[:minor] minor = matches[:minor]
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
expect(finder.execute('0.9.0')).to eq(tag6) expect(finder.execute('0.9.0')).to eq(tag6)
expect(finder.execute('0.6.0')).to eq(tag7) expect(finder.execute('0.6.0')).to eq(tag7)
# with a pre-release version
expect(finder.execute('0.6.0-rc1')).to eq(tag7)
# with v at the beginning # with v at the beginning
expect(finder.execute('v2.1.0')).to eq(tag3) expect(finder.execute('v2.1.0')).to eq(tag3)
expect { finder.execute('wrong_version') }.to raise_error(Gitlab::Changelog::Error) expect { finder.execute('wrong_version') }.to raise_error(Gitlab::Changelog::Error)
...@@ -70,6 +73,9 @@ ...@@ -70,6 +73,9 @@
expect(finder.execute('0.9.0')).to eq(tag6) expect(finder.execute('0.9.0')).to eq(tag6)
expect(finder.execute('0.6.0')).to eq(tag7) expect(finder.execute('0.6.0')).to eq(tag7)
# with a pre-release version
expect(finder.execute('0.6.0-rc1')).to eq(tag7)
# with v at the beginning # with v at the beginning
expect(finder.execute('v2.1.0')).to eq(nil) expect(finder.execute('v2.1.0')).to eq(nil)
expect(finder.execute('wrong_version')).to eq(nil) expect(finder.execute('wrong_version')).to eq(nil)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册