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
- Variables
- func AddFragment(u *Unreleased, fragment []byte)
- func Ahead(ctx context.Context, dir, tag, rev string) (int, error)
- func Changelog(ctx context.Context, dir, rev string) ([]byte, bool)
- func DefaultRef(ctx context.Context, dir string) (ref, sha string, err error)
- func Fragments(ctx context.Context, dir, rev string) ([][]byte, bool)
- func HistoryKey(ctx context.Context, dir string) (key, ref, tagsOut string, err error)
- func MedianGap(tags []Tag) (int64, int)
- func OriginURL(ctx context.Context, dir string) (string, error)
- func SubjectPR(subject string) int
- type Release
- type Tag
- type TagRef
- type Unreleased
Constants ¶
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 )
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 ¶
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).
var Kinds = []string{"Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"}
Kinds are Keep a Changelog's six kinds, the ones Unreleased.Kinds counts.
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 DefaultRef ¶
DefaultRef is the remote default branch as this clone knows it, "origin/main", and its commit. It reads refs only; it never fetches.
func Fragments ¶ added in v0.120.0
Fragments is the text of 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 HistoryKey ¶ added in v0.153.0
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 ¶
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.
Types ¶
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
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
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 ¶
Tag is one tag and when it was made (unix ms): an annotated tag's own date, else its commit's.
type TagRef ¶ added in v0.153.0
TagRef is a tag and the commit it names (peeled for an annotated one).
func ParseTagRefs ¶ added in v0.153.0
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
}
Unreleased is the CHANGELOG's Unreleased section, summed up.
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.