repomatic.github.release_sync module

Sync GitHub release notes from changelog.md.

Compares each GitHub release body against the corresponding changelog.md section and updates any that have drifted. changelog.md is the single source of truth.

repomatic.github.release_sync.build_expected_body(changelog, version, *, admonition_override=None)[source]

Build the expected release body from the changelog.

Decomposes the changelog section into discrete elements and renders them through the github-releases template. This allows the GitHub release body to include a different subset of elements than the release-notes template used for changelog.md entries.

Lives here, with the release publishers, rather than in repomatic.changelog: every caller is a GitHub-release writer (this sync, the dev pre-release, the release-notes metadata keys), and the changelog module renders changelog entries, not release bodies. The release draft is one more: see build_draft_body().

Parameters:
  • changelog (Changelog) – Parsed changelog instance.

  • version (str) – Version string, like 1.2.3.

  • admonition_override (str | None) – If provided, replaces the availability_admonition from the changelog. Used by build_pypi_body() to inject a pre-computed admonition at release time.

Return type:

str

Returns:

The rendered release body, or empty string if the version has no changelog section.

repomatic.github.release_sync.build_pypi_body(changelog, version, package_name)[source]

Build the release body of a version published on PyPI.

The body of build_expected_body(), with the availability admonition linking to PyPI and GitHub injected before fix-changelog writes it into changelog.md. The admonition comes from availability_admonition(), the renderer fix-changelog writes the section with, so both word it the same way.

The draft cannot ask the platforms which release came first: the PyPI upload runs beside it, and a failed lookup reads like an empty one. The changelog answers instead, as lint-changelog will once both platforms carry the release.

Parameters:
  • changelog (Changelog) – Parsed changelog instance.

  • version (str) – Version string, like 1.2.3.

  • package_name (str) – The project name on PyPI.

Return type:

str

Returns:

The rendered body, or an empty string when the changelog names no repository or holds no section for version.

repomatic.github.release_sync.build_draft_body(changelog, version, package_name)[source]

Build the body a release draft is created with.

The body carries the PyPI availability admonition from the start: baking it into the draft, rather than editing the release from the caller’s fast publish-pypi lane, avoids a race between the lanes. That edit can run before the draft exists. The bake is optimistic: it assumes the parallel PyPI upload succeeds, which it does on the normal path, and a failed upload surfaces as a red publish-pypi job.

Parameters:
  • changelog (Changelog) – Parsed changelog instance.

  • version (str) – Version string, like 1.2.3.

  • package_name (str | None) – The project name on PyPI, or None for a project that does not publish there.

Return type:

str

Returns:

build_pypi_body() for a PyPI project, else build_expected_body(). Empty when the changelog holds no section for version.

class repomatic.github.release_sync.SyncRow(action, version, release_url)[source]

Bases: object

Per-release detail for the markdown report table.

action: ReportAction
version: str
release_url: str
class repomatic.github.release_sync.SyncResult(dry_run=True, rows=list(), total=0, in_sync=0, drifted=0, updated=0, failed=0, missing_changelog=0)[source]

Bases: object

Accumulated results from a release-notes sync run.

dry_run: bool = True
rows: list[SyncRow]
total: int = 0
in_sync: int = 0
drifted: int = 0
updated: int = 0
failed: int = 0
missing_changelog: int = 0
repomatic.github.release_sync.sync_github_releases(repo_url, changelog_path, dry_run=True)[source]

Sync GitHub release bodies from changelog.md.

For each released version in the changelog, compares the expected body (from changelog.md) with the actual GitHub release body. In live mode, updates drifted releases via gh release edit.

Live mode reads the release bodies fresh rather than from the day-long cache: an edit decided against a stale body would rewrite a release that already matches, or miss one that drifted since.

Parameters:
  • repo_url (str) – Repository URL (like https://github.com/user/repo).

  • changelog_path (Path) – Path to changelog.md.

  • dry_run (bool) – If True, report without making changes.

Return type:

SyncResult

Returns:

Structured sync results.

repomatic.github.release_sync.render_sync_report(result)[source]

Render a markdown report from sync results.

Parameters:

result (SyncResult) – Structured results from the sync run.

Return type:

str

Returns:

Markdown report string.