rewriter

package
v0.15.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindSectionEnd

func FindSectionEnd(lines []string, startIndex int) int

FindSectionEnd returns the exclusive index of the first ## line after startIndex, or len(lines) if none — matching changelog-rewriter.js findSectionEnd.

func RewriteSection

func RewriteSection(content []byte, rewrite SectionRewrite, mode RewriteMode, targetVersion string) ([]byte, error)

RewriteSection mirrors rewriteChangelogSection from changelog-rewriter.js.

When mode is ModeRelease, targetVersion is the semver without a leading 'v'; otherwise it is ignored.

RewriteSection returns an error when mode is unrecognized.

func UpdateLinks(content []byte, entries []LinkEntry) ([]byte, error)

UpdateLinks applies rewriteLinkTable from changelog-rewriter.js for each entry (sequentially).

Behaviour details (mirrors JS exactly for one entry — the common case): only the [Unreleased] line anchors mutation; inserting a missing [targetVersion]: line nests it adjacent to Unreleased, preserving ordering of unrelated link lines afterward.

Types

type LinkEntry

type LinkEntry struct {
	TargetVersion string
	PreviousTag   string // with leading 'v', e.g. v0.14.5
}

LinkEntry is one release bump for the changelog compare link table ([Unreleased]: / [x.y.z]: lines).

type RewriteMode

type RewriteMode int

RewriteMode selects which CHANGELOG section heading rewriteChangelogSection targets.

const (
	// ModeUnreleased updates the ## [Unreleased] section.
	ModeUnreleased RewriteMode = iota
	// ModeRelease updates by target version (and may remove Unreleased in the same pass).
	ModeRelease
)

type SectionRewrite

type SectionRewrite struct {
	// Header is the literal heading without the leading "## ", e.g.
	// "[Unreleased]" or "[1.2.3] - 2025-05-01".
	Header string
	// Body is the Markdown rendered under Header (parity with changelog-rewriter.js: pasted verbatim).
	Body string
}

SectionRewrite describes a CHANGELOG release or Unreleased section to write in place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL