Skip to content

Commit

Permalink
fix(reana-dev): detect number of already open PR in commit suffix (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Mar 1, 2024
1 parent 6efdc9b commit 9e9532d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion reana/reana_dev/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def run_command(
return_output: bool = False,
directory: str = None,
dry_run: bool = False,
exit_on_error: bool = True,
) -> Optional[str]:
"""Run given command in the given component source directory.
Expand Down Expand Up @@ -350,7 +351,10 @@ def run_command(
click.secho("[{0}] ".format(now), bold=True, nl=False, fg="green")
click.secho("{0}: ".format(component), bold=True, nl=False, fg="yellow")
click.secho("{0}".format(err), bold=True, fg="red")
sys.exit(err.returncode)
if exit_on_error:
sys.exit(err.returncode)

Check warning on line 355 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L354-L355

Added lines #L354 - L355 were not covered by tests
else:
raise

Check warning on line 357 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L357

Added line #L357 was not covered by tests


@dataclass
Expand Down Expand Up @@ -970,6 +974,25 @@ def validate_directory(ctx, param, target_directory):
return target_directory


def get_current_pr_number(component):
"""Get the PR number of the current branch."""
try:
output = run_command(

Check warning on line 980 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L979-L980

Added lines #L979 - L980 were not covered by tests
f"gh pr view --json number",
component=component,
display=False,
return_output=True,
exit_on_error=False,
)
except subprocess.CalledProcessError as e:
if e.returncode == 1:

Check warning on line 988 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L987-L988

Added lines #L987 - L988 were not covered by tests
# no PR associated to the branch
return None
raise
res = json.loads(output)
return res["number"]

Check warning on line 993 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L990-L993

Added lines #L990 - L993 were not covered by tests


def get_next_available_issue_pr_number(component):
"""Get the next available number for issues/PRs."""
last_used = 0
Expand All @@ -990,6 +1013,10 @@ def get_next_available_issue_pr_number(component):

def get_commit_pr_suffix(component):
"""Get the commit message suffix containing the expected PR number."""
current_pr = get_current_pr_number(component)
if current_pr:
return f" (#{current_pr})"

Check warning on line 1018 in reana/reana_dev/utils.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L1016-L1018

Added lines #L1016 - L1018 were not covered by tests

pr_number_suffix = ""
try:
pr_number = get_next_available_issue_pr_number(component)
Expand Down

0 comments on commit 9e9532d

Please sign in to comment.