Documentation
¶
Index ¶
- Constants
- func AddLabelsToIssue(ctx context.Context, client *github.Client, owner, repo string, number int, ...) error
- func AppendToFile(path string, data []byte) error
- func AppendToFileString(path string, content string) error
- func ContainsAll(s string, substrings ...string) bool
- func ContainsAny(s string, substrings ...string) bool
- func CopyFile(src, dst string) error
- func CreatePullRequest(ctx context.Context, client *github.Client, owner, repo string, ...) (*github.PullRequest, error)
- func CreateRef(ctx context.Context, client *github.Client, owner, repo string, ...) error
- func ExecuteWithRetry(ctx context.Context, client *github.Client, maxRetries int, ...) error
- func FileExists(path string) bool
- func FindFilesWithExtension(dir string, ext string) ([]string, error)
- func GetLatestRelease(ctx context.Context, client *github.Client, owner, repo string) (*github.RepositoryRelease, error)
- func GetRef(ctx context.Context, client *github.Client, owner, repo, ref string) (*github.Reference, error)
- func IsDirectory(path string) bool
- func IsHexString(s string) bool
- func IsPathSafe(baseDir, path string) bool
- func IsRegularFile(path string) bool
- func JoinAndValidatePath(baseDir string, elements ...string) (string, error)
- func JoinNonEmpty(sep string, parts ...string) string
- func ModifyLines(path string, fn func(line string, lineNum int) string) error
- func NewGitHubClient(options GitHubClientOptions) *github.Client
- func NewGitHubClientWithToken(token string) *github.Client
- func ReadFile(path string) ([]byte, error)
- func ReadFileString(path string) (string, error)
- func ReadFileWithOptions(path string, options FileOptions) ([]byte, error)
- func ReadLines(path string) ([]string, error)
- func ReplaceInFile(path string, oldStr, newStr string) error
- func SafeAbs(baseDir, path string) (string, error)
- func SplitAndTrim(s, sep string) []string
- func TrimPrefixAny(s string, prefixes ...string) string
- func TrimSuffixAny(s string, suffixes ...string) string
- func ValidatePath(baseDir, path string, options PathValidationOptions) error
- func ValidatePathWithDefaults(baseDir, path string) error
- func WriteFile(path string, data []byte) error
- func WriteFileString(path string, content string) error
- func WriteFileWithOptions(path string, data []byte, options FileOptions) error
- func WriteLines(path string, lines []string) error
- type FileLockManager
- type FileOptions
- type GitHubClientOptions
- type PathValidationOptions
- type RateLimitHandler
Constants ¶
const (
// MaxPathLength defines the maximum allowed path length
MaxPathLength = 255
)
Variables ¶
This section is empty.
Functions ¶
func AddLabelsToIssue ¶
func AddLabelsToIssue(ctx context.Context, client *github.Client, owner, repo string, number int, labels []string) error
AddLabelsToIssue adds labels to an issue or pull request with retry logic
func AppendToFile ¶
AppendToFile appends content to a file
func AppendToFileString ¶
AppendToFileString appends a string to a file
func ContainsAll ¶
ContainsAll checks if a string contains all of the given substrings
func ContainsAny ¶
ContainsAny checks if a string contains any of the given substrings
func CreatePullRequest ¶
func CreatePullRequest(ctx context.Context, client *github.Client, owner, repo string, pull *github.NewPullRequest) (*github.PullRequest, error)
CreatePullRequest creates a pull request with retry logic
func CreateRef ¶
func CreateRef(ctx context.Context, client *github.Client, owner, repo string, ref *github.Reference) error
CreateRef creates a reference (branch, tag) with retry logic
func ExecuteWithRetry ¶
func ExecuteWithRetry(ctx context.Context, client *github.Client, maxRetries int, retryDelay time.Duration, fn func() (*github.Response, error)) error
ExecuteWithRetry executes a GitHub API request with retry logic for rate limiting
func FindFilesWithExtension ¶
FindFilesWithExtension finds all files with the given extension in a directory
func GetLatestRelease ¶
func GetLatestRelease(ctx context.Context, client *github.Client, owner, repo string) (*github.RepositoryRelease, error)
GetLatestRelease gets the latest release for a repository with retry logic
func GetRef ¶
func GetRef(ctx context.Context, client *github.Client, owner, repo, ref string) (*github.Reference, error)
GetRef gets a reference (branch, tag) with retry logic
func IsHexString ¶
IsHexString checks if a string is a valid hexadecimal string (for commit SHAs)
func IsPathSafe ¶
IsPathSafe is a simplified version that just checks if a path is within a base directory
func IsRegularFile ¶
IsRegularFile checks if a path is a regular file
func JoinAndValidatePath ¶
JoinAndValidatePath joins path elements and validates the result
func JoinNonEmpty ¶
JoinNonEmpty joins non-empty strings with the given separator
func ModifyLines ¶
ModifyLines modifies lines in a file using a function
func NewGitHubClient ¶
func NewGitHubClient(options GitHubClientOptions) *github.Client
NewGitHubClient creates a new GitHub client with the given options
func NewGitHubClientWithToken ¶
NewGitHubClientWithToken creates a new GitHub client with just a token
func ReadFileString ¶
ReadFileString reads a file and returns its contents as a string
func ReadFileWithOptions ¶
func ReadFileWithOptions(path string, options FileOptions) ([]byte, error)
ReadFileWithOptions reads a file with the given options
func ReplaceInFile ¶
ReplaceInFile replaces content in a file
func SplitAndTrim ¶
SplitAndTrim splits a string by the given separator and trims each part
func TrimPrefixAny ¶
TrimPrefixAny trims any of the given prefixes from the string
func TrimSuffixAny ¶
TrimSuffixAny trims any of the given suffixes from the string
func ValidatePath ¶
func ValidatePath(baseDir, path string, options PathValidationOptions) error
ValidatePath ensures the path is safe and within the allowed directory baseDir is the root directory that all paths must be contained within path is the path to validate options provides configuration for the validation process
func ValidatePathWithDefaults ¶
ValidatePathWithDefaults validates a path using default options
func WriteFileString ¶
WriteFileString writes a string to a file
func WriteFileWithOptions ¶
func WriteFileWithOptions(path string, data []byte, options FileOptions) error
WriteFileWithOptions writes data to a file with the given options
func WriteLines ¶
WriteLines writes lines to a file
Types ¶
type FileLockManager ¶
type FileLockManager struct {
// contains filtered or unexported fields
}
FileLockManager manages locks for file operations to prevent concurrent access
func NewFileLockManager ¶
func NewFileLockManager() *FileLockManager
NewFileLockManager creates a new file lock manager
func (*FileLockManager) GetLock ¶
func (m *FileLockManager) GetLock(path string) *sync.Mutex
GetLock gets or creates a lock for the given file path
func (*FileLockManager) LockFile ¶
func (m *FileLockManager) LockFile(path string)
LockFile locks a file for exclusive access
func (*FileLockManager) UnlockFile ¶
func (m *FileLockManager) UnlockFile(path string)
UnlockFile unlocks a file
func (*FileLockManager) WithFileLock ¶
func (m *FileLockManager) WithFileLock(path string, fn func() error) error
WithFileLock executes a function with a lock on the given file
type FileOptions ¶
type FileOptions struct {
// CreateDirs if true, creates parent directories if they don't exist
CreateDirs bool
// Mode is the file mode to use when creating files
Mode os.FileMode
// BaseDir is the base directory for path validation
BaseDir string
// ValidateOptions are the options for path validation
ValidateOptions PathValidationOptions
}
FileOptions provides options for file operations
func DefaultFileOptions ¶
func DefaultFileOptions() FileOptions
DefaultFileOptions returns the default options for file operations
type GitHubClientOptions ¶
type GitHubClientOptions struct {
// Token is the GitHub API token
Token string
// BaseURL is the base URL for the GitHub API (optional, for GitHub Enterprise)
BaseURL string
// Timeout is the default timeout for API requests
Timeout time.Duration
// RetryCount is the number of times to retry failed requests
RetryCount int
// RetryDelay is the delay between retries
RetryDelay time.Duration
}
GitHubClientOptions provides configuration options for GitHub client creation
func DefaultGitHubClientOptions ¶
func DefaultGitHubClientOptions() GitHubClientOptions
DefaultGitHubClientOptions returns the default options for GitHub client creation
type PathValidationOptions ¶
type PathValidationOptions struct {
// RequireRegularFile if true, validates that the path points to a regular file
RequireRegularFile bool
// AllowNonExistent if true, allows paths that don't exist yet
AllowNonExistent bool
// CheckSymlinks if true, validates that symlinks don't point outside the base directory
CheckSymlinks bool
// MaxPathLength specifies the maximum allowed path length (defaults to 255 if not set)
MaxPathLength int
}
PathValidationOptions provides configuration options for path validation
func DefaultPathValidationOptions ¶
func DefaultPathValidationOptions() PathValidationOptions
DefaultPathValidationOptions returns the default options for path validation
type RateLimitHandler ¶
type RateLimitHandler struct {
// contains filtered or unexported fields
}
RateLimitHandler provides rate limit handling for GitHub API requests
func NewRateLimitHandler ¶
func NewRateLimitHandler(client *github.Client, maxRetries int, retryDelay time.Duration) *RateLimitHandler
NewRateLimitHandler creates a new rate limit handler for the given client
func (*RateLimitHandler) GetRateLimitInfo ¶
func (h *RateLimitHandler) GetRateLimitInfo() string
GetRateLimitInfo returns information about the current rate limit
func (*RateLimitHandler) HandleRateLimit ¶
func (h *RateLimitHandler) HandleRateLimit(resp *github.Response, err error) bool
HandleRateLimit handles rate limiting for GitHub API requests It returns true if the request should be retried, and false otherwise