Read about our upcoming Code of Conduct on this issue

Commit 5323e170 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

fetch_watch_tags: using the new GitLabVersion class

This means in particular that `filter_new_versions` has to be
adapted to work on `GitLabVersion` instances.
parent b55145c8647c
......@@ -11,7 +11,10 @@
import requests
from subprocess import Popen, PIPE
from .version import level2_version
from .version import (
level2_version,
GitLabVersion,
)
# Regular expression for a new version tag on the remote.
# The required whitespace after the last number excludes rc releases
......@@ -65,8 +68,12 @@
>>> filter_new_versions([])
()
>>> filter_new_versions([(13, 7, 2), (13, 9, 3)])
[(13, 9, 3)]
>>> filter_new_versions([(13, 7, 2), (13, 7, 3), (13, 5, 4),
... (13, 9, 3), (13, 9, 4)],
>>> filter_new_versions([GitLabVersion(13, 7, 2),
... GitLabVersion(13, 9, 3)])
[GitLabVersion(13, 9, 3)]
>>> filter_new_versions([GitLabVersion(13, 7, 2),
... GitLabVersion(13, 7, 3),
... GitLabVersion(13, 9, 3),
... GitLabVersion(13, 9, 4),
... ],
... series=((13, 7), (13, 9)))
......@@ -72,5 +79,7 @@
... series=((13, 7), (13, 9)))
[(13, 7, 3), (13, 9, 4)]
>>> filter_new_versions([(13, 1, 4),
... (13, 9, 3), (13, 9, 5)],
[GitLabVersion(13, 7, 3), GitLabVersion(13, 9, 4)]
>>> filter_new_versions([GitLabVersion(13, 1, 4),
... GitLabVersion(13, 9, 3),
... GitLabVersion(13, 9, 5),
... ],
... series=((13, 7), (13, 9)))
......@@ -76,5 +85,5 @@
... series=((13, 7), (13, 9)))
[(13, 9, 5)]
[GitLabVersion(13, 9, 5)]
"""
if not new_versions:
return ()
......@@ -82,7 +91,7 @@
if series is None:
return [max(v for v in new_versions)]
by_series = [[v for v in new_versions if v[:2] == ser]
by_series = [[v for v in new_versions if v.version_tuple[:2] == ser]
for ser in series]
return sorted(max(versions) for versions in by_series if versions)
......@@ -92,10 +101,9 @@
token = tokenf.read().strip()
for version in versions:
version_str = '.'.join(str(i) for i in version)
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
project.replace('/', '%2F'),
'issues'))
description = ISSUE_TEMPLATE.format(
......@@ -96,11 +104,11 @@
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
project.replace('/', '%2F'),
'issues'))
description = ISSUE_TEMPLATE.format(
git_branch='%d-%d-stable' % version[:2],
tag='v' + version_str,
git_branch=version.git_stable_branch,
tag=version.gitlab_rails_tag,
)
post_data = dict(
description=description,
......@@ -104,7 +112,7 @@
)
post_data = dict(
description=description,
title="GitLab " + version_str
title="GitLab %s" % version,
)
if simulate:
......@@ -169,10 +177,10 @@
line = line.strip().decode('ascii', 'ignore')
m = NEW_TAG_RX.search(line)
if m is not None:
new_versions.append((int(m.group(1)),
int(m.group(2)),
int(m.group(3)),
))
new_versions.append(GitLabVersion(int(m.group(1)),
int(m.group(2)),
int(m.group(3)),
))
if new_versions:
print("Releases to consider in new tags: %r" % new_versions)
......
# 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
import requests
from ..fetch_watch_tags import (
create_issues,
)
from ..version import GitLabVersion
class FakeResponse:
def __init__(self, code, data):
self.status_code = code
self.data = data
def json(self):
return self.data
def test_create_issues(monkeypatch, tmpdir):
records = []
def intercept_post(*a, **kw):
records.append((a, kw))
return FakeResponse(code=200, data=dict(iid=123))
token_path = tmpdir / 'heptapod.token'
token_path.write('siCr3t')
monkeypatch.setattr(requests, 'post', intercept_post)
create_args = ([GitLabVersion(14, 1, 5)],
'https://heptapod.example',
str(token_path),
'heptapod/heptapod')
create_issues(*create_args, simulate=False)
req_args, req_kwargs = records.pop()
assert (
req_args[0] ==
'https://heptapod.example/api/v4/projects/heptapod%2Fheptapod/issues'
)
assert req_kwargs['headers'] == {'Private-Token': 'siCr3t'}
req_data = req_kwargs['data']
assert req_data['title'] == 'GitLab 14.1.5'
description = req_data['description']
assert '--branch-prefix 14-1-stable' in description
# doesn't fail in simulation mode
create_issues(*create_args, simulate=True)
# and doesn't post anything
assert len(records) == 0
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