relplan

package
v0.192.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 11 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 relplan reads what a repository has merged and not yet released, and how its releases have been spaced, from the machine alone (ADR-064).

The Work board's release column asks two questions: what is waiting to ship, and how often does this repository ship. Both are answered from git as it stands on this machine: the CHANGELOG's Unreleased section on the remote's default branch (`git show origin/HEAD:CHANGELOG.md`), plus the changelog fragments in changes/unreleased/ on that branch for a repository that keeps one file per change, and the newest tags. Nothing here fetches: the answer is only as fresh as the user's last `git fetch`, and the board says so. No release time is predicted; the median gap is a measured spacing, shown as one.

Index

Constants

View Source
const (
	// MaxItems is how many [Unreleased] entries are returned; the count
	// says how many there are.
	MaxItems = 30
	// TagsRead is how many of the newest tags are read: ten gaps.
	TagsRead = 11
	// MinGaps is how many gaps between releases a median needs (rule 6):
	// with fewer, the spacing is anecdote, not a measure.
	MinGaps = 3
)
View Source
const EntryRunes = 280

EntryRunes bounds an entry's text: release notes say it in two lines.

View Source
const FragmentsDir = "changes/unreleased"

FragmentsDir is where a repository that keeps one file per change holds the entries waiting for the next release (changes/README.md): each file is a `---`/`kind: …`/`---` front matter and then its bullets.

Variables

View Source
var ErrNoRef = errors.New("no remote default branch known locally")

ErrNoRef is returned when the clone has no remote default branch known locally (no refs/remotes/origin/HEAD).

View Source
var Kinds = []string{"Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"}

Kinds are Keep a Changelog's six kinds, the ones Unreleased.Kinds counts.

View Source
var ReleaseTag = regexp.MustCompile(`^v(\d+)\.(\d+)\.(\d+)$`)

ReleaseTag is the version tags read as releases: v-prefixed semver, "v0.152.0". A pre-release ("v1.0.0-rc.1") or a tag of another shape ("app-v2.0.1", "1.4") is not one: its pull requests fall to the next release.

Functions

func AddFragment added in v0.120.0

func AddFragment(u *Unreleased, fragment []byte)

AddFragment counts one fragment's top-level bullets into u, as ParseUnreleased counts the section's: the front matter is read for its `kind:` and skipped, and a file without a closing `---` is read as bullets alone, of no kind.

func AddFragmentFile added in v0.184.0

func AddFragmentFile(u *Unreleased, file string, fragment []byte)

AddFragmentFile is AddFragment for a fragment named file, the name its entries carry.

func Ahead

func Ahead(ctx context.Context, dir, tag, rev string) (int, error)

Ahead is how many commits rev has that the tag does not.

func Changelog

func Changelog(ctx context.Context, dir, rev string) ([]byte, bool)

Changelog is CHANGELOG.md at rev; ok is false when the file is not there.

func DefaultRef

func DefaultRef(ctx context.Context, dir string) (ref, sha string, err error)

DefaultRef is the remote default branch as this clone knows it, "origin/main", and its commit. It reads refs only; it never fetches.

func FragmentNames added in v0.184.0

func FragmentNames(ctx context.Context, dir, rev string) ([]string, bool)

FragmentNames is the `.md` files in FragmentsDir at rev, as paths from the repository's root, sorted. ok is false when rev has no such directory.

func HistoryKey added in v0.153.0

func HistoryKey(ctx context.Context, dir string) (key, ref, tagsOut string, err error)

HistoryKey is what ReleaseHistory's answer rests on, read cheaply: the line's tip and every tag with the commit it names. When it has not changed, neither has the answer.

func MedianGap

func MedianGap(tags []Tag) (int64, int)

MedianGap is the median time between consecutive tags (ms) and how many gaps it is taken over; 0 with fewer than MinGaps gaps. Order does not matter; tags made in the same second are one release.

func MergeBase added in v0.184.0

func MergeBase(ctx context.Context, dir, a, b string) (string, bool)

MergeBase is the best common ancestor of a and b; ok is false when git cannot say.

func OriginURL

func OriginURL(ctx context.Context, dir string) (string, error)

OriginURL is the address of the remote named origin, as configured.

func Plain added in v0.184.0

func Plain(s string) (scope, text string)

Plain is a changelog bullet in plain words: its leading `**scope:**` taken off and returned apart, bold, italics, code ticks and link targets dropped (a link keeps its words), cut to EntryRunes runes with an ellipsis.

func RemoteBranch added in v0.184.0

func RemoteBranch(ctx context.Context, dir, branch string) (string, bool)

RemoteBranch is the commit of origin/<branch> as this clone knows it; ok is false when the clone has no such remote-tracking branch. Nothing is fetched.

func SubjectPR added in v0.153.0

func SubjectPR(subject string) int

SubjectPR is the pull request a first-parent commit's subject names, 0 when it names none.

Types

type Entry added in v0.184.0

type Entry struct {
	// Text is the bullet whole, continuation lines joined, the leading
	// `**scope:**` taken off and markdown emphasis dropped; at most
	// EntryRunes runes.
	Text string
	// Scope is the `**scope:**` the bullet starts with, "" without one.
	Scope string
	// Kind is its Keep a Changelog kind, "" when none is said.
	Kind string
	// File is the fragment file it came from (base name), "" for a
	// CHANGELOG bullet.
	File string
}

Entry is one changelog bullet as release notes say it.

type Fragment added in v0.184.0

type Fragment struct {
	Name string
	Body []byte
}

Fragment is one changelog fragment file: its base name and its text.

func Fragments added in v0.120.0

func Fragments(ctx context.Context, dir, rev string) ([]Fragment, bool)

Fragments is every `.md` file in FragmentsDir at rev, in file name order, read with two git processes however many there are. ok is false when rev has no such directory.

func ReadFragments added in v0.184.0

func ReadFragments(ctx context.Context, dir, rev string, paths []string) ([]Fragment, bool)

ReadFragments reads the files at paths (FragmentNames') at rev with one `git cat-file --batch`. A path git cannot find is left out.

type Release added in v0.153.0

type Release struct {
	Tag string
	// At is when the tag was made (unix ms): an annotated tag's own date,
	// else its commit's.
	At int64
	// PRs are the pull request numbers its commits name, oldest first, each
	// once.
	PRs []int
	// First says it is the oldest release on the line: it shipped everything
	// before it too, back to the first commit.
	First bool
}

Release is one version tag and the pull requests it shipped.

func ParseReleases added in v0.153.0

func ParseReleases(log string, tags []TagRef) []Release

ParseReleases walks first-parent history ("sha<TAB>subject" per line, newest first, as `git log --first-parent` prints it) and charges each commit's pull request to the first release at or after it on the line. Tags whose commit is not on the line are left out; of several version tags on one commit, the highest version is the release. Newest first.

func ReleaseHistory added in v0.153.0

func ReleaseHistory(ctx context.Context, dir, ref, tagsOut string) ([]Release, error)

ReleaseHistory is every release on ref's first-parent line and the pull requests each shipped, newest first: two git reads, the tags and the line's history (one `git log`, not one per release).

type Tag

type Tag struct {
	Name string
	At   int64
}

Tag is one tag and when it was made (unix ms): an annotated tag's own date, else its commit's.

func ParseTags

func ParseTags(out string) []Tag

ParseTags reads for-each-ref output in the format Tags asks for ("name<TAB>unix seconds" per line), newest first as git sorted it. Lines it cannot read are skipped.

func Tags

func Tags(ctx context.Context, dir string) ([]Tag, error)

Tags is the repository's newest TagsRead tags, newest first.

type TagRef added in v0.153.0

type TagRef struct {
	Name   string
	Commit string
	At     int64 // unix ms
}

TagRef is a tag and the commit it names (peeled for an annotated one).

func ParseTagRefs added in v0.153.0

func ParseTagRefs(out string) []TagRef

ParseTagRefs reads for-each-ref output in the format ReleaseHistory asks for ("name<TAB>object<TAB>peeled<TAB>unix seconds"), keeping version tags (ReleaseTag) only. Lines it cannot read are skipped; CRLF is read as LF.

type Unreleased

type Unreleased struct {
	// Items are the first lines of its top-level bullets, in order, at most
	// MaxItems; nested bullets and sub-headings are not items.
	Items []string
	// Count is how many top-level bullets the section has.
	Count int
	// Kinds counts the bullets by their Keep a Changelog kind — the `### `
	// heading they sit under in the section, a fragment's `kind:` — for the
	// six kinds only (Kinds); a bullet under no such heading counts in Count
	// alone. Nil when no bullet has a kind. The release plan predicts the
	// next version from it: an Added entry is a minor release.
	Kinds map[string]int
	// Entries are the same bullets whole, at most MaxItems: the text with
	// its continuation lines, in plain words (Plain), its scope and kind.
	// The right panel's release notes draw them.
	Entries []Entry
}

Unreleased is the CHANGELOG's Unreleased section, summed up.

func ParseRelease added in v0.184.0

func ParseRelease(changelog []byte) (version string, u Unreleased, ok bool)

ParseRelease reads the newest released section of a Keep a Changelog file: the first `## [x.y.z]` heading that is not Unreleased. version is its bracketed name ("0.183.0"); ok is false when there is none.

func ParseUnreleased

func ParseUnreleased(changelog []byte) (Unreleased, bool)

ParseUnreleased reads the Unreleased section of a Keep a Changelog file. ok is false when there is no such section; an empty section is ok with no items. The heading may carry more after the bracket ("## Unreleased - …"), and CRLF line ends read as LF.

Jump to

Keyboard shortcuts

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