Skip to content

Branch naming

branch_naming

Branch naming convention for ticket-driven workflows.

branch_name_from_ticket(ticket_id, title, labels)

Build a deterministic branch name from ticket metadata.

Produces names in the format <type>/<TICKET_ID>-<slug> where type is derived from the ticket labels.

Parameters:

Name Type Description Default
ticket_id str

Ticket identifier (e.g. "AXM-42").

required
title str

Ticket title used to generate the slug.

required
labels list[str]

Ticket labels used to determine the branch type.

required

Returns:

Type Description
str

A URL-safe branch name.

Source code in packages/axm-git/src/axm_git/core/branch_naming.py
def branch_name_from_ticket(
    ticket_id: str,
    title: str,
    labels: list[str],
) -> str:
    """Build a deterministic branch name from ticket metadata.

    Produces names in the format ``<type>/<TICKET_ID>-<slug>`` where
    *type* is derived from the ticket labels.

    Args:
        ticket_id: Ticket identifier (e.g. ``"AXM-42"``).
        title: Ticket title used to generate the slug.
        labels: Ticket labels used to determine the branch type.

    Returns:
        A URL-safe branch name.
    """
    branch_type = _resolve_type(labels, title)
    slug = slugify(title)
    return f"{branch_type}/{ticket_id}-{slug}"

slugify(title, *, max_len=40)

Convert a title string into a URL-safe slug.

Lowercases the input, replaces non-alphanumeric characters with hyphens, collapses consecutive hyphens, and strips leading/trailing hyphens.

Parameters:

Name Type Description Default
title str

The title to slugify.

required
max_len int

Maximum length of the slug (default 40). Truncation prefers word boundaries when possible.

40

Returns:

Type Description
str

A sanitized slug, or "untitled" if the title is empty or

str

contains only special characters.

Source code in packages/axm-git/src/axm_git/core/branch_naming.py
def slugify(title: str, *, max_len: int = 40) -> str:
    """Convert a title string into a URL-safe slug.

    Lowercases the input, replaces non-alphanumeric characters with hyphens,
    collapses consecutive hyphens, and strips leading/trailing hyphens.

    Args:
        title: The title to slugify.
        max_len: Maximum length of the slug (default 40). Truncation
            prefers word boundaries when possible.

    Returns:
        A sanitized slug, or ``"untitled"`` if the title is empty or
        contains only special characters.
    """
    slug = title.lower()
    slug = re.sub(r"[^a-z0-9]+", "-", slug)
    slug = slug.strip("-")

    if not slug:
        return "untitled"

    if len(slug) <= max_len:
        return slug

    # Truncate at word boundary
    truncated = slug[:max_len]
    last_hyphen = truncated.rfind("-")
    if last_hyphen > 0:
        truncated = truncated[:last_hyphen]

    return truncated.rstrip("-")