Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package utils provides shared utility functions for the stackit codebase.

Index

Constants

View Source
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

View Source
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

func CleanCommitMessage(message string) string

CleanCommitMessage removes comments and trailing whitespace from a commit message

func GenerateBranchNameFromMessage

func GenerateBranchNameFromMessage(message string) string

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 IsTTY

func IsTTY() bool

IsTTY returns true if we can use a TTY for interactive TUI

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens a URL in the default browser on Linux

func ProcessBranchNamePattern

func ProcessBranchNamePattern(pattern string, username, date, message string) string

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

func ReadFromStdin() (string, error)

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

func RunWithWorkers[T any](items []T, numWorkers int, worker func(item T))

RunWithWorkers runs the given worker function for each item in the slice in parallel with a specified number of workers.

func SanitizeBranchName

func SanitizeBranchName(name string) string

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

func ShortRevision(rev string, maxLen int) string

ShortRevision returns a shortened version of a git revision hash. Returns at most maxLen characters, defaulting to 7 if maxLen <= 0.

func ValidateBranchName

func ValidateBranchName(name string) error

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

type BranchNameError struct {
	Name   string
	Reason string
}

BranchNameError represents an invalid branch name error

func (*BranchNameError) Error

func (e *BranchNameError) Error() string

Jump to

Keyboard shortcuts

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