Read about our upcoming Code of Conduct on this issue

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

fetch-watch-tags: split out issue creating function

will make it easier to expand
parent 2813a34be1d5
......@@ -50,6 +50,44 @@
return sorted(max(versions) for versions in by_series if versions)
def create_issues(versions, server, token, project, simulate=True):
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'))
with open(os.path.expanduser(token)) as tokenf:
token = tokenf.read().strip()
post_data = dict(
description="A new release tag v%s appeared in "
"upstream GitLab."
"\n\n"
"It should be considered for a stable Heptapod "
"release.\n" % version_str,
title="GitLab " + version_str
)
if simulate:
print("Simulate mode: would POST %r, data=%r" % (url,
post_data))
continue
resp = requests.post(url,
headers={'Private-Token': token},
data=post_data)
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():
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--simulate", action='store_true')
......@@ -115,41 +153,12 @@
print("No new releases to consider")
return
if cl_args.create_issue:
for version in new_versions:
version_str = '.'.join(str(i) for i in version)
print("Creating issue for GitLab " + repr(version))
url = '/'.join((cl_args.heptapod_server, 'api', 'v4',
'projects',
cl_args.heptapod_project.replace('/', '%2F'),
'issues'))
with open(os.path.expanduser(cl_args.heptapod_token)) as tokenf:
token = tokenf.read().strip()
post_data = dict(
description="A new release tag v%s appeared in "
"upstream GitLab."
"\n\n"
"It should be considered for a stable Heptapod "
"release.\n" % version_str,
title="GitLab " + version_str
)
if simulate:
print("Simulate mode: would POST %r, data=%r" % (url,
post_data))
else:
resp = requests.post(url,
headers={'Private-Token': token},
data=post_data)
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
if cl_args.create_issues:
return create_issues(versions=new_versions,
server=cl_args.heptapod_server,
token=cl_args.heptapod_token,
project=cl_args.heptapod_project,
simulate=simulate)
if __name__ == '__main__':
......
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