scripts

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package scripts provides CHANGELOG.md generation utilities.

Package scripts provides banner generation utilities for release management.

Package scripts provides release entry generation utilities for the changelog site.

Package scripts provides release notes generation utilities for the changelog site.

Package scripts provides version extraction utilities for release management.

Index

Constants

View Source
const DefaultProjectName = "Narvana"

DefaultProjectName is the default project name used in titles and closings.

View Source
const SectionItemIndent = "- "

FormatSectionItem formats a single commit or group for display in release notes. It uses consistent indentation (bullet point with space) for all items.

Variables

View Source
var ErrInvalidVersion = errors.New("invalid semantic version format")

ErrInvalidVersion is returned when a version string doesn't match semantic versioning format.

View Source
var KeywordMapping = map[string]FeatureArea{

	"build":    FeatureAreaBuildSystem,
	"nix":      FeatureAreaBuildSystem,
	"flake":    FeatureAreaBuildSystem,
	"compile":  FeatureAreaBuildSystem,
	"makefile": FeatureAreaBuildSystem,

	"deploy":     FeatureAreaDeployment,
	"deployment": FeatureAreaDeployment,
	"release":    FeatureAreaDeployment,
	"rollout":    FeatureAreaDeployment,

	"auth":           FeatureAreaAuthentication,
	"authentication": FeatureAreaAuthentication,
	"login":          FeatureAreaAuthentication,
	"logout":         FeatureAreaAuthentication,
	"session":        FeatureAreaAuthentication,
	"token":          FeatureAreaAuthentication,
	"oauth":          FeatureAreaAuthentication,
	"rbac":           FeatureAreaAuthentication,

	"api":      FeatureAreaAPI,
	"endpoint": FeatureAreaAPI,
	"rest":     FeatureAreaAPI,
	"openapi":  FeatureAreaAPI,
	"handler":  FeatureAreaAPI,

	"database":  FeatureAreaDatabase,
	"db":        FeatureAreaDatabase,
	"migration": FeatureAreaDatabase,
	"postgres":  FeatureAreaDatabase,
	"sql":       FeatureAreaDatabase,
	"query":     FeatureAreaDatabase,
	"store":     FeatureAreaDatabase,

	"ui":        FeatureAreaUserInterface,
	"web":       FeatureAreaUserInterface,
	"dashboard": FeatureAreaUserInterface,
	"frontend":  FeatureAreaUserInterface,
	"page":      FeatureAreaUserInterface,
	"template":  FeatureAreaUserInterface,
	"templ":     FeatureAreaUserInterface,

	"config":   FeatureAreaConfiguration,
	"settings": FeatureAreaConfiguration,
	"env":      FeatureAreaConfiguration,
	"secret":   FeatureAreaConfiguration,
	"secrets":  FeatureAreaConfiguration,

	"docker":     FeatureAreaContainerization,
	"container":  FeatureAreaContainerization,
	"podman":     FeatureAreaContainerization,
	"oci":        FeatureAreaContainerization,
	"image":      FeatureAreaContainerization,
	"dockerfile": FeatureAreaContainerization,

	"grpc":      FeatureAreaCommunication,
	"websocket": FeatureAreaCommunication,
	"socket":    FeatureAreaCommunication,
	"stream":    FeatureAreaCommunication,
	"proto":     FeatureAreaCommunication,
	"protobuf":  FeatureAreaCommunication,

	"scheduler": FeatureAreaScheduler,
	"schedule":  FeatureAreaScheduler,
	"queue":     FeatureAreaScheduler,
	"job":       FeatureAreaScheduler,
	"worker":    FeatureAreaScheduler,

	"log":     FeatureAreaLogging,
	"logs":    FeatureAreaLogging,
	"logging": FeatureAreaLogging,
	"logger":  FeatureAreaLogging,

	"security":   FeatureAreaSecurity,
	"encrypt":    FeatureAreaSecurity,
	"encryption": FeatureAreaSecurity,
	"sops":       FeatureAreaSecurity,
	"tls":        FeatureAreaSecurity,
	"ssl":        FeatureAreaSecurity,

	"test":  FeatureAreaTesting,
	"tests": FeatureAreaTesting,

	"doc":           FeatureAreaDocumentation,
	"docs":          FeatureAreaDocumentation,
	"documentation": FeatureAreaDocumentation,
	"readme":        FeatureAreaDocumentation,
}

KeywordMapping maps keywords to feature areas. Keywords are matched case-insensitively against commit descriptions.

View Source
var MajorReleaseTitles = map[int]string{
	1: "The Beginning",
	2: "A New World",
	3: "The Next Chapter",
	4: "Rising Higher",
	5: "Breaking Boundaries",
}

MajorReleaseTitles provides creative title templates for major releases. The key is the major version number, and the value is the creative title.

View Source
var SectionHeaders = map[ReleaseSection]string{
	SectionFeatures:        "![rocket](../../assets/icons/rocket.svg) New Features & Enhancements",
	SectionImprovements:    "![bolt](../../assets/icons/bolt.svg) Performance & Improvements",
	SectionBugFixes:        "![bug](../../assets/icons/bug.svg) Bug Fixes",
	SectionBreakingChanges: "![warning](../../assets/icons/warning.svg) Breaking Changes",
	SectionOther:           "![box](../../assets/icons/box.svg) Other Changes",
}

SectionHeaders maps each section to its icon-enhanced header. These headers are used when generating the release notes markdown. Uses Font Awesome SVG icons for visual appeal.

Functions

func BannerContainsBranding

func BannerContainsBranding(svg, brandName string) bool

BannerContainsBranding checks if the SVG banner contains the brand name. The check is case-insensitive since the brand name may be uppercased in the SVG.

func BannerContainsVersion

func BannerContainsVersion(svg, version string) bool

BannerContainsVersion checks if the SVG banner contains the version number as visible text.

func BannerHasGradient

func BannerHasGradient(svg string) bool

BannerHasGradient checks if the SVG banner has a gradient background.

func ChangelogContainsVersion

func ChangelogContainsVersion(changelog, version string) bool

ChangelogContainsVersion checks if a changelog already contains a specific version.

func CleanDescription

func CleanDescription(desc string) string

CleanDescription processes a commit description for display. - Removes commit hashes in parentheses (abc123) - Removes leading "Add ", "Update ", "Fix " prefixes - Capitalizes first letter - Adds period if missing punctuation at end

func ContainsHash

func ContainsHash(desc string) bool

ContainsHash checks if description contains a commit hash pattern in parentheses.

func CreateNewChangelog

func CreateNewChangelog(entry ChangelogEntry) (string, error)

CreateNewChangelog creates a new changelog with a single entry.

func CustomBannerExists

func CustomBannerExists(version string) bool

CustomBannerExists checks if a custom banner exists for the given version.

func EnsureOtherCommitsPreserved

func EnsureOtherCommitsPreserved(commits []ParsedCommit, content CategorizedContent) bool

EnsureOtherCommitsPreserved ensures that commits with type "other" are properly preserved in the categorized content. This is a validation function that can be used to verify the fallback behavior is working correctly.

func ExtractKeyFeatures

func ExtractKeyFeatures(commits []ParsedCommit) []string

ExtractKeyFeatures identifies the main features from a group of commits. It extracts unique, meaningful descriptions from the commits, removing duplicates and preserving important technical details.

func ExtractMajorVersion

func ExtractMajorVersion(version string) int

ExtractMajorVersion extracts the major version number from a version string. Returns -1 if the version string is invalid.

func ExtractVersionString

func ExtractVersionString(tag string) (string, error)

ExtractVersionString extracts a version string from a git tag without the 'v' prefix. Returns the version in MAJOR.MINOR.PATCH format.

func ExtractVersionsFromChangelog

func ExtractVersionsFromChangelog(changelog string) []string

ExtractVersionsFromChangelog extracts all version numbers from a changelog.

func FormatCommit

func FormatCommit(commit ParsedCommit) string

FormatCommit formats a ParsedCommit back to conventional commit string. This enables round-trip testing: parse(format(commit)) should equal commit.

func FormatSection

func FormatSection(section ReleaseSection, groups []CommitGroup) string

FormatSection formats a complete section with header and items. Returns empty string if the section has no items.

func FormatSectionItems

func FormatSectionItems(groups []CommitGroup) []string

FormatSectionItems formats all items in a section with consistent indentation. Each item is prefixed with "- " for bullet point formatting.

func GenerateBannerFilename

func GenerateBannerFilename(version string) string

GenerateBannerFilename generates the filename for a release banner. Example: "1.0.0" -> "release-1_0_0.svg"

func GenerateBannerPath

func GenerateBannerPath(version string) string

GenerateBannerPath generates the full path for a release banner in the changelog assets. Example: "1.0.0" -> "changelog/src/assets/release-1_0_0.svg"

func GenerateBannerRelativePath

func GenerateBannerRelativePath(version string) string

GenerateBannerRelativePath generates the relative path for a release banner from the content directory (changelog/src/content/releases/). This path format is compatible with Astro's image optimization. Example: "1.0.0" -> "../../assets/release-1_0_0.svg"

func GenerateBannerSVG

func GenerateBannerSVG(config BannerConfig) (string, error)

GenerateBannerSVG generates an SVG banner for a release version.

func GenerateBothBanners

func GenerateBothBanners(version, brandName, outputDir string) (contentPath, socialPath string, err error)

GenerateBothBanners generates both content and social media banners for a version. Returns the paths to both generated files.

func GenerateChangelogEntry

func GenerateChangelogEntry(entry ChangelogEntry) (string, error)

GenerateChangelogEntry generates a single changelog entry in conventional format.

func GenerateChangelogLink(entry ChangelogEntry) (string, error)

GenerateChangelogLink generates a version link for the changelog footer.

func GenerateClosing

func GenerateClosing(projectName string, override string) string

GenerateClosing creates the closing paragraph for release notes. Only returns content if an override is provided; otherwise returns empty string. The closing appears at the end of the release notes, after all sections.

func GenerateCustomBannerRelativePath

func GenerateCustomBannerRelativePath(version string) string

GenerateCustomBannerRelativePath generates the relative path for a custom release banner from the content directory (changelog/src/content/releases/). This path format is compatible with Astro's image optimization. Example: "1.0.0" -> "../../assets/custom/release-1_0_0.svg"

func GenerateIntroduction

func GenerateIntroduction(override string) string

GenerateIntroduction creates the introduction paragraph for release notes. Only returns content if an override is provided; otherwise returns empty string. The introduction appears at the beginning of the release notes, before any sections.

func GenerateReleaseEntry

func GenerateReleaseEntry(entry ReleaseEntry) (string, error)

GenerateReleaseEntry generates a release entry markdown file content.

func GenerateReleaseFilename

func GenerateReleaseFilename(version string) string

GenerateReleaseFilename generates the filename for a release entry. Example: "1.0.0" -> "1_0_0.md"

func GenerateReleaseNotes

func GenerateReleaseNotes(content CategorizedContent, config ReleaseNotesConfig) (string, error)

GenerateReleaseNotes produces the final markdown release notes. It accepts CategorizedContent and config, generating complete markdown with frontmatter, banner image reference, optional introduction, sections, and optional closing.

func GenerateSocialBannerFilename

func GenerateSocialBannerFilename(version string) string

GenerateSocialBannerFilename generates the filename for a social media release banner. Example: "1.0.0" -> "release-1_0_0-social.svg"

func GenerateSocialBannerPath

func GenerateSocialBannerPath(version string) string

GenerateSocialBannerPath generates the full path for a social media banner. Example: "1.0.0" -> "changelog/src/assets/release-1_0_0-social.svg"

func GenerateTitle

func GenerateTitle(version string, override string) string

GenerateTitle creates a title based on version and optional override. If an override is provided (non-empty), it is used regardless of version. For major versions (X.0.0), a creative title is generated. For minor/patch versions, the standard "Narvana vX.Y.Z" format is used.

func GetBannerDimensions

func GetBannerDimensions(size BannerSize) (width, height int)

GetBannerDimensions returns width and height for a given banner size.

func GetBannerPath

func GetBannerPath(version string) string

GetBannerPath returns the appropriate banner path, preferring custom over generated. If a custom banner exists, returns the custom path; otherwise returns the generated path.

func GetCustomBannerPath

func GetCustomBannerPath(version string) string

GetCustomBannerPath returns the path where a custom banner would be located.

func GetEffectiveScope

func GetEffectiveScope(commit ParsedCommit) string

GetEffectiveScope returns the scope to use for grouping a commit. If the commit has an explicit scope, it returns that scope. Otherwise, it falls back to the detected feature area from keywords. This ensures explicit scopes take priority over keyword matching.

func GetMajorVersionTitle

func GetMajorVersionTitle(majorVersion int) string

GetMajorVersionTitle returns a creative title for a major release. For known major versions, it returns a predefined creative title. For unknown major versions, it generates a generic creative title.

func HasRequiredFrontmatterFields

func HasRequiredFrontmatterFields(frontmatter map[string]string) bool

HasRequiredFrontmatterFields checks if the frontmatter contains all required fields.

func IsMajorRelease

func IsMajorRelease(version string) bool

IsMajorRelease checks if a version string represents a major release (X.0.0). A major release is defined as a version where both minor and patch are zero. Accepts versions with or without "v" prefix (e.g., "1.0.0" or "v1.0.0").

func IsNoiseCommit

func IsNoiseCommit(commit ParsedCommit, config NoiseFilterConfig) bool

IsNoiseCommit checks if a single commit is noise based on the config. A commit is noise if its type is in the excluded types list OR if its description matches any of the noise patterns.

func IsValidCommitType

func IsValidCommitType(t string) bool

IsValidCommitType checks if a string is a valid commit type.

func IsValidSemver

func IsValidSemver(tag string) bool

IsValidSemver checks if a string is a valid semantic version (with or without 'v' prefix).

func ParseReleaseEntryFrontmatter

func ParseReleaseEntryFrontmatter(markdown string) (map[string]string, error)

ParseReleaseEntryFrontmatter extracts frontmatter fields from generated markdown. Returns a map of field names to values.

func PrependChangelogEntry

func PrependChangelogEntry(existingChangelog string, entry ChangelogEntry) (string, error)

PrependChangelogEntry prepends a new entry to an existing changelog. It preserves the header and inserts the new entry after it.

func PreserveMarkdownFormatting

func PreserveMarkdownFormatting(content string) string

PreserveMarkdownFormatting ensures markdown formatting is preserved in release notes. This is a pass-through function that validates the content is not corrupted.

func ResolveBannerPath

func ResolveBannerPath(version string) (string, bool)

ResolveBannerPath resolves the banner path with custom banner precedence. Returns (path, isCustom) where isCustom indicates if a custom banner was found.

func ResolveBannerRelativePath

func ResolveBannerRelativePath(version string) string

ResolveBannerRelativePath resolves the banner relative path with custom banner precedence. Returns the relative path suitable for use in markdown frontmatter. If a custom banner exists, returns the custom path; otherwise returns the generated path. The returned path is relative to the content directory and compatible with Astro image optimization.

func SectionHeader

func SectionHeader(section ReleaseSection) string

SectionHeader returns the icon-enhanced header for a section. Returns the appropriate header with icon prefix based on the section type.

func ShouldSummarize

func ShouldSummarize(group CommitGroup) bool

ShouldSummarize returns true if a group should be summarized. Groups with more than 3 commits should produce a summary instead of listing each commit.

func SummarizeGroup

func SummarizeGroup(group CommitGroup) string

SummarizeGroup creates a high-level summary for a commit group. For groups with more than 3 commits, it creates a concise summary paragraph that extracts key functionality rather than listing every implementation detail. It preserves important technical details that affect users.

func ValidateBannerRelativePath

func ValidateBannerRelativePath(path string) error

ValidateBannerRelativePath checks if a banner relative path has the correct format for Astro image optimization. The path should: - Start with "../../assets/" - End with ".svg"

func ValidateBannerSVG

func ValidateBannerSVG(svg string) error

ValidateBannerSVG checks if the generated SVG is valid and contains required elements.

func ValidateMarkdownPreservation

func ValidateMarkdownPreservation(original, processed string) bool

ValidateMarkdownPreservation checks if markdown elements are preserved.

func ValidateReleaseEntry

func ValidateReleaseEntry(entry ReleaseEntry) error

ValidateReleaseEntry validates that a release entry has all required fields.

func VersionToUnderscore

func VersionToUnderscore(version string) string

VersionToUnderscore converts a version string to underscore format for filenames. Example: "1.2.3" -> "1_2_3"

func WriteBannerToFile

func WriteBannerToFile(config BannerConfig) error

WriteBannerToFile generates a banner and writes it to a file.

Types

type BannerConfig

type BannerConfig struct {
	Version    string // Version number to display (e.g., "1.0.0")
	Width      int    // SVG width in pixels
	Height     int    // SVG height in pixels
	BrandName  string // Brand name to display (e.g., "Narvana")
	OutputPath string // Output file path
}

BannerConfig holds configuration for banner generation.

func DefaultBannerConfig

func DefaultBannerConfig() BannerConfig

DefaultBannerConfig returns a BannerConfig with default values. Uses 800x200 dimensions optimized for content banners.

func SocialMediaBannerConfig

func SocialMediaBannerConfig() BannerConfig

SocialMediaBannerConfig returns a BannerConfig optimized for social media sharing. Uses 1200x630 dimensions (Open Graph standard for Twitter/Facebook/LinkedIn).

type BannerSize

type BannerSize string

BannerSize represents predefined banner size options.

const (
	// BannerSizeContent is the default size for content banners (800x200)
	BannerSizeContent BannerSize = "content"
	// BannerSizeSocial is the size for social media sharing (1200x630)
	BannerSizeSocial BannerSize = "social"
)

type CategorizedContent

type CategorizedContent struct {
	Features        []CommitGroup // New features (feat commits)
	Improvements    []CommitGroup // Performance improvements (perf commits)
	BugFixes        []CommitGroup // Bug fixes (fix commits)
	BreakingChanges []CommitGroup // Breaking changes (commits with BreakingChange=true)
	Other           []CommitGroup // Other changes (remaining commits)
}

CategorizedContent holds commits organized by section. This is the result of categorizing commit groups into release note sections.

func CategorizeCommits

func CategorizeCommits(groups []CommitGroup) CategorizedContent

CategorizeCommits organizes commit groups into sections based on commit types. - feat commits go to Features - fix commits go to BugFixes - perf commits go to Improvements - Commits with BreakingChange=true go to BreakingChanges (regardless of type) - Remaining commits go to Other

Note: A commit with BreakingChange=true will appear in BreakingChanges AND its type-appropriate section (e.g., a breaking feat will be in both Features and BreakingChanges).

func CategorizeCommitsByType

func CategorizeCommitsByType(commits []ParsedCommit) CategorizedContent

CategorizeCommitsByType is a simpler categorization that works directly on commits without pre-grouping. It groups commits by type first, then by scope within each section.

func CategorizeCommitsWithFallback

func CategorizeCommitsWithFallback(groups []CommitGroup) CategorizedContent

CategorizeCommitsWithFallback categorizes commit groups into sections with fallback handling. If normal categorization fails, it falls back to placing all commits in the "Other" section. This ensures the release notes generation never fails due to categorization errors.

func ProcessCommitsWithFallback

func ProcessCommitsWithFallback(rawCommits []string, filterConfig NoiseFilterConfig) CategorizedContent

ProcessCommitsWithFallback is a high-level function that processes raw commit messages through the entire pipeline with fallback handling at each stage. It parses, filters, groups, and categorizes commits, ensuring graceful degradation at each step if errors occur.

func (CategorizedContent) GetSectionGroups

func (c CategorizedContent) GetSectionGroups(section ReleaseSection) []CommitGroup

GetSectionGroups returns the commit groups for a given section.

func (CategorizedContent) HasContent

func (c CategorizedContent) HasContent() bool

HasContent returns true if any section has commits. Used to determine if there's any content to render in the release notes.

func (CategorizedContent) NonEmptySections

func (c CategorizedContent) NonEmptySections() []ReleaseSection

NonEmptySections returns a list of sections that have content. Useful for iterating only over sections that should be rendered.

type ChangelogEntry

type ChangelogEntry struct {
	Version      string    // e.g., "1.0.0"
	Date         time.Time // Release date
	ReleaseURL   string    // URL to the GitHub release
	ReleaseNotes string    // Release notes content (markdown)
}

ChangelogEntry represents a single release entry in the changelog.

type CommitGroup

type CommitGroup struct {
	Name      string         // Group name (scope or detected feature area)
	Commits   []ParsedCommit // Commits in this group
	Summary   string         // Merged summary of changes (for groups > 3 commits)
	IsSummary bool           // Whether this group uses a summary vs individual list
}

CommitGroup represents a group of related commits. Commits are grouped by their effective scope (explicit scope or detected feature area).

func GroupCommits

func GroupCommits(commits []ParsedCommit) []CommitGroup

GroupCommits groups commits by their effective scope. Commits with the same effective scope are placed in the same group. Groups track whether they should be summarized (>3 commits).

func GroupCommitsWithFallback

func GroupCommitsWithFallback(commits []ParsedCommit) []CommitGroup

GroupCommitsWithFallback groups commits by their effective scope with fallback handling. If grouping fails for any reason, it falls back to listing commits by type without grouping. This ensures the release notes generation never fails due to grouping errors.

type CommitType

type CommitType string

CommitType represents the type of change in a conventional commit.

const (
	CommitTypeFeat     CommitType = "feat"
	CommitTypeFix      CommitType = "fix"
	CommitTypeDocs     CommitType = "docs"
	CommitTypeStyle    CommitType = "style"
	CommitTypeRefactor CommitType = "refactor"
	CommitTypePerf     CommitType = "perf"
	CommitTypeTest     CommitType = "test"
	CommitTypeBuild    CommitType = "build"
	CommitTypeCI       CommitType = "ci"
	CommitTypeChore    CommitType = "chore"
	CommitTypeOther    CommitType = "other"
)

func AllCommitTypes

func AllCommitTypes() []CommitType

AllCommitTypes returns all valid commit types.

type FeatureArea

type FeatureArea string

FeatureArea represents a detected feature area for grouping commits.

const (
	FeatureAreaBuildSystem      FeatureArea = "Build System"
	FeatureAreaDeployment       FeatureArea = "Deployment"
	FeatureAreaAuthentication   FeatureArea = "Authentication"
	FeatureAreaAPI              FeatureArea = "API"
	FeatureAreaDatabase         FeatureArea = "Database"
	FeatureAreaUserInterface    FeatureArea = "User Interface"
	FeatureAreaConfiguration    FeatureArea = "Configuration"
	FeatureAreaContainerization FeatureArea = "Containerization"
	FeatureAreaCommunication    FeatureArea = "Communication"
	FeatureAreaScheduler        FeatureArea = "Scheduler"
	FeatureAreaLogging          FeatureArea = "Logging"
	FeatureAreaSecurity         FeatureArea = "Security"
	FeatureAreaTesting          FeatureArea = "Testing"
	FeatureAreaDocumentation    FeatureArea = "Documentation"
	FeatureAreaOther            FeatureArea = "Other"
)

func DetectFeatureArea

func DetectFeatureArea(commit ParsedCommit) FeatureArea

DetectFeatureArea analyzes a commit description to detect feature area. It matches keywords case-insensitively and returns the first matching feature area. If no keywords match or multiple conflicting keywords are found, it returns FeatureAreaOther.

type FilterResult

type FilterResult struct {
	Commits       []ParsedCommit // Commits that passed the filter
	OriginalCount int            // Original number of commits before filtering
	FilteredCount int            // Number of commits that passed the filter
	NoiseCommits  []ParsedCommit // Commits that were filtered out
}

FilterResult contains filtered commits and statistics.

func FilterCommits

func FilterCommits(commits []ParsedCommit, config NoiseFilterConfig) FilterResult

FilterCommits removes noise commits from the list based on the config. It filters by excluded types and noise patterns, preserving the original count.

type NoiseFilterConfig

type NoiseFilterConfig struct {
	ExcludedTypes []CommitType // Types to always exclude (chore, style, ci, test)
	NoisePatterns []string     // Regex patterns for noise descriptions
	PreserveStats bool         // Whether to track original count
}

NoiseFilterConfig holds configuration for filtering noise commits.

func DefaultNoiseFilterConfig

func DefaultNoiseFilterConfig() NoiseFilterConfig

DefaultNoiseFilterConfig returns the default noise filter configuration. Excludes chore, style, ci, test types and common noise patterns.

type OverrideContent

type OverrideContent struct {
	Title        string // Custom title for the release
	Introduction string // Custom introduction paragraph
	Closing      string // Custom closing paragraph
}

OverrideContent holds parsed override file content. Override files allow customization of release notes with custom titles, introductions, and closing messages.

func ParseOverrideContent

func ParseOverrideContent(content string) (*OverrideContent, error)

ParseOverrideContent parses override content from a string. This is separated from ParseOverrideFile to allow testing without file I/O.

func ParseOverrideFile

func ParseOverrideFile(path string) (*OverrideContent, error)

ParseOverrideFile reads and parses an override file. Override files use YAML frontmatter format with optional title, introduction, and closing fields. If the file doesn't exist or is malformed, it returns nil without error (graceful fallback). Returns an error only for unexpected I/O errors.

type ParsedCommit

type ParsedCommit struct {
	Type           CommitType // The type of commit (feat, fix, etc.)
	Scope          string     // Optional scope in parentheses
	Description    string     // The commit description
	Body           string     // Optional commit body
	BreakingChange bool       // Whether this is a breaking change
	Hash           string     // Short commit hash (for reference only, not displayed)
	Raw            string     // Original raw commit message
}

ParsedCommit represents a parsed conventional commit.

func ParseCommit

func ParseCommit(raw string) ParsedCommit

ParseCommit parses a raw commit message into structured form. It handles the conventional commit format: type(scope): description If the message doesn't match the format, it returns a commit with type "other".

func ParseCommitWithFallback

func ParseCommitWithFallback(raw string) ParsedCommit

ParseCommitWithFallback parses a raw commit message with fallback handling. If parsing fails or produces an "other" type commit, it ensures the raw message is preserved for display in the "Other Changes" section. This function wraps ParseCommit and ensures graceful degradation.

func ParseCommitsWithFallback

func ParseCommitsWithFallback(rawCommits []string) []ParsedCommit

ParseCommitsWithFallback parses multiple raw commit messages with fallback handling. Any commits that fail to parse are categorized as "other" with their raw message preserved. This ensures the release notes generation never fails due to unparseable commits.

type ParsedReleaseNotes

type ParsedReleaseNotes struct {
	Frontmatter  ReleaseNotesFrontmatter
	Introduction string
	Sections     map[ReleaseSection][]string // Section -> list of items
	Closing      string
}

ParsedReleaseNotes represents the parsed structure of release notes. This is used for round-trip testing to verify the structure can be reconstructed.

type ReleaseEntry

type ReleaseEntry struct {
	Title         string    // e.g., "Narvana v1.0.0"
	Date          time.Time // Release date
	VersionNumber string    // e.g., "1.0.0"
	Description   string    // Brief summary of the release
	ImagePath     string    // Path to banner image (relative to markdown file)
	ImageAlt      string    // Alt text for banner image
	Content       string    // Release notes content (markdown)
}

ReleaseEntry represents the data needed to generate a release entry markdown file.

func NewReleaseEntryFromTag

func NewReleaseEntryFromTag(tag string, releaseNotes string, releaseDate time.Time) (ReleaseEntry, error)

NewReleaseEntryFromTag creates a ReleaseEntry from a git tag and release notes.

type ReleaseNotesConfig

type ReleaseNotesConfig struct {
	Version      string // The version number (e.g., "1.0.0" or "v1.0.0")
	Date         string // The release date in YYYY-MM-DD format
	Title        string // Optional custom title (from override file)
	Introduction string // Optional custom introduction (from override file)
	Closing      string // Optional custom closing (from override file)
	BannerPath   string // Path to banner image (relative to content directory)
	ProjectName  string // Project name for templates (default: "Narvana")
}

ReleaseNotesConfig holds configuration for generating release notes. It contains all the information needed to produce a complete release entry.

type ReleaseNotesFrontmatter

type ReleaseNotesFrontmatter struct {
	Title         string                       `yaml:"title"`
	Date          string                       `yaml:"date"`
	VersionNumber string                       `yaml:"versionNumber"`
	Description   string                       `yaml:"description"`
	Image         ReleaseNotesFrontmatterImage `yaml:"image"`
}

ReleaseNotesFrontmatter represents the YAML frontmatter for a release entry.

func ParseReleaseNotesFrontmatter

func ParseReleaseNotesFrontmatter(markdown string) (*ReleaseNotesFrontmatter, string, error)

ParseReleaseNotesFrontmatter extracts frontmatter from release notes markdown. It returns the frontmatter struct and the remaining content after frontmatter.

type ReleaseNotesFrontmatterImage

type ReleaseNotesFrontmatterImage struct {
	Src string `yaml:"src"`
	Alt string `yaml:"alt"`
}

ReleaseNotesFrontmatterImage represents the image field in frontmatter.

type ReleaseSection

type ReleaseSection string

ReleaseSection represents a section in the release notes. Each section groups commits by their semantic meaning (features, fixes, etc.).

const (
	SectionFeatures        ReleaseSection = "features"
	SectionImprovements    ReleaseSection = "improvements"
	SectionBugFixes        ReleaseSection = "bugfixes"
	SectionBreakingChanges ReleaseSection = "breaking"
	SectionOther           ReleaseSection = "other"
)

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version represents a semantic version with major, minor, and patch components.

func ExtractVersion

func ExtractVersion(tag string) (Version, error)

ExtractVersion extracts a semantic version from a git tag. It handles the 'v' prefix removal and validates the semantic version format. Valid inputs: "v1.2.3", "1.2.3", "v0.0.1" Invalid inputs: "v1.2", "1.2.3.4", "abc", ""

func (Version) String

func (v Version) String() string

String returns the version as a string in MAJOR.MINOR.PATCH format.

Jump to

Keyboard shortcuts

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