Read about our upcoming Code of Conduct on this issue

Commit b55145c8 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Introducing GitLabVersion class

In the forthcoming improvements, we will have more callers for
the stable branch name etc.
parent 27bd5e9e99cd
# Copyright 2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
from ..version import (
GitLabVersion,
)
def test_gitlab_version():
version = GitLabVersion(14, 1, 7)
assert str(version) == '14.1.7'
assert repr(version) == 'GitLabVersion(14, 1, 7)'
assert version.git_stable_branch == '14-1-stable'
assert version.gitlab_rails_tag == 'v14.1.7'
......@@ -29,3 +29,54 @@
if len(split) != 2:
raise TypeError("Invalid level 2 version string: %r" % s)
return int(split[0]), int(split[1])
class GitLabVersion:
"""Return names relevant Git revisions for given version tuple.
These are
- tag of GitLab Rails
- stable branch of GitLab Rails
- tag of Omnibus GitLab
- the plain version string is added as convenience
"""
def __init__(self, major, minor, patch):
self.version_tuple = (major, minor, patch)
def __str__(self):
return '.'.join(str(i) for i in self.version_tuple)
def __repr__(self):
return '%s%r' % (self.__class__.__name__, self.version_tuple)
@property
def git_stable_branch(self):
"""Name of the Git stable branch for this version.
Applicable to GitLab Rails as well as Omnibus GitLab
"""
return '%d-%d-stable' % self.version_tuple[:2]
@property
def gitlab_rails_tag(self):
return 'v' + str(self)
def __lt__(self, other):
return self.version_tuple < other.version_tuple
def __le__(self, other):
return self.version_tuple <= other.version_tuple
def __gt__(self, other):
return self.version_tuple > other.version_tuple
def __ge__(self, other):
return self.version_tuple >= other.version_tuple
def __eq__(self, other):
return self.version_tuple == other.version_tuple
def __hash__(self):
return hash(self.version_tuple)
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