Skip to content

Commit 6f5f39a

Browse files
committed
fix(reana-dev): create commits that conform to conventional style (#777)
1 parent ae90500 commit 6f5f39a

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

reana/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

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

11+
import re
12+
13+
1114
REPO_LIST_DEMO_RUNNABLE = [
1215
"reana-demo-alice-lego-train-test-run",
1316
"reana-demo-alice-pt-analysis",
@@ -298,3 +301,6 @@
298301

299302
PYTHON_DOCKER_IMAGE = "docker.io/library/python:3.8"
300303
"""Python docker image with the same version as cluster components."""
304+
305+
RELEASE_COMMIT_REGEX = re.compile("^(release:|chore.*: release)")
306+
"""Regex to find out if commit message refers to a new release."""

reana/reana_dev/git.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
OPENAPI_VERSION_FILE,
2525
PYTHON_REQUIREMENTS_FILE,
2626
PYTHON_VERSION_FILE,
27+
RELEASE_COMMIT_REGEX,
2728
REPO_LIST_ALL,
2829
REPO_LIST_PYTHON_REQUIREMENTS,
2930
REPO_LIST_SHARED,
@@ -46,6 +47,7 @@
4647
update_module_in_cluster_components,
4748
upgrade_requirements,
4849
validate_directory,
50+
get_commit_pr_suffix,
4951
)
5052

5153

@@ -163,7 +165,7 @@ def git_create_release_commit(
163165
next_version: Optional[str] = None,
164166
) -> bool:
165167
"""Create a release commit for the given component."""
166-
if "release:" in get_current_commit(get_srcdir(component)):
168+
if is_last_commit_release_commit(component):
167169
display_message("Nothing to do, last commit is a release commit.", component)
168170
return False
169171

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

204+
commit_msg = (
205+
f"chore({base}): release {next_version}{get_commit_pr_suffix(component)}"
206+
)
202207
run_command(
203-
f"git commit -m 'release: {next_version}' {'--allow-empty' if not modified_files else ''}",
208+
f"git commit -m '{commit_msg}' {'--allow-empty' if not modified_files else ''}",
204209
component,
205210
)
206211
return True
@@ -289,7 +294,8 @@ def print_branch_difference_report(
289294
def is_last_commit_release_commit(package):
290295
"""Check whether the last commit is a release commit."""
291296
current_commit = get_current_commit(get_srcdir(package))
292-
return current_commit.split()[1] == "release:"
297+
commit_msg = current_commit.split(maxsplit=1)[1]
298+
return RELEASE_COMMIT_REGEX.match(commit_msg)
293299

294300

295301
def git_push_to_origin(components):
@@ -1280,7 +1286,7 @@ def git_upgrade_shared_modules(
12801286

12811287
def _create_commit_or_amend(components):
12821288
for c in components:
1283-
commit_cmd = 'git commit -m "installation: bump shared modules"'
1289+
commit_cmd = f'git commit -m "build(deps): bump shared modules{get_commit_pr_suffix(component)}"'
12841290
if amend:
12851291
commit_cmd = "git commit --amend --no-edit"
12861292

@@ -1365,7 +1371,8 @@ def git_upgrade_requirements(ctx, component, exclude_components): # noqa: D301
13651371
if upgrade_requirements(component):
13661372
run_command(f"git add {PYTHON_REQUIREMENTS_FILE}", component)
13671373
run_command(
1368-
'git commit -m "installation: bump all dependencies"', component
1374+
f'git commit -m "build(deps): bump all dependencies{get_commit_pr_suffix(component)}"',
1375+
component,
13691376
)
13701377

13711378

reana/reana_dev/utils.py

+29
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,32 @@ def validate_directory(ctx, param, target_directory):
968968
click.echo(click.style(message, fg="red"), err=True)
969969
ctx.exit(1)
970970
return target_directory
971+
972+
973+
def get_next_available_issue_pr_number(component):
974+
"""Get the next available number for issues/PRs."""
975+
last_used = 0
976+
for type_ in ("pr", "issue"):
977+
res = json.loads(
978+
run_command(
979+
f"gh {type_} list --state all --limit 1 --json number",
980+
component=component,
981+
display=False,
982+
return_output=True,
983+
)
984+
)
985+
if res:
986+
last_used = max(last_used, res[0]["number"])
987+
988+
return last_used + 1
989+
990+
991+
def get_commit_pr_suffix(component):
992+
"""Get the commit message suffix containing the expected PR number."""
993+
pr_number_suffix = ""
994+
try:
995+
pr_number = get_next_available_issue_pr_number(component)
996+
pr_number_suffix = f" (#{pr_number})"
997+
except Exception as e:
998+
display_message(f"Could not find next available PR number: {e}", component)
999+
return pr_number_suffix

0 commit comments

Comments
 (0)