Read about our upcoming Code of Conduct on this issue

Commit 09748e9c authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

convert-local: new --min-gitlab-version option

This should be often nicer than `--branch-prefix`. Did not bother
to make both of them really compatible and deal with resulting
corner cases, that's why they are mutually exclusive.
parent 045bc68c6edc
Pipeline #20077 passed with stage
in 38 seconds
......@@ -11,7 +11,11 @@
from subprocess import Popen, PIPE, check_call, check_output
from .version import (
level2_version,
)
STABLE_BRANCH_SUFFIX = '-stable'
def extract_stable_branch_version(brname):
......@@ -14,7 +18,24 @@
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('-'))
......@@ -22,6 +43,11 @@
def is_branch_to_pull(cl_args, branch_name):
if not branch_name.endswith(STABLE_BRANCH_SUFFIX):
return False
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
if prefix is not None:
return branch_name.startswith(prefix)
......@@ -36,8 +62,9 @@
"directory",
epilog=""
"Examples: `{self} gitlab-ce heptapod-rails` (the default)\n"
" `{self} --min-gitlab-version 13.7\n"
" `{self} --branch-prefix 13-9-stable`".format(
self=sys.argv[0])
)
parser.add_argument("--heptapod-repo", default='heptapod-rails')
parser.add_argument("--gitlab-repo", default='gitlab-ce')
......@@ -39,10 +66,15 @@
" `{self} --branch-prefix 13-9-stable`".format(
self=sys.argv[0])
)
parser.add_argument("--heptapod-repo", default='heptapod-rails')
parser.add_argument("--gitlab-repo", default='gitlab-ce')
parser.add_argument("--branch-prefix")
parser.add_argument("--min-gitlab-version", default=(13, 9))
filt_group = parser.add_mutually_exclusive_group()
filt_group.add_argument("--branch-prefix",
help="Prefix of upstream Git branches to "
"consider. In many cases, --min-gitlab-version "
"is more interesting.")
filt_group.add_argument("--min-gitlab-version", type=level2_version,
help="Minimum GitLab version to consider")
cl_args = parser.parse_args()
......
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