Read about our upcoming Code of Conduct on this issue

Commit 05fe5793 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

upstream_branch: new helper module

This is extracted from the `convert` module, with a change
of semantics: returning `None` if the branch name doesn't match
the conventions. With this, it is more self-contained and can
be used for filtering purposes.
parent 22029ff22567
......@@ -14,30 +14,9 @@
from .version import (
level2_version,
)
STABLE_BRANCH_SUFFIX = '-stable'
def extract_stable_branch_version(brname):
"""Extract the GitLab version from a stable branch name.
:returns: a tuple of integers.
Examples::
>>> extract_stable_branch_version('13-7-stable')
(13, 7)
Version tuples different from 2 are supported, underlining that
even if it does not happen in practice::
>>> extract_stable_branch_version('13-10-5-stable')
(13, 10, 5)
>>> extract_stable_branch_version('14-stable')
(14,)
"""
return tuple(int(segment)
for segment in brname[:-len(STABLE_BRANCH_SUFFIX)].split('-'))
from .upstream_branch import (
extract_stable_branch_version
)
def is_branch_to_pull(cl_args, branch_name):
......@@ -41,5 +20,6 @@
def is_branch_to_pull(cl_args, branch_name):
if not branch_name.endswith(STABLE_BRANCH_SUFFIX):
gl_version = extract_stable_branch_version(branch_name)
if gl_version is None:
return False
......@@ -45,3 +25,4 @@
return False
min_version = cl_args.min_gitlab_version
if min_version is not None:
......@@ -46,6 +27,5 @@
min_version = cl_args.min_gitlab_version
if min_version is not None:
gl_version = extract_stable_branch_version(branch_name)
return gl_version >= min_version
prefix = cl_args.branch_prefix
......
# Copyright 2020-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
"""Utilities for upstream GitLab branch conventions."""
import re
STABLE_BRANCH_RX = re.compile(r'(\d+)-(\d+)-stable$')
def extract_stable_branch_version(brname):
"""Extract the GitLab version from a stable branch name.
:returns: a tuple of integers, or `None` if the branch name does not
match the convention for upstream stable branches
Examples::
>>> extract_stable_branch_version('13-7-stable')
(13, 7)
>>> extract_stable_branch_version('13-8-other') is None
True
Version tuples different from 2 are not supported:
>>> extract_stable_branch_version('13-10-5-stable') is None
True
>>> extract_stable_branch_version('14-stable') is None
True
"""
m = STABLE_BRANCH_RX.match(brname)
if m is None:
return None
return int(m.group(1)), int(m.group(2))
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