Skip to content
Snippets Groups Projects
Commit d19ac3cd authored by Emanuele Aina's avatar Emanuele Aina
Browse files

pkg-merge-upstream-to-downstreams: Add --dry-run


Add a command line flag to avoid pushing commits, to make local testing easier.

Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent e3923096
No related branches found
No related tags found
1 merge request!214v2021 ← v2022dev2: pkg-merge-updates: Always produce a merge commit
......@@ -10,6 +10,7 @@
import argparse
from sh.contrib import git
from sh import apertis_pkg_merge_updates
from sh import echo
import re
from pathlib import Path
from functools import partial
......@@ -53,16 +54,16 @@ def is_minor_change(upstream, downstream):
o = git('diff', '--exit-code', upstream, downstream, ':!debian/changelog', ':!debian/apertis/*', _ok_code=[0,1])
return o.exit_code == 0
def push_merge_request(project_url, proposed_branch, upstream, downstream, auto_merge = ''):
def push_merge_request(project_url, proposed_branch, upstream, downstream, auto_merge = '', dry_run=False):
title = f"Update from {upstream} for {downstream}"
print(f"Pushing {proposed_branch}: {title}")
print(f'Minor change {upstream}..{proposed_branch}? {is_minor_change(upstream, proposed_branch)}')
git_push_custom = git.push.bake()
git_push_custom = echo.bake("dry run:", "git", "push") if dry_run else git.push.bake()
if is_minor_change(upstream, proposed_branch) and downstream in auto_merge:
print('Minor change and auto_merge set, merge can be done when pipeline succeeds')
git_push_custom = git.push.bake('-o', 'merge_request.merge_when_pipeline_succeeds')
git_push_custom = git_push_custom.bake('-o', 'merge_request.merge_when_pipeline_succeeds')
else:
print('Merge should be reviewed')
......@@ -86,6 +87,7 @@ def main():
parser.add_argument('project_url', type=str, help='git project url to push updates to')
parser.add_argument('--auto-merge', dest='auto_merge', type=str, default='',
help='list of branches that allow auto merge, colon-separated (e.g. apertis/v2020dev0:apertis/v2019)')
parser.add_argument('--dry-run', action='store_true', help='do not push merged commits')
args = parser.parse_args()
upstream = args.upstream
......@@ -111,7 +113,7 @@ def main():
ref = git("rev-parse", downstream_branch).rstrip()
proposed_branch = f"proposed-updates/{upstream_branch}/{ref[0:8]}"
push_this_merge_request = partial(push_merge_request, args.project_url, proposed_branch, upstream_branch, downstream_branch, auto_merge)
push_this_merge_request = partial(push_merge_request, args.project_url, proposed_branch, upstream_branch, downstream_branch, auto_merge, dry_run=args.dry_run)
# check if we have a proposed branch from a previous iteration
if git("rev-parse", "--verify", proposed_branch, _ok_code=[0, 128]).strip():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment