common

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TrunkBranchCandidates = []string{"main", "master", "trunk"}

TrunkBranchCandidates is the list of common trunk branch names in priority order.

Functions

func AtomicWriteFile

func AtomicWriteFile(outputPath string, writeFn func(*os.File) error) error

AtomicWriteFile writes data to a file atomically using a temp file + rename pattern. This ensures that on failure, no partial/corrupted file is left behind. The writeFn is called with the temp file to perform the actual write.

func Coalesce

func Coalesce(values ...string) string

Coalesce returns the first non-empty string from the arguments

func CoalesceBlank

func CoalesceBlank(values ...string) string

CoalesceBlank returns the first non-blank string from the arguments

func ContainsAny

func ContainsAny(text string, substrings ...string) bool

ContainsAny returns true if text contains any of the substrings

func ContainsAnyIgnoreCase

func ContainsAnyIgnoreCase(text string, substrings ...string) bool

ContainsAnyIgnoreCase returns true if text contains any of the substrings (case-insensitive)

func ContainsIgnoreCase

func ContainsIgnoreCase(text, substr string) bool

ContainsIgnoreCase checks if text contains substr (case-insensitive)

func DaysBetween

func DaysBetween(a, b time.Time) int

DaysBetween returns the number of days between two times

func DetectTrunkBranch added in v1.4.1

func DetectTrunkBranch(repoPath string) string

DetectTrunkBranch detects the trunk/main branch using Git's native methods. Priority order: 1. Remote HEAD reference (refs/remotes/origin/HEAD) - most reliable for cloned repos 2. Current branch via symbolic-ref (works even before first commit) 3. Current branch via rev-parse (works after first commit) 4. Git's configured default branch (init.defaultBranch) 5. Check if main or master branch exists locally Falls back to "main" if nothing found.

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists at the given path. Returns false if the path doesn't exist or is not a directory.

func EndOfDay

func EndOfDay(t time.Time) time.Time

EndOfDay returns the end of the day for the given time

func EqualFold

func EqualFold(a, b string) bool

EqualFold compares two strings case-insensitively

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists at the given path. Returns false if the path doesn't exist or is a directory.

func FirstNonEmpty

func FirstNonEmpty(strings ...string) string

FirstNonEmpty returns the first non-empty string, or empty if all are empty

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats a time as a date string (YYYY-MM-DD)

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime formats a time as a datetime string (YYYY-MM-DD HH:MM:SS)

func FormatDateTimeShort

func FormatDateTimeShort(t time.Time) string

FormatDateTimeShort formats a time as a short datetime string (MM-DD HH:MM)

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration as a short human-readable string

func FormatDurationLong

func FormatDurationLong(d time.Duration) string

FormatDurationLong formats a duration as a long human-readable string (e.g., "2 days, 3 hours")

func FormatTimeAgo

func FormatTimeAgo(t time.Time) string

FormatTimeAgo formats a time as a human-readable "time ago" string

func GetSnippet

func GetSnippet(text, query string, maxLen int) string

GetSnippet extracts a snippet around the query match

func HasPrefixFold

func HasPrefixFold(s, prefix string) bool

HasPrefix checks if s has the given prefix (case-insensitive)

func HasSuffixFold

func HasSuffixFold(s, suffix string) bool

HasSuffix checks if s has the given suffix (case-insensitive)

func IsBlank

func IsBlank(s string) bool

IsBlank returns true if string is empty or only whitespace

func IsJSONFile

func IsJSONFile(filename string) bool

IsJSONFile checks if a filename has a .json extension.

func IsNotBlank

func IsNotBlank(s string) bool

IsNotBlank returns true if string has non-whitespace content

func IsThisWeek

func IsThisWeek(t time.Time) bool

IsThisWeek returns true if the given time is in the current week

func IsToday

func IsToday(t time.Time) bool

IsToday returns true if the given time is today

func IsTrunkBranch added in v1.4.1

func IsTrunkBranch(branch string) bool

IsTrunkBranch checks if the given branch name is a trunk/main branch.

func IsYAMLFile

func IsYAMLFile(filename string) bool

IsYAMLFile checks if a filename has a .yml or .yaml extension.

func IsYesterday

func IsYesterday(t time.Time) bool

IsYesterday returns true if the given time is yesterday

func JoinNonEmpty

func JoinNonEmpty(sep string, parts ...string) string

JoinNonEmpty joins non-empty strings with the given separator

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string with common shortcuts Supports: "1h", "30m", "2d" (days), "1w" (weeks)

func ParseMetadataFlags

func ParseMetadataFlags(pairs []string) map[string]interface{}

ParseMetadataFlags parses key=value pairs into a metadata map. Empty values are ignored.

func PathExists

func PathExists(path string) bool

PathExists checks if a path (file or directory) exists.

func ShouldSkipFogitFile

func ShouldSkipFogitFile(path string) bool

ShouldSkipFogitFile returns true if the given path is inside the .fogit directory and should be excluded from auto-linking or other file operations.

func SplitKeyValue

func SplitKeyValue(s, sep string) (key, value string)

SplitKeyValue splits a string on the first occurrence of separator

func SplitKeyValueEquals

func SplitKeyValueEquals(s string) (key, value string)

SplitKeyValueEquals is a convenience function that splits on "="

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay returns the start of the day for the given time

func TruncateWithEllipsis

func TruncateWithEllipsis(text string, maxLen int) string

TruncateWithEllipsis truncates text to maxLen and adds ellipsis

func ValidateOutputPath

func ValidateOutputPath(outputPath string) error

ValidateOutputPath validates that an output path is safe to write to. It prevents path traversal attacks by ensuring: 1. The path doesn't contain traversal sequences (..) 2. The resolved absolute path is within the current working directory

Returns an error if the path is unsafe, nil if safe.

Types

This section is empty.

Jump to

Keyboard shortcuts

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