Skip to content

cmd

Changelog related commands.

Commands invoked by dpteam changelogs are defined here.

print_changelogs(n_logs=typer.Option(5, '--nlogs', '-n', help='Number of latest logs to show'))

Prints the n last release changelogs for 'dapla-team-cli'.

Source code in dapla_team_cli/changelogs/cmd.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def print_changelogs(n_logs: int = typer.Option(5, "--nlogs", "-n", help="Number of latest logs to show")) -> None:
    """Prints the n last release changelogs for 'dapla-team-cli'."""
    logs = get_release_logs("dapla-team-cli", n_logs)
    for log in reversed(logs):
        console.print(f"[green]Release tag: {log.tag_name}, released on {str(log.published_at)}")
        if log.body == "":
            continue

        new_body: str = remove_unnecessary_content(log.body)
        log_lines = [line.replace("##", "[yellow]").lstrip() if "##" in line else line for line in new_body.splitlines()]

        for line in log_lines:
            console.print(line)
        console.print("\n")

remove_unnecessary_content(body)

The function divides the input string into a list by splitting on the header's prefix.

Unnecessary headers are removed by comparing each header to a regular expression. The list is then joined and returned as a string.

:param body: A string with log data, divided into different contet by headers. :return: Log data with filtered content.

Source code in dapla_team_cli/changelogs/cmd.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def remove_unnecessary_content(body: str) -> str:
    """The function divides the input string into a list by splitting on the header's prefix.

    Unnecessary headers are removed by comparing each header to a regular expression.
    The list is then joined and returned as a string.

    :param body: A string with log data, divided into different contet by headers.
    :return: Log data with filtered content.
    """
    regex_pattern: str = "^[^\n]*(" + HEADERS_TO_KEEP + ")(.|\n)*$"
    body_list: list[str] = body.split("##")

    for i in range(len(body_list) - 1, -1, -1):
        if re.search(regex_pattern, body_list[i]) is None:
            body_list.pop(i)

    new_body: str = "##" + "##".join(body_list)
    return new_body