Documentation
¶
Overview ¶
hash.go - Hash generation for message content and refs
parser.go - GitMsg protocol message parsing
ref.go - GitMsg ref parsing and formatting (repo#type:value@branch)
trailers.go - Git trailer extraction from commit messages
types.go - Protocol data types for headers, messages, and refs
url.go - Repository URL normalization and display name extraction
writer.go - GitMsg protocol message formatting and header generation
Index ¶
- Variables
- func ApplyOrigin(fields map[string]string, origin *Origin)
- func BranchURL(repoURL, branch string) string
- func CommitURL(repoURL, hash string) string
- func CreateHeader(header Header) string
- func CreateRef(refType RefType, value string, repository string, branch string) string
- func CreateRefSection(ref Ref) string
- func EnsureBranchRef(value string) string
- func ExtractBranchFromRemote(remoteBranch string) string
- func ExtractCleanContent(message string) string
- func ExtractDomain(rawURL string) string
- func FileURL(repoURL, branch, filePath string) string
- func FormatMessage(content string, header Header, references []Ref) string
- func FormatShortRef(ref, workspaceURL string) string
- func GetDisplayName(rawURL string) string
- func GetFullDisplayName(rawURL string) string
- func IsClosingTrailer(key string) bool
- func IsMessageType(header *Header, ext, msgType string) bool
- func LocalizeRef(ref, workspaceRepoURL string) string
- func NormalizeHash(hash string) (string, error)
- func NormalizeRef(ref string) string
- func NormalizeRefWithContext(ref string, currentRepository string, branch string) string
- func NormalizeURL(rawURL string) string
- func OriginDisplayAuthor(origin *Origin) string
- func QuoteContent(content string) string
- func SplitSubjectBody(content string) (subject, body string)
- func StripRepoFromRef(ref string) string
- func UnquoteContent(metadata string) string
- func ValidateHash(hash string) bool
- type Header
- type HostingService
- type Message
- type Origin
- type ParsedRef
- type Ref
- type RefType
- type RepoInfo
- type RepositoryID
- type ResolvedRef
- type Trailer
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidHash = errors.New("invalid commit hash format")
)
Functions ¶
func ApplyOrigin ¶
ApplyOrigin adds origin-* fields to a header fields map.
func CreateHeader ¶
CreateHeader formats a Header struct into a GitMsg trailer line.
func CreateRefSection ¶
CreateRefSection formats a Ref struct into a GitMsg-Ref trailer with continuation lines.
func EnsureBranchRef ¶
EnsureBranchRef normalizes a value to a proper #branch: ref if it isn't already a recognized ref type.
func ExtractBranchFromRemote ¶
ExtractBranchFromRemote extracts branch name from remote ref.
func ExtractCleanContent ¶
ExtractCleanContent extracts user content without protocol metadata.
func ExtractDomain ¶
ExtractDomain extracts the domain from a repository URL.
func FormatMessage ¶
FormatMessage assembles content, header, and refs into a commit message.
func FormatShortRef ¶
FormatShortRef formats a ref for compact display. Workspace items (matching workspaceURL or local) show "#hash@branch". External items show the full ref. Omits the type prefix for brevity.
func GetDisplayName ¶
GetDisplayName returns the repository name for display.
func GetFullDisplayName ¶
GetFullDisplayName returns owner/repo for display.
func IsClosingTrailer ¶
IsClosingTrailer returns true if the trailer key implies closing/completing an item.
func IsMessageType ¶
IsMessageType checks if a header matches extension and type.
func LocalizeRef ¶
LocalizeRef strips the repository URL from a ref if it belongs to the workspace repo. Remote refs are returned unchanged.
func NormalizeHash ¶
NormalizeHash normalizes a commit hash to lowercase 12 chars.
func NormalizeRef ¶
NormalizeRef normalizes a ref string to canonical format.
func NormalizeRefWithContext ¶
NormalizeRefWithContext normalizes a ref with repository context.
func NormalizeURL ¶
NormalizeURL normalizes repository URLs to HTTPS format.
func OriginDisplayAuthor ¶ added in v0.15.0
OriginDisplayAuthor returns the origin author display name. Uses AuthorName directly when available, falling back to an @handle derived from the author email (including GitHub's "id+login@users.noreply.github.com" form). Returns "" when origin is nil or both fields are empty.
func QuoteContent ¶
QuoteContent prefixes each line with "> " for blockquote formatting in GitMsg-Ref metadata.
func SplitSubjectBody ¶
SplitSubjectBody splits content into a subject (first line) and body (rest).
func StripRepoFromRef ¶
StripRepoFromRef removes the repository prefix from a ref, returning just "#type:value@branch". This is used for workspace items where refs should be relative.
func UnquoteContent ¶
UnquoteContent reverses QuoteContent: extracts blockquoted content from GitMsg-Ref metadata by keeping only lines starting with ">" and stripping the marker. Lines that don't start with ">" are ignored (they aren't part of the quoted content).
func ValidateHash ¶
ValidateHash checks if a hash is a valid 12-char hex string.
Types ¶
type Header ¶
type Header struct {
Ext string
V string
Fields map[string]string
FieldOrder []string // extension-declared priority fields placed before alphabetical remainder
}
func ParseHeader ¶
ParseHeader parses a GitMsg trailer line into a Header struct.
type HostingService ¶
type HostingService string
const ( HostGitHub HostingService = "github" HostGitLab HostingService = "gitlab" HostBitbucket HostingService = "bitbucket" HostGitea HostingService = "gitea" HostUnknown HostingService = "unknown" )
func DetectHost ¶
func DetectHost(rawURL string) HostingService
DetectHost identifies the git hosting service from a URL.
type Message ¶
func ParseMessage ¶
ParseMessage parses a complete GitMsg message with header and refs.
type Origin ¶
type Origin struct {
AuthorEmail string // email address of original author
AuthorName string // display name of original author
Time string // ISO 8601 timestamp of original creation
URL string // URL to original item on source platform
Platform string // source platform name (e.g., "github")
}
Origin holds provenance metadata for content imported from external platforms.
func ExtractOrigin ¶
ExtractOrigin reads origin-* fields from a parsed header and returns an Origin. Returns nil when no origin fields are present.
type ParsedRef ¶
type ParsedRef struct {
Type RefType
Repository string
Value string
Branch string
// File ref specific fields
FilePath string // For file refs: the file path
FileRef string // For file refs: specific commit/tag (optional)
LineStart int // For file refs: start line number (0 if not specified)
LineEnd int // For file refs: end line number (0 if not specified, or same as LineStart for single line)
}
type Ref ¶
type Ref struct {
Ext string
Ref string
V string
Author string
Email string
Time string
Fields map[string]string
Metadata string
FieldOrder []string // extension-declared priority fields placed before alphabetical remainder
}
func ParseRefSection ¶
ParseRefSection parses a GitMsg-Ref trailer with continuation lines into a Ref struct.
type RepositoryID ¶
func ParseRepositoryID ¶
func ParseRepositoryID(identifier string) RepositoryID
ParseRepositoryID parses a repository identifier into URL and branch.
type ResolvedRef ¶
ResolvedRef holds the resolved components of a ref after applying defaults.
func ResolveRefWithDefaults ¶
func ResolveRefWithDefaults(refStr, defaultRepoURL, defaultBranch string) ResolvedRef
ResolveRefWithDefaults parses a ref string and fills in missing repo/branch from defaults.
type Trailer ¶
type Trailer struct {
Key string // Fixes, Closes, Resolves, Implements, Refs
Value string // Raw value (GitMsg ref, URL, or opaque ID)
}
Trailer represents a parsed git trailer (Key: Value) from a commit message.
func ExtractTrailers ¶
ExtractTrailers parses recognized git trailers from the commit message footer. Returns nil if no trailers are found.