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

Merge branch '452171_fix_changelog_version_for_preleases' into 'master'

Fix edge case when the version is a pre-release

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



Merged-by: default avatarTiger Watson <twatson@gitlab.com>
Approved-by: default avatarMadelein van Niekerk <mvanniekerk@gitlab.com>
Approved-by: default avatarTiger Watson <twatson@gitlab.com>
Co-authored-by: default avatarVasilii Iakliushin <viakliushin@gitlab.com>
No related branches found
No related tags found
加载中
......@@ -35,13 +35,18 @@ def execute(new_version)
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)
if Feature.enabled?(:update_changelog_logic, @project)
# 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)
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
raise Gitlab::Changelog::Error,
......@@ -54,7 +59,16 @@ def execute(new_version)
versions = [requested_version]
@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
......@@ -84,15 +98,9 @@ def matcher(regex)
)
end
def extract_version(string, version_matcher)
matches = version_matcher.match(string)
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]
# Builds a version string based on regex matcher's output
def assemble_version(matches)
return if matches.blank?
major = matches[:major]
minor = matches[:minor]
......
......@@ -39,6 +39,9 @@
expect(finder.execute('0.9.0')).to eq(tag6)
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
expect(finder.execute('v2.1.0')).to eq(tag3)
expect { finder.execute('wrong_version') }.to raise_error(Gitlab::Changelog::Error)
......@@ -70,6 +73,9 @@
expect(finder.execute('0.9.0')).to eq(tag6)
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
expect(finder.execute('v2.1.0')).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.
先完成此消息的编辑!
想要评论请 注册