Skip to main content

Strategy Pattern

Strategy Pattern

Contributor Extension Point

Keep tag generation, existing-tag ordering, and cross-format conversion as separate responsibilities.

Commandapp/core/git_ops/tag_strategy/

Category

Architecture

Quick Command

requested strategy -> implementation -> version tag

TagStrategyTagSorterfactoryVersionBridge

Overview​

Custy uses two related but independent strategy families. A TagStrategy calculates a new tag. A TagSorter orders tags that already exist. Keeping the families separate prevents parsing and ordering rules from becoming mixed with version-bump policy.

VersionBridge is a supporting conversion utility. It synchronizes equivalent SemVer and PEP 440 representations when a project file requires a different format from the selected Git tag; it does not choose the next version.


The Three Responsibilities

Generate a Tag

Sort Existing Tags

Convert a Version


Tag Generation Family

Built-in Tag Strategies

These implementations answer one question: what tag should Custy use next?

PatternPurposeImplementation
SemVerIncrement a semantic version using the selected bump and optional prerelease input.SemverStrategy
PEP 440Generate a Python-compatible public version from repository state and bump input.PEP440Strategy
CommitizenUse Commitizen-compatible project metadata, then delegate the version calculation through semantic-version behavior.CommitizenStrategy
DateCreate a date-based tag for projects whose releases are organized by calendar value.DateStrategy
Git CountDerive the next value from repository commit count.GitCountStrategy

Tag Resolution Flow

Workflow Timeline

1
Resolve CLI and configuration
The command resolver prepares the explicit tag, strategy, bump, prerelease, and related inputs.
completed
2
Build WorkflowConfig
WorkflowEngineBuilder carries the resolved values into one engine configuration.
completed
3
Check explicit input
A supplied tag is accepted directly and bypasses automatic generation.
completed
4
Select implementation
Without an explicit tag, WorkflowEngine dispatches to the concrete strategy for the selected enum value.
current
5
Generate the value
The strategy reads only the repository or project inputs it needs and returns the next tag string.
pending
6
Apply and consume
Later workflow phases update version files, generate changelog context, create the Git tag, and optionally push it.
pending

Tag Sorting Family

Existing-Tag Ordering

GitService→TagSorterFactory

Requests a sorter that matches the active version strategy.


TagSorterFactory→SemverSorter

Orders semantic-version tags.


TagSorterFactory→PEP440Sorter

Orders PEP 440-compatible tags.


TagSorterFactory→DateSorter

Orders date-based tags.


TagSorterFactory→GitCountSorter

Orders commit-count tags.

GitService detects or receives a project strategy, creates the matching sorter, and caches it for later tag queries. Commitizen does not have a separate sorter: its generated versions use semantic-version behavior, so compatible tags are ordered through the SemVer path.


Extension Boundary

Adding a source-owned generation strategy requires more than implementing get_next_tag(). The contributor must also extend the strategy choice enum, workflow dispatch, CLI and configuration resolution, tests, and documentation. If the resulting tag format needs special ordering, the sorter family and factory require a corresponding implementation too.


Continue