source

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package source fetches release notes for a tool's versions. Each changelog source kind is an Adapter; gh-release reads GitHub release bodies.

Index

Constants

View Source
const (
	KindGHRelease      = "gh-release"
	KindChangelogFile  = "changelog-file"
	KindStructuredJSON = "structured-json"
	KindWebDoc         = "web-doc"
	KindUpgradeGuide   = "upgrade-guide"
	KindUpgradeNotes   = "upgrade-notes"
)

Adapter kinds, as named in registry entries.

View Source
const (
	HeadingUpgradeGuide = "Upgrade guide"
	HeadingUpgradeNotes = "Upgrade notes"
)

Headings that upgrade documents are filed under. The classifier reads both as breaking.

Variables

View Source
var ErrNotFound = errors.New("page not found")

ErrNotFound is wrapped by Web errors for pages that don't exist.

Functions

func Boilerplate

func Boilerplate(body string) bool

Boilerplate reports whether a release body carries no notes of its own: it is under 400 bytes, or it holds only headings, links and checksums.

func Expand

func Expand(tmpl string, s version.Scheme, v version.Version) string

Expand fills a path or ref template: {version}, {major}, {minor} (the minor number alone) and {tag}.

func ExpandPrev

func ExpandPrev(tmpl string, s version.Scheme, v version.Version, prev version.V) string

ExpandPrev is Expand with {prev_minor} (the line, such as 3.5) and {prev_major} taken from prev, the version before v.

func FileURL

func FileURL(k mdindex.Key) string

FileURL returns the GitHub page of the file k names.

func NewFileCache

func NewFileCache(gh FileFetcher) *mdindex.Cache

NewFileCache returns an mdindex.Cache that reads files through gh. reStructuredText files get Markdown headings first.

func PickChangelog

func PickChangelog(files []github.File) (string, bool)

PickChangelog returns the changelog file of a repository's top directory. It prefers .md over .rst over .txt over other names, and never picks .json files or files under 100 bytes.

Types

type Adapter

type Adapter interface {
	Kind() string
	Fetch(ctx context.Context, t registry.ToolSpec, versions []version.Version) ([]VersionNotes, error)
}

Adapter fetches notes for versions. Versions without notes are left out, not errors.

type Auto

type Auto struct {
	// contains filtered or unexported fields
}

Auto finds notes for a tool without registry sources, as Renovate and Dependabot do: GitHub release bodies when the range has real ones, else a changelog file in the default branch, unless the file stops before the newest release. Without a usable file it keeps whatever release bodies there are.

func NewAuto

func NewAuto(logger *slog.Logger, gh ReleaseFetcher, lister RootLister, files *mdindex.Cache, newest version.V) *Auto

NewAuto returns an auto-discovery adapter; newest is the tool's newest stable version.

func (*Auto) Fetch

func (a *Auto) Fetch(ctx context.Context, t registry.ToolSpec, versions []version.Version) ([]VersionNotes, error)

Fetch returns the release bodies when one is more than boilerplate, else the notes of the changelog file, else the release bodies there are.

func (*Auto) Kind

func (a *Auto) Kind() string

Kind returns "auto".

func (*Auto) Warnings

func (a *Auto) Warnings() []string

Warnings says why a changelog file was ignored.

type ChangelogFile

type ChangelogFile struct {
	// contains filtered or unexported fields
}

ChangelogFile reads version sections from a changelog file in the tool's repository. Each file is fetched and parsed once through the shared cache.

func NewChangelogFile

func NewChangelogFile(logger *slog.Logger, cache *mdindex.Cache, s registry.Source) *ChangelogFile

NewChangelogFile returns a changelog-file adapter for the registry source s.

func (*ChangelogFile) Fetch

func (a *ChangelogFile) Fetch(
	ctx context.Context,
	t registry.ToolSpec,
	versions []version.Version,
) ([]VersionNotes, error)

Fetch returns the section of each version, in the order given. A missing file or a version without a heading is left out.

func (*ChangelogFile) Kind

func (a *ChangelogFile) Kind() string

Kind returns KindChangelogFile.

type FileFetcher

type FileFetcher interface {
	File(ctx context.Context, repo, ref, path string) ([]byte, error)
}

FileFetcher returns a file of a repository at a ref; github.Client implements it.

type GHRelease

type GHRelease struct {
	// contains filtered or unexported fields
}

GHRelease reads the GitHub release body of each version.

func NewGHRelease

func NewGHRelease(gh ReleaseFetcher) *GHRelease

NewGHRelease returns a gh-release adapter that fetches through gh.

func (*GHRelease) Fetch

func (a *GHRelease) Fetch(
	ctx context.Context,
	t registry.ToolSpec,
	versions []version.Version,
) ([]VersionNotes, error)

Fetch returns the non-empty release bodies of versions, in the order given.

func (*GHRelease) Kind

func (a *GHRelease) Kind() string

Kind returns KindGHRelease.

type PageCache

type PageCache struct {
	// contains filtered or unexported fields
}

PageCache fetches and parses each web page once. It is safe for concurrent use and lives as long as a digester.

func NewPageCache

func NewPageCache(web WebFetcher) *PageCache

NewPageCache returns a cache that fetches pages with web.

func (*PageCache) Get

func (c *PageCache) Get(ctx context.Context, rawURL string) (*htmlmd.Document, error)

Get returns the parsed page at rawURL. A failed fetch is remembered.

type Ref

type Ref struct {
	Adapter string   `json:"adapter"`
	URL     string   `json:"url"`
	Heading []string `json:"heading,omitempty"` // heading path inside the document
}

Ref says where a piece of notes came from.

type ReleaseFetcher

type ReleaseFetcher interface {
	ReleaseBodies(ctx context.Context, repo string, tags []string) (map[string]github.Release, error)
}

ReleaseFetcher returns releases by tag; github.Client implements it.

type RootLister

type RootLister interface {
	RootFiles(ctx context.Context, repo string) ([]github.File, error)
}

RootLister lists a repository's top directory; github.Client implements it.

type StructuredJSON

type StructuredJSON struct {
	// contains filtered or unexported fields
}

StructuredJSON reads one JSON document per version, from a repository file or an allowed URL, and turns its entries into a Markdown list grouped by a heading field.

func NewStructuredJSON

func NewStructuredJSON(logger *slog.Logger, files FileFetcher, web WebFetcher, s registry.Source) *StructuredJSON

NewStructuredJSON returns a structured-json adapter for the registry source s.

func (*StructuredJSON) Fetch

func (a *StructuredJSON) Fetch(
	ctx context.Context,
	t registry.ToolSpec,
	versions []version.Version,
) ([]VersionNotes, error)

Fetch returns the entries of each version, in the order given. A missing document or one without entries is left out.

func (*StructuredJSON) Kind

func (a *StructuredJSON) Kind() string

Kind returns KindStructuredJSON.

type UpgradeGuide

type UpgradeGuide struct {
	// contains filtered or unexported fields
}

UpgradeGuide attaches a whole upgrade document to the first version of each new release line in a range. A template with {minor} or {prev_minor} names one document per minor transition, otherwise one per major.

func NewUpgradeGuide

func NewUpgradeGuide(
	logger *slog.Logger,
	files *mdindex.Cache,
	pages *PageCache,
	s registry.Source,
	from version.V,
) *UpgradeGuide

NewUpgradeGuide returns an upgrade-guide adapter for the registry source s. from is the version before the range; it names the line the first transition starts from.

func (*UpgradeGuide) Fetch

func (a *UpgradeGuide) Fetch(
	ctx context.Context,
	t registry.ToolSpec,
	versions []version.Version,
) ([]VersionNotes, error)

Fetch returns the guide of each line transition in the range. Transitions without a document are left out.

func (*UpgradeGuide) Kind

func (a *UpgradeGuide) Kind() string

Kind returns KindUpgradeGuide.

type UpgradeNotes

type UpgradeNotes struct {
	// contains filtered or unexported fields
}

UpgradeNotes takes the section under a heading such as "Urgent Upgrade Notes" out of each version's changelog section, so those entries carry their own source and are classified as upgrade notes. It reads the file of the tool's changelog-file source.

func NewUpgradeNotes

func NewUpgradeNotes(
	logger *slog.Logger,
	cache *mdindex.Cache,
	s registry.Source,
	file *registry.Source,
) *UpgradeNotes

NewUpgradeNotes returns an upgrade-notes adapter for the registry source s that reads the changelog file source file names; nil means the tool has none.

func (*UpgradeNotes) Fetch

func (a *UpgradeNotes) Fetch(
	ctx context.Context,
	t registry.ToolSpec,
	versions []version.Version,
) ([]VersionNotes, error)

Fetch returns the upgrade notes of each version that has them, in the order given.

func (*UpgradeNotes) Kind

func (a *UpgradeNotes) Kind() string

Kind returns KindUpgradeNotes.

type VersionNotes

type VersionNotes struct {
	Version  version.Version
	Markdown string
	Line     int // 1-based line where Markdown starts in a file; 0 for release bodies
	Source   Ref
}

VersionNotes is the Markdown one source has for one version.

type Web

type Web struct {
	// contains filtered or unexported fields
}

Web fetches pages from the hosts registry.WebHosts allows, redirects included.

func NewWeb

func NewWeb(hc *http.Client) *Web

NewWeb returns a fetcher that sends requests through hc's transport, which brings retries, rate limits and the cache.

func (*Web) Get

func (w *Web) Get(ctx context.Context, rawURL, accept string) ([]byte, error)

Get returns the body of rawURL. It wraps ErrNotFound for 404 and 410, and fails for hosts outside the allow-list and bodies over 8 MB.

type WebDoc

type WebDoc struct {
	// contains filtered or unexported fields
}

WebDoc reads release notes from allowed web pages. With an anchor, each version gets the element with its id. Without one, a page holds a whole release line, such as one minor, and goes to the first version of the range whose URL is that page.

func NewWebDoc

func NewWebDoc(logger *slog.Logger, pages *PageCache, s registry.Source, from version.V) *WebDoc

NewWebDoc returns a web-doc adapter for the registry source s. from is the version before the range, whose page the range doesn't repeat.

func (*WebDoc) Fetch

func (a *WebDoc) Fetch(ctx context.Context, t registry.ToolSpec, versions []version.Version) ([]VersionNotes, error)

Fetch returns the notes of each version, in the order given.

func (*WebDoc) Kind

func (a *WebDoc) Kind() string

Kind returns KindWebDoc.

type WebFetcher

type WebFetcher interface {
	Get(ctx context.Context, rawURL, accept string) ([]byte, error)
}

WebFetcher returns the body of an allowed web page.

Jump to

Keyboard shortcuts

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