Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Mar 6, 2024
1 parent a4cb84c commit a5ba55e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions reana/reana_dev/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

import datetime
import os
import re
import subprocess
import sys
from typing import Optional

import click
import yaml

from reana.config import (
COMPONENTS_USING_SHARED_MODULE_COMMONS,
Expand All @@ -28,6 +30,8 @@
PYTHON_VERSION_FILE,
RELEASE_COMMIT_REGEX,
REPO_LIST_ALL,
REPO_LIST_CLUSTER_INFRASTRUCTURE,
REPO_LIST_CLUSTER_RUNTIME_BATCH,
REPO_LIST_PYTHON_REQUIREMENTS,
REPO_LIST_SHARED,
)
Expand Down Expand Up @@ -1586,4 +1590,59 @@ def git_tag(component, exclude_components): # noqa: D301
run_command(f"git tag {current_version}", component=component)


@git_commands.command(name="git-aggregate-changelog")
def get_aggregate_changelog(): # noqa: D301
"""TODO"""

for component in REPO_LIST_CLUSTER_INFRASTRUCTURE + REPO_LIST_CLUSTER_RUNTIME_BATCH:
if not is_last_commit_release_commit(component):
click.secho(
"The last commit is not a release commit. Please use `reana-dev git-create-release-commit`.",
fg="red",
)
sys.exit(1)

with open(get_srcdir("reana") + "/helm/reana/values.yaml") as values_file:
values = yaml.safe_load(values_file)

aggregated_changelog = []
for component in REPO_LIST_CLUSTER_INFRASTRUCTURE + REPO_LIST_CLUSTER_RUNTIME_BATCH:
image = values["components"][component.replace("-", "_")]["image"]
prev_version = image.split(":")[1]

with open(get_srcdir(component) + "/CHANGELOG.md") as f:
changelog_lines = f.readlines()

start_index = None
for i, line in enumerate(changelog_lines):
if line.startswith("##"):
start_index = i
break

end_index = None
for i, line in enumerate(changelog_lines):
prev_version_escaped = prev_version.replace(".", "\.")
if re.match(f"^##\s+\[?{prev_version_escaped}", line):
end_index = i
break

filtered_lines = []
current_section = ""
for line in changelog_lines[start_index:end_index]:
if line.startswith("### "):
current_section = line[len("### "):].strip()

if line.startswith("## "):
line = f"### {component}" + line[len("##") :]
filtered_lines.append("\n")
filtered_lines.append(line)
filtered_lines.append("\n")
elif line.startswith("*") and "Continuous" not in current_section:
filtered_lines.append(f"* [{current_section}]" + line[1:])

aggregated_changelog += filtered_lines

print("".join(aggregated_changelog))


git_commands_list = list(git_commands.commands.values())

0 comments on commit a5ba55e

Please sign in to comment.