Documentation
¶
Overview ¶
Package utils provides shared utility functions for the stackit codebase.
Index ¶
- Constants
- Variables
- func CleanCommitMessage(message string) string
- func GenerateBranchNameFromMessage(message string) string
- func IsDemoMode() bool
- func IsInteractive() bool
- func IsTTY() bool
- func OpenBrowser(url string) error
- func ProcessBranchNamePattern(pattern string, username, date, message string) string
- func ReadFromStdin() (string, error)
- func Run[T any](items []T, worker func(item T))
- func RunWithWorkers[T any](items []T, numWorkers int, worker func(item T))
- func SanitizeBranchName(name string) string
- func SetInteractive(interactive bool)
- func ShortRevision(rev string, maxLen int) string
- func ValidateBranchName(name string) error
- type BranchNameError
Constants ¶
const ( // MaxBranchNameByteLength is the maximum length for a branch name // Git refs have a max length of 256 bytes, minus 22 for "refs/stackit/metadata/" MaxBranchNameByteLength = 234 )
Variables ¶
var ( // BranchNameReplaceRegex matches characters that are not valid in branch names // Valid characters: letters, numbers, -, _, /, . BranchNameReplaceRegex = regexp.MustCompile(`[^-_/.a-zA-Z0-9]+`) // BranchNameIgnoreRegex matches trailing slashes and dots that should be removed BranchNameIgnoreRegex = regexp.MustCompile(`[/.]*$`) )
Functions ¶
func CleanCommitMessage ¶
CleanCommitMessage removes comments and trailing whitespace from a commit message
func GenerateBranchNameFromMessage ¶
GenerateBranchNameFromMessage generates a branch name from a commit message
func IsDemoMode ¶
func IsDemoMode() bool
IsDemoMode returns true if STACKIT_DEMO environment variable is set
func IsInteractive ¶
func IsInteractive() bool
IsInteractive checks if we're in an interactive terminal
func OpenBrowser ¶
OpenBrowser opens a URL in the default browser on Linux
func ProcessBranchNamePattern ¶
ProcessBranchNamePattern processes a branch name pattern by replacing placeholders Supported placeholders:
- {username}: The sanitized Git username
- {date}: Current date and time in yyyyMMddHHmmss format in UTC
- {message}: The sanitized commit message subject (required)
The pattern must contain {message} placeholder. The pattern is processed and then sanitized to ensure it's a valid branch name.
func ReadFromStdin ¶
ReadFromStdin reads all content from standard input
func Run ¶
func Run[T any](items []T, worker func(item T))
Run runs the given worker function for each item in the slice in parallel. It uses runtime.GOMAXPROCS(0) as the default number of workers.
func RunWithWorkers ¶
RunWithWorkers runs the given worker function for each item in the slice in parallel with a specified number of workers.
func SanitizeBranchName ¶
SanitizeBranchName sanitizes a branch name by replacing invalid characters
func SetInteractive ¶
func SetInteractive(interactive bool)
SetInteractive sets whether the TUI should be interactive
func ShortRevision ¶
ShortRevision returns a shortened version of a git revision hash. Returns at most maxLen characters, defaulting to 7 if maxLen <= 0.
func ValidateBranchName ¶
ValidateBranchName checks if a branch name is valid according to Git rules. Returns an error describing the issue if invalid, nil if valid.
Types ¶
type BranchNameError ¶
BranchNameError represents an invalid branch name error
func (*BranchNameError) Error ¶
func (e *BranchNameError) Error() string