Skip to content

Commit

Permalink
Add helper and fix wording
Browse files Browse the repository at this point in the history
Signed-off-by: Wei-Chun, Chang <[email protected]>
  • Loading branch information
wcchang1115 committed Sep 15, 2023
1 parent 95bcdbc commit 1d58ce5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
26 changes: 23 additions & 3 deletions piperider_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def cloud_compare_reports(**kwargs):


@cli.command(name='compare', short_help='Compare the change for the current branch.', cls=TrackCommand)
@click.argument('ref-diff', required=False, type=click.STRING)
@click.argument('ref', required=False, type=click.STRING)
@click.option('--recipe', default=None, type=click.STRING, help='Select a different recipe.')
@click.option('--upload', default=False, is_flag=True, help='Upload the report to PipeRider Cloud.')
@click.option('--share', default=False, is_flag=True, help='Enable public share of the report to PipeRider Cloud.')
Expand All @@ -451,13 +451,33 @@ def cloud_compare_reports(**kwargs):
])
@add_options(dbt_related_options)
@add_options(debug_option)
def compare_with_recipe(ref_diff, **kwargs):
def compare_with_recipe(ref, **kwargs):
"""
Generate the comparison report for your branch.
\b
# compare with main/master branch
piperider compare
\b
# compare with specific branch
piperider compare --base-branch <branch>
\b
# compare with any reference
piperider compare <git-ref>
\b
# compare with two references
piperider compare <git-ref>...<git-ref>
\b
Note: <git-ref> can be reference that git understands. e.g., branch, tag, commit, etc.
"""

from piperider_cli.cli_utils.compare_with_recipe import compare_with_recipe as cmd
return cmd(ref_diff, **kwargs)
return cmd(ref, **kwargs)

Check warning on line 480 in piperider_cli/cli.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/cli.py#L480

Added line #L480 was not covered by tests


@cloud.command(short_help='Signup to PipeRider Cloud.', cls=TrackCommand)
Expand Down
25 changes: 13 additions & 12 deletions piperider_cli/cli_utils/compare_with_recipe.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
from rich.console import Console


def parse_compare_ref(refs: str):
def parse_compare_ref(ref: str):
console = Console()

if refs is None:
if ref is None:
return None, None

if '...' in refs:
base_ref = refs.split('...')[0]
target_ref = refs.split('...')[1]
if '...' in ref:
base_ref = ref.split('...')[0]
target_ref = ref.split('...')[1]
if base_ref == '' or target_ref == '':
console.print('[bold red]Error:[/bold red] Commit format is not supported')
console.print('[bold red]Error:[/bold red] '
'Please either provide a single git reference or a 3-dot diff comparison form.')
return None, None
elif '..' in refs:
elif '..' in ref:
console.print('[bold red]Error:[/bold red] Two-dot diff comparisons are not supported')
return None, None
else:
base_ref = refs
base_ref = ref
target_ref = None

return base_ref, target_ref


def compare_with_recipe(ref_diff, **kwargs):
def compare_with_recipe(ref, **kwargs):
"""
Generate the comparison report for your branch.
"""
Expand All @@ -48,13 +49,13 @@ def compare_with_recipe(ref_diff, **kwargs):
modified = kwargs.get('modified')
skip_datasource_connection = kwargs.get('skip_datasource')

base_ref, target_ref = parse_compare_ref(ref_diff)
if ref_diff is not None and base_ref is None:
base_ref, target_ref = parse_compare_ref(ref)
if ref is not None and base_ref is None:
return -1

Check warning on line 54 in piperider_cli/cli_utils/compare_with_recipe.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/cli_utils/compare_with_recipe.py#L52-L54

Added lines #L52 - L54 were not covered by tests

if base_ref is not None and kwargs.get('base_branch') is not None:
console.print("[bold red]Error:[/bold red] "

Check warning on line 57 in piperider_cli/cli_utils/compare_with_recipe.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/cli_utils/compare_with_recipe.py#L56-L57

Added lines #L56 - L57 were not covered by tests
"'--base-branch' option and '[REF-DIFF]' argument cannot be used together")
"'--base-branch' option and '[REF]' argument cannot be used together")
return -1
elif base_ref is None:
base_ref = kwargs.get('base_branch')

Check warning on line 61 in piperider_cli/cli_utils/compare_with_recipe.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/cli_utils/compare_with_recipe.py#L59-L61

Added lines #L59 - L61 were not covered by tests
Expand Down

0 comments on commit 1d58ce5

Please sign in to comment.