Skip to content

Commit

Permalink
fix(reana-dev): create commits that conform to conventional style (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Feb 16, 2024
1 parent 43ead8a commit 86d0133
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
6 changes: 6 additions & 0 deletions reana/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

"""``reana-dev`` CLI configuration."""

import re


REPO_LIST_DEMO_RUNNABLE = [
"reana-demo-alice-lego-train-test-run",
"reana-demo-alice-pt-analysis",
Expand Down Expand Up @@ -298,3 +301,6 @@

PYTHON_DOCKER_IMAGE = "docker.io/library/python:3.8"
"""Python docker image with the same version as cluster components."""

RELEASE_COMMIT_REGEX = re.compile("^(release:|chore.*: release)")
"""Regex to find out if commit message refers to a new release."""
17 changes: 12 additions & 5 deletions reana/reana_dev/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
OPENAPI_VERSION_FILE,
PYTHON_REQUIREMENTS_FILE,
PYTHON_VERSION_FILE,
RELEASE_COMMIT_REGEX,
REPO_LIST_ALL,
REPO_LIST_PYTHON_REQUIREMENTS,
REPO_LIST_SHARED,
Expand All @@ -46,6 +47,7 @@
update_module_in_cluster_components,
upgrade_requirements,
validate_directory,
get_commit_pr_suffix,
)


Expand Down Expand Up @@ -163,7 +165,7 @@ def git_create_release_commit(
next_version: Optional[str] = None,
) -> bool:
"""Create a release commit for the given component."""
if "release:" in get_current_commit(get_srcdir(component)):
if is_last_commit_release_commit(component):

Check warning on line 168 in reana/reana_dev/git.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/git.py#L168

Added line #L168 was not covered by tests
display_message("Nothing to do, last commit is a release commit.", component)
return False

Expand Down Expand Up @@ -199,8 +201,11 @@ def git_create_release_commit(
if modified_files:
run_command(f"git add {' '.join(modified_files)}", component)

commit_msg = (

Check warning on line 204 in reana/reana_dev/git.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/git.py#L204

Added line #L204 was not covered by tests
f"chore({base}): release {next_version}{get_commit_pr_suffix(component)}"
)
run_command(
f"git commit -m 'release: {next_version}' {'--allow-empty' if not modified_files else ''}",
f"git commit -m '{commit_msg}' {'--allow-empty' if not modified_files else ''}",
component,
)
return True
Expand Down Expand Up @@ -289,7 +294,8 @@ def print_branch_difference_report(
def is_last_commit_release_commit(package):
"""Check whether the last commit is a release commit."""
current_commit = get_current_commit(get_srcdir(package))
return current_commit.split()[1] == "release:"
commit_msg = current_commit.split(maxsplit=1)[1]
return RELEASE_COMMIT_REGEX.match(commit_msg)

Check warning on line 298 in reana/reana_dev/git.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/git.py#L297-L298

Added lines #L297 - L298 were not covered by tests


def git_push_to_origin(components):
Expand Down Expand Up @@ -1280,7 +1286,7 @@ def git_upgrade_shared_modules(

def _create_commit_or_amend(components):
for c in components:
commit_cmd = 'git commit -m "installation: bump shared modules"'
commit_cmd = f'git commit -m "build(python): bump shared modules{get_commit_pr_suffix(component)}"'

Check warning on line 1289 in reana/reana_dev/git.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/git.py#L1289

Added line #L1289 was not covered by tests
if amend:
commit_cmd = "git commit --amend --no-edit"

Expand Down Expand Up @@ -1365,7 +1371,8 @@ def git_upgrade_requirements(ctx, component, exclude_components): # noqa: D301
if upgrade_requirements(component):
run_command(f"git add {PYTHON_REQUIREMENTS_FILE}", component)
run_command(
'git commit -m "installation: bump all dependencies"', component
f'git commit -m "build(python): bump all dependencies{get_commit_pr_suffix(component)}"',
component,
)


Expand Down
29 changes: 29 additions & 0 deletions reana/reana_dev/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,32 @@ def validate_directory(ctx, param, target_directory):
click.echo(click.style(message, fg="red"), err=True)
ctx.exit(1)
return target_directory


def get_next_available_issue_pr_number(component):
"""Get the next available number for issues/PRs."""
last_used = 0
for type_ in ("pr", "issue"):
res = json.loads(

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

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L975-L977

Added lines #L975 - L977 were not covered by tests
run_command(
f"gh {type_} list --state all --limit 1 --json number",
component=component,
display=False,
return_output=True,
)
)
if res:
last_used = max(last_used, res[0]["number"])

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

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L985-L986

Added lines #L985 - L986 were not covered by tests

return last_used + 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#L988

Added line #L988 was not covered by tests


def get_commit_pr_suffix(component):
"""Get the commit message suffix containing the expected PR number."""
pr_number_suffix = ""
try:
pr_number = get_next_available_issue_pr_number(component)
pr_number_suffix = f" (#{pr_number})"
except Exception as e:
display_message(f"Could not find next available PR number: {e}", component)
return pr_number_suffix

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

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/utils.py#L993-L999

Added lines #L993 - L999 were not covered by tests

0 comments on commit 86d0133

Please sign in to comment.