Commit ffef261a authored by Yorick Peterse's avatar Yorick Peterse

Relax tag requirements when generating changelogs

When generating a changelog and leaving out the `from` parameter, we no
longer require that the names of tags start with a "v". Instead, tags
can now be in the format `X.Y.Z` or `vX.Y.Z`.

This fixes https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1572
parent 981ba891
......@@ -16,12 +16,13 @@ module Repositories
# This finder expects that all tags to consider meet the following
# requirements:
#
# * They start with the letter "v"
# * They use semantic versioning for the tag format
# * They start with the letter "v" followed by a version, or immediately start
# with a version
# * They use semantic versioning for the version format
#
# Tags not meeting these requirements are ignored.
class PreviousTagFinder
TAG_REGEX = /\Av(?<version>#{Gitlab::Regex.unbounded_semver_regex})\z/.freeze
TAG_REGEX = /\Av?(?<version>#{Gitlab::Regex.unbounded_semver_regex})\z/.freeze
def initialize(project)
@project = project
......
---
title: Relax tag requirements when generating changelogs
merge_request: 54832
author:
type: changed
......@@ -285,8 +285,8 @@ Example response:
Generate changelog data based on commits in a repository.
Given a version (using semantic versioning) and a range of commits,
GitLab generates a changelog for all commits that use a particular
Given a version (using [semantic versioning](https://semver.org/)) and a range
of commits, GitLab generates a changelog for all commits that use a particular
[Git trailer](https://git-scm.com/docs/git-interpret-trailers).
The output of this process is a new section in a changelog file in the Git
......@@ -312,15 +312,15 @@ Supported attributes:
If the `from` attribute is unspecified, GitLab uses the Git tag of the last
version that came before the version specified in the `version` attribute. For
this to work, your project must create Git tags for versions using the
following format:
this to work, your project must create Git tags for versions using one of the
following formats:
```plaintext
vX.Y.Z
```
- `vX.Y.Z`
- `X.Y.Z`
Where `X.Y.Z` is a version that follows semantic versioning. For example,
consider a project with the following tags:
Where `X.Y.Z` is a version that follows [semantic
versioning](https://semver.org/). For example, consider a project with the
following tags:
- v1.0.0
- v1.1.0
......
......@@ -12,16 +12,19 @@ RSpec.describe Repositories::PreviousTagFinder do
tag1 = double(:tag1, name: 'v1.0.0')
tag2 = double(:tag2, name: 'v1.1.0')
tag3 = double(:tag3, name: 'v2.0.0')
tag4 = double(:tag4, name: '1.0.0')
tag4 = double(:tag4, name: '0.9.0')
tag5 = double(:tag4, name: 'v0.8.0-pre1')
allow(project.repository)
.to receive(:tags)
.and_return([tag1, tag3, tag2, tag4])
.and_return([tag1, tag3, tag2, tag4, tag5])
expect(finder.execute('2.1.0')).to eq(tag3)
expect(finder.execute('2.0.0')).to eq(tag2)
expect(finder.execute('1.5.0')).to eq(tag2)
expect(finder.execute('1.0.1')).to eq(tag1)
expect(finder.execute('1.0.0')).to eq(tag4)
expect(finder.execute('0.9.0')).to eq(tag5)
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