utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package utils holds small helpers shared across flakehunter's packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseBlankLines

func CollapseBlankLines(s string) string

CollapseBlankLines replaces runs of blank lines with a single blank line. CI logs are full of padding that wastes scarce LLM context.

func Do

func Do(ctx context.Context, cfg RetryConfig, fn func(attempt int) error) error

Do runs fn until it succeeds, the context is cancelled, or attempts are exhausted. Backoff is exponential with jitter, so a fleet of runners retrying together does not synchronise into a thundering herd.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable reports whether err asks to be retried.

func LastLines

func LastLines(s string, n int) []string

LastLines returns the final n lines of s, preserving their order.

func ShortHash

func ShortHash(parts ...string) string

ShortHash returns the first 12 hex characters of the SHA-256 of s. Used to give flaky occurrences a stable identity across runs so reports can be diffed and de-duplicated.

func TruncateRunes

func TruncateRunes(s string, max int) string

TruncateRunes shortens s to at most max runes, appending an ellipsis when it had to cut. Rune-aware so multi-byte characters are never split in half.

Types

type RetryConfig

type RetryConfig struct {
	Attempts int
	BaseWait time.Duration
	MaxWait  time.Duration
}

RetryConfig controls the exponential backoff used for network calls.

func DefaultRetry

func DefaultRetry() RetryConfig

DefaultRetry is a sensible policy for the GitHub API: enough attempts to ride out a secondary rate limit without hanging a CI job for minutes.

type Retryable

type Retryable interface {
	Retryable() bool
}

Retryable lets a caller signal that an error is worth retrying. Errors that do not implement it are treated as permanent, so a 404 is not retried four times before failing.

Jump to

Keyboard shortcuts

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