Read about our upcoming Code of Conduct on this issue

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

fetch_watch_tags: loop over new versions in main function

This is because we want to add more actions than just creating
an issue for each version, and the resulting issue will depend
on these actions.
parent 738443bb4391
......@@ -103,10 +103,9 @@
return tokenf.read().strip()
def create_issues(versions, server, token, project, simulate=True):
for version in versions:
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
project.replace('/', '%2F'),
'issues'))
def create_issue(version, server, token, project, simulate=True):
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
project.replace('/', '%2F'),
'issues'))
......@@ -112,10 +111,10 @@
description = ISSUE_TEMPLATE.format(
git_branch=version.git_stable_branch,
tag=version.gitlab_rails_tag,
)
post_data = dict(
description=description,
title="GitLab %s" % version,
)
description = ISSUE_TEMPLATE.format(
git_branch=version.git_stable_branch,
tag=version.gitlab_rails_tag,
)
post_data = dict(
description=description,
title="GitLab %s" % version,
)
......@@ -121,6 +120,6 @@
if simulate:
print("Simulate mode: would POST %r, data=%r" % (url,
post_data))
continue
if simulate:
print("Simulate mode: would POST %r, data=%r" % (url,
post_data))
return
......@@ -126,5 +125,5 @@
resp = requests.post(url,
headers={'Private-Token': token},
data=post_data)
resp = requests.post(url,
headers={'Private-Token': token},
data=post_data)
......@@ -130,12 +129,12 @@
as_json = resp.json()
if resp.status_code < 400:
print("Issue %d created. Details: %r" % (as_json['iid'],
as_json))
else:
print("Error %d creating issue. Details: %r" % (
resp.status_code, as_json))
return 2
as_json = resp.json()
if resp.status_code < 400:
print("Issue %d created. Details: %r" % (as_json['iid'],
as_json))
else:
print("Error %d creating issue. Details: %r" % (
resp.status_code, as_json))
return 2
def main():
......@@ -204,4 +203,5 @@
token = read_token_file(cl_args.heptapod_token)
error_codes = []
if cl_args.create_issues:
......@@ -207,5 +207,7 @@
if cl_args.create_issues:
return create_issues(versions=new_versions,
for version in new_versions:
error_codes.append(
create_issue(version=version,
server=cl_args.heptapod_server,
token=token,
project=cl_args.heptapod_project,
......@@ -209,4 +211,7 @@
server=cl_args.heptapod_server,
token=token,
project=cl_args.heptapod_project,
simulate=simulate)
simulate=simulate))
if any(code for code in error_codes):
return 2
......@@ -7,7 +7,7 @@
import requests
from ..fetch_watch_tags import (
create_issues,
create_issue,
read_token_file,
)
from ..version import GitLabVersion
......@@ -30,7 +30,7 @@
assert read_token_file(token_path) == 'siCr3t'
def test_create_issues(monkeypatch):
def test_create_issue(monkeypatch):
records = []
def intercept_post(*a, **kw):
......@@ -38,8 +38,8 @@
return FakeResponse(code=200, data=dict(iid=123))
monkeypatch.setattr(requests, 'post', intercept_post)
create_args = ([GitLabVersion(14, 1, 5)],
create_args = (GitLabVersion(14, 1, 5),
'https://heptapod.example',
'siCr3t',
'heptapod/heptapod')
......@@ -42,8 +42,8 @@
'https://heptapod.example',
'siCr3t',
'heptapod/heptapod')
create_issues(*create_args, simulate=False)
create_issue(*create_args, simulate=False)
req_args, req_kwargs = records.pop()
assert (
......@@ -57,6 +57,6 @@
assert '--branch-prefix 14-1-stable' in description
# doesn't fail in simulation mode
create_issues(*create_args, simulate=True)
create_issue(*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