diff --git a/git-flow b/git-flow index e1590a3..2176e10 100755 --- a/git-flow +++ b/git-flow @@ -493,21 +493,13 @@ def get_changelog_header_lines(branch: str): "", f"- Autor: [{name}](mailto:{email})", f"- Rama: `{branch}`", - "" - "### Commits" + "", + "### Commits", "" ] -def get_changelog_footer_lines(): - return [ - "", - "---", - "", - "" - ] - -def generate_changelog_entry(branch: str, target: str): - entry_lines = get_changelog_header_lines(branch) +def get_changelog_content_lines(target: str): + lines = [] commits = Git("log", target + "..", first_parent=True, format="%h", merges=False).lines() for commit in commits: @@ -520,13 +512,26 @@ def generate_changelog_entry(branch: str, target: str): commit_type = message[:index] commit_message = message[index+1:] - entry_lines.append(f"- **{commit_type}**: {commit_message} ({commit})") + lines.append(f"- **{commit_type}**: {commit_message} ({commit})") diff_tree = Git("diff-tree", commit, r=True, commit_id=False, name_status=True).lines() for diff in diff_tree: [status, filename] = diff.split("\t") - entry_lines.append(f"\t- {filename} ({status})") + lines.append(f"\t- {filename} ({status})") + return lines + +def get_changelog_footer_lines(): + return [ + "", + "---", + "", + "" + ] + +def generate_changelog_entry(branch: str, target: str): + entry_lines = get_changelog_header_lines(branch) + entry_lines = get_changelog_content_lines(target) entry_lines += get_changelog_footer_lines() return "\n".join(entry_lines) @@ -535,10 +540,7 @@ def generate_changelog_entry(branch: str, target: str): def create_pull_request(service: str, repository: str, source: str, destination: str): endpoint = get_api_endpoint(service, repository, "/pullrequests") title = source.replace("/", ": ").replace("-", " ") - lines = generate_changelog_entry(source, destination).splitlines() - header_lines = get_changelog_header_lines(source) - footer_lines = get_changelog_footer_lines() - description = "\n".join(lines[len(header_lines):-len(footer_lines)]) + description = "\n".join(get_changelog_content_lines(destination)) headers = get_headers() json = { @@ -552,7 +554,8 @@ def create_pull_request(service: str, repository: str, source: str, destination: request = requests.post(endpoint, headers=headers, json=json) if request.ok: - print("PR creado exitosamente.") + print_success("PR creado exitosamente.") + print_debug("Response body: " + request.text) else: print_error("Ocurrió un error al crear el PR: " + request.text) diff --git a/lib/io.py b/lib/io.py index 9676ef3..dd9951a 100644 --- a/lib/io.py +++ b/lib/io.py @@ -54,6 +54,9 @@ def print_error(message: str): def print_warning(message: str): print(f"{COLOR_YELLOW}[wrn] {message}{COLOR_RESET}") +def print_success(message: str): + print(f"{COLOR_GREEN}[ok!] {message}{COLOR_RESET}") + def print_info(message: str): print(f"{COLOR_BLUE}[inf] {message}{COLOR_RESET}")