Skip to content

Commit

Permalink
cli: add git-merge command
Browse files Browse the repository at this point in the history
closes #362
  • Loading branch information
mvidalgarcia committed Aug 5, 2020
1 parent d825f12 commit 7e22a2c
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions reana/reana_dev/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def git_branch(component): # noqa: D301


@click.option(
"--branch", "-b", nargs=2, multiple=True, help="Which PR? [number component]"
"--branch", "-b", nargs=2, multiple=True, help="Which PR? [component PR#]"
)
@click.option("--fetch", is_flag=True, default=False)
@git_commands.command(name="git-checkout")
Expand All @@ -465,7 +465,7 @@ def git_checkout(branch, fetch): # noqa: D301
72`` will create a local branch called ``pr-72`` in the
reana-workflow-controller source code directory.
:param fetch: Should we fetch latest upstream first? [default=False]
:type component: str
:type branch: list
:type fetch: bool
"""
for cpr in branch:
Expand All @@ -482,6 +482,52 @@ def git_checkout(branch, fetch): # noqa: D301
display_message(msg, component)


@click.option(
"--branch", "-b", nargs=2, multiple=True, help="Which PR? [component PR#]"
)
@click.option("--push", is_flag=True, default=False)
@git_commands.command(name="git-merge")
def git_merge(branch, push): # noqa: D301
"""Merge to local master a component pull request.
The ``-b`` option can be repetitive to merge several pull requests in
several repositories at the same time.
\b
:param branch: The option ``branch`` can be repeated. The value consist of
two strings specifying the component name and the pull
request number. For example, ``-b reana-workflow-controler
72`` will merge a local branch called ``pr-72`` from the
reana-workflow-controller to master branch.
:param push: Should we push to origin and upstream? [default=False]
:type branch: list
:type push: bool
"""
for cpr in branch:
component, pull_request = cpr
component = select_components([component,])[0]
if component in REPO_LIST_ALL:
for cmd in [
"git fetch upstream",
"git diff pr-{0}..upstream/pr/{0}".format(pull_request),
"git checkout master",
"git merge --ff-only upstream/master",
"git merge --ff-only upstream/pr/{0}".format(pull_request),
"git branch -D pr-{0}".format(pull_request),
]:
run_command(cmd, component)

if push:
for cmd in [
"git push origin master",
"git push upstream master",
]:
run_command(cmd, component)
else:
msg = "Ignoring unknown component."
display_message(msg, component)


@click.option(
"--component",
"-c",
Expand Down

0 comments on commit 7e22a2c

Please sign in to comment.