Read about our upcoming Code of Conduct on this issue

Commit 900780e0 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

fetch_watch_tags: new option to perform convert/push automatically

If it is used, the checkboxes for the corresponding tasks in the issue
will be ticked according to the success of the conversion.
parent c202b8aae6d7
Pipeline #28649 passed with stage
in 1 minute and 10 seconds
......@@ -9,7 +9,7 @@
import os
import re
import requests
from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, call
from .version import (
level2_version,
......@@ -34,7 +34,7 @@
(if a script is not found, add `$HOME/.local/bin` to $PATH)
- [ ] Main repository:
- [{rails_converted}] Main repository:
```
fetch-stable-branches && \
......@@ -42,7 +42,7 @@
convert-git-tags-push -R heptapod-rails
```
- [ ] Omnibus:
- [{omnibus_converted}] Omnibus:
```
fetch-stable-branches --gitlab-repo omnibus-gitlab && \
......@@ -103,7 +103,58 @@
return tokenf.read().strip()
def create_issue(version, server, token, project, simulate=True):
def result_as_checkbox(result):
return 'x' if result else ' '
def cmd(*args, **kwargs):
simulate = kwargs.pop('simulate', True)
if simulate:
print("Simulation mode, would call %r with options %r" % (args,
kwargs))
return True
print("Calling %r with options %r" % (args, kwargs))
exit_code = call(args, **kwargs)
return exit_code == 0
def convert_push_repo(gitlab_repo, heptapod_repo, git_branch, simulate=True):
"""Run the full conversion for the given GitLab project.
:return: ``True`` if the three steps succeeded
"""
return all((
cmd('fetch-stable-branches', '--gitlab-repo', gitlab_repo,
simulate=simulate),
cmd('convert-pull-local',
'--gitlab-repo', gitlab_repo,
'--heptapod-repo', heptapod_repo,
'--branch-prefix', git_branch,
'--push',
simulate=simulate),
cmd('convert-git-tags-push',
'-R', heptapod_repo,
'--force-confirm',
simulate=simulate),
))
def convert_push(version, simulate=True):
git_branch = version.git_stable_branch
return dict(rails=convert_push_repo(gitlab_repo='gitlab-ce',
heptapod_repo='heptapod-rails',
git_branch=git_branch,
simulate=simulate),
omnibus=convert_push_repo(gitlab_repo='omnibus-gitlab',
heptapod_repo='omnibus-heptapod',
git_branch=git_branch,
simulate=simulate),
)
def create_issue(version, server, token, project, conversion_result,
simulate=True):
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
project.replace('/', '%2F'),
......@@ -112,6 +163,8 @@
description = ISSUE_TEMPLATE.format(
git_branch=version.git_stable_branch,
tag=version.gitlab_rails_tag,
rails_converted=result_as_checkbox(conversion_result.get('rails')),
omnibus_converted=result_as_checkbox(conversion_result.get('omnibus')),
)
post_data = dict(
description=description,
......@@ -144,6 +197,9 @@
help="Path to GitLab CE Git repo, relative "
"to the parent direcoty of the "
"`heptapod_git_conversion` package")
parser.add_argument("--convert-push", action='store_true',
help="Run all Git to Mercurial conversions and "
"push to the repos default paths")
parser.add_argument("--create-issues", "--create-issue",
action='store_true')
parser.add_argument("--heptapod-token",
......@@ -200,5 +256,7 @@
print("No new releases to consider")
return
do_convert = cl_args.convert_push
token = read_token_file(cl_args.heptapod_token)
......@@ -203,5 +261,12 @@
token = read_token_file(cl_args.heptapod_token)
conversion_results = {}
if do_convert:
for version in new_versions:
conversion_results[version] = convert_push(version,
simulate=simulate)
print("Conversion results: %r " % conversion_results)
error_codes = []
if cl_args.create_issues:
for version in new_versions:
......@@ -210,6 +275,8 @@
server=cl_args.heptapod_server,
token=token,
project=cl_args.heptapod_project,
conversion_result=conversion_results.get(version,
{}),
simulate=simulate))
if any(code for code in error_codes):
......
......@@ -38,10 +38,15 @@
return FakeResponse(code=200, data=dict(iid=123))
monkeypatch.setattr(requests, 'post', intercept_post)
create_args = (GitLabVersion(14, 1, 5),
'https://heptapod.example',
'siCr3t',
'heptapod/heptapod')
create_issue(*create_args, simulate=False)
for conversion_result in (
{},
dict(omnibus=True, rails=False),
dict(omnibus=True, rails=True),
dict(rails=True),
):
create_args = (GitLabVersion(14, 1, 5),
'https://heptapod.example',
'siCr3t',
'heptapod/heptapod',
conversion_result)
......@@ -47,14 +52,17 @@
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
create_issue(*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_issue(*create_args, simulate=True)
......
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