Merge pull request 'bugfix: apply release prefix and ticket detection to single-commit PR titles' (#20) from bugfix/pr-title-single-commit into main
Publish to PyPI / Publish-to-PyPI (push) Failing after 14s
Publish to PyPI / Publish-to-PyPI (push) Failing after 14s
Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
import git_flow.command.base as base
|
import git_flow.command.base as base
|
||||||
@@ -102,7 +104,7 @@ def check_merge_conflicts(target: str):
|
|||||||
def create_pull_request(token: str, branch: str, target: str):
|
def create_pull_request(token: str, branch: str, target: str):
|
||||||
changelog = Changelog()
|
changelog = Changelog()
|
||||||
commits = Git("log", target + "..", format="%s").lines()
|
commits = Git("log", target + "..", format="%s").lines()
|
||||||
title = commits[0] if len(commits) == 1 else _get_pr_title_from_branch(branch)
|
title = _get_pr_title(branch, commits)
|
||||||
|
|
||||||
base.panel("Título del PR", title)
|
base.panel("Título del PR", title)
|
||||||
|
|
||||||
@@ -120,34 +122,42 @@ def create_pull_request(token: str, branch: str, target: str):
|
|||||||
base.io_success(message, "Rama creada")
|
base.io_success(message, "Rama creada")
|
||||||
|
|
||||||
|
|
||||||
def _get_pr_title_from_branch(branch: str) -> str:
|
def _get_pr_title(branch: str, commits: list[str]) -> str:
|
||||||
if branch in base.environments:
|
if branch in base.environments:
|
||||||
target = base.environments[base.environments.index(branch) + 1]
|
target = base.environments[base.environments.index(branch) + 1]
|
||||||
return f"Sincronización de entorno {branch} a {target}"
|
return f"Sincronización de entorno {branch} a {target}"
|
||||||
|
|
||||||
components = branch.split("/") # <type>/<desc> or release/<env>/<type>/<desc>
|
components = branch.split("/") # <type>/<desc> or release/<env>/<type>/<desc>
|
||||||
|
release_prefix = f"[Pasaje a {components[1]}]" if len(components) == 4 else None
|
||||||
branch_type = components[-2]
|
branch_type = components[-2]
|
||||||
branch_desc = components[-1]
|
branch_ticket, branch_desc = _extract_ticket_from_branch(components[-1])
|
||||||
|
|
||||||
# detect if branch description has ticket as prefix: <desc> = ABC-123-my-branch-name
|
# when there's a single commit, use it as the PR description instead of
|
||||||
branch_ticket = None
|
# deriving one from the branch name, but keep the release prefix / ticket
|
||||||
first_dash = branch_desc.find("-")
|
if len(commits) == 1:
|
||||||
second_dash = branch_desc.find("-", first_dash + 1)
|
return " ".join(filter(None, [release_prefix, branch_ticket, commits[0]]))
|
||||||
|
|
||||||
if first_dash >= 0 and second_dash >= 0:
|
|
||||||
maybe_ticket = branch_desc[:second_dash]
|
|
||||||
if base.is_valid_ticket(maybe_ticket):
|
|
||||||
branch_ticket = maybe_ticket
|
|
||||||
branch_desc = branch_desc[second_dash + 1 :]
|
|
||||||
|
|
||||||
return " ".join(
|
return " ".join(
|
||||||
filter(
|
filter(
|
||||||
None,
|
None,
|
||||||
[
|
[
|
||||||
f"[Pasaje a {components[1]}]" if len(components) == 4 else None,
|
release_prefix,
|
||||||
branch_type + ":",
|
branch_type + ":",
|
||||||
branch_ticket,
|
branch_ticket,
|
||||||
branch_desc.replace("-", " "),
|
branch_desc.replace("-", " "),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_ticket_from_branch(branch_desc: str) -> tuple[Optional[str], str]:
|
||||||
|
"""detect if branch description has ticket as prefix: <desc> = ABC-123-my-branch-name"""
|
||||||
|
first_dash = branch_desc.find("-")
|
||||||
|
second_dash = branch_desc.find("-", first_dash + 1)
|
||||||
|
|
||||||
|
if first_dash >= 0 and second_dash >= 0:
|
||||||
|
maybe_ticket = branch_desc[:second_dash]
|
||||||
|
if base.is_valid_ticket(maybe_ticket):
|
||||||
|
return maybe_ticket, branch_desc[second_dash + 1 :]
|
||||||
|
|
||||||
|
return None, branch_desc
|
||||||
|
|||||||
Reference in New Issue
Block a user