gitutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvGitHubToken is the primary GitHub token environment variable
	EnvGitHubToken = "GITHUB_TOKEN"

	// EnvGitHubToken2 is an alternative GitHub token environment variable
	EnvGitHubToken2 = "GH_TOKEN"

	// EnvGitHubAccessToken is another common GitHub token environment variable
	EnvGitHubAccessToken = "GITHUB_ACCESS_TOKEN"

	// EnvCascadeToken is the Cascade-specific GitHub token environment variable
	EnvCascadeToken = "CASCADE_GITHUB_TOKEN"

	// EnvSSHKeyPath is the environment variable for custom SSH key path
	EnvSSHKeyPath = "SSH_KEY_PATH"
)

Environment variable names for authentication configuration.

Variables

This section is empty.

Functions

func BuildCloneURL

func BuildCloneURL(repo string, protocol Protocol) (string, error)

BuildCloneURL constructs a cloneable git URL from a repository string. If the string is already a valid URL, returns it as-is. For shorthand formats (user/repo), constructs an HTTPS URL.

func ExtractOwnerAndRepo

func ExtractOwnerAndRepo(repo string) (owner, name string, err error)

ExtractOwnerAndRepo extracts owner and repository name from a URL or path. Returns owner and repo name separately.

func ExtractRepoName

func ExtractRepoName(repo string) string

ExtractRepoName extracts the repository name from a git URL or path.

func GetGitHubToken

func GetGitHubToken() string

GetGitHubToken retrieves a GitHub token from environment variables. Checks multiple common environment variable names in order of precedence: 1. GITHUB_TOKEN 2. GH_TOKEN 3. CASCADE_GITHUB_TOKEN 4. GITHUB_ACCESS_TOKEN Returns empty string if no token is found.

func GetGitHubTokenOrError

func GetGitHubTokenOrError() (string, error)

GetGitHubTokenOrError retrieves a GitHub token or returns an error if not found. This is useful when a token is required for an operation.

func GetSSHKeyPath

func GetSSHKeyPath() string

GetSSHKeyPath returns the SSH key path from environment or the default location. Checks SSH_KEY_PATH environment variable first, then falls back to ~/.ssh/id_rsa.

func GetSSHKeyPathOrError

func GetSSHKeyPathOrError() (string, error)

GetSSHKeyPathOrError returns the SSH key path or an error if it doesn't exist.

func IsValidGitHubName

func IsValidGitHubName(name string) bool

IsValidGitHubName checks if a name follows GitHub naming conventions. Returns true if valid, false otherwise.

func IsValidLabelName

func IsValidLabelName(name string) bool

IsValidLabelName checks if a label name follows GitHub label rules.

func NormalizeURL

func NormalizeURL(url string) string

NormalizeURL normalizes git URLs for comparison. Removes .git suffix, converts SSH to HTTPS format, and lowercases.

func SSHKeyExists

func SSHKeyExists(path string) bool

SSHKeyExists checks if an SSH key file exists at the given path.

func SanitizeBranchName

func SanitizeBranchName(input string) string

SanitizeBranchName sanitizes a string to create a valid git branch name. Replaces or removes invalid characters.

func SanitizeLabels

func SanitizeLabels(labels []string) []string

SanitizeLabels enforces GitHub label rules and deduplicates labels.

func ValidateBranchName

func ValidateBranchName(name string) error

ValidateBranchName validates a git branch name according to git rules. Returns an error if the name is invalid.

func ValidateOwnerName

func ValidateOwnerName(name string) error

ValidateOwnerName validates a GitHub owner or organization name. Returns an error if the name is invalid.

func ValidateRepoName

func ValidateRepoName(name string) error

ValidateRepoName validates a GitHub repository name. Returns an error if the name is invalid.

Types

type Protocol

type Protocol string

Protocol represents the git protocol type.

const (
	// ProtocolHTTPS represents HTTPS git protocol
	ProtocolHTTPS Protocol = "https"
	// ProtocolSSH represents SSH git protocol
	ProtocolSSH Protocol = "ssh"
	// ProtocolGit represents git protocol
	ProtocolGit Protocol = "git"
)

type RepoURL

type RepoURL struct {
	// Host is the git hosting provider (e.g., github.com, gitlab.com)
	Host string

	// Owner is the repository owner or organization
	Owner string

	// Name is the repository name
	Name string

	// Protocol is the access protocol used in the original URL
	Protocol Protocol

	// CloneURL is the full clone URL in the original format
	CloneURL string

	// HTTPSURL is the HTTPS version of the clone URL
	HTTPSURL string

	// SSHURL is the SSH version of the clone URL
	SSHURL string
}

RepoURL represents a parsed git repository URL with multiple access formats.

func ParseRepoURL

func ParseRepoURL(repo string) (*RepoURL, error)

ParseRepoURL parses a repository string into a structured RepoURL. Handles various formats: - user/repo (assumes GitHub) - github.com/user/repo - https://github.com/user/repo.git - git@github.com:user/repo.git

Jump to

Keyboard shortcuts

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