protocol

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash = errors.New("invalid commit hash format")
)

Functions

func ApplyOrigin

func ApplyOrigin(fields map[string]string, origin *Origin)

ApplyOrigin adds origin-* fields to a header fields map.

func BranchURL

func BranchURL(repoURL, branch string) string

BranchURL generates host-specific branch/tree URL for web viewing

func CommitURL

func CommitURL(repoURL, hash string) string

CommitURL generates host-specific commit URL for web viewing

func CreateHeader

func CreateHeader(header Header) string

CreateHeader formats a Header struct into a GitMsg trailer line.

func CreateRef

func CreateRef(refType RefType, value string, repository string, branch string) string

CreateRef formats a ref string from its components.

func CreateRefSection

func CreateRefSection(ref Ref) string

CreateRefSection formats a Ref struct into a GitMsg-Ref trailer with continuation lines.

func EnsureBranchRef

func EnsureBranchRef(value string) string

EnsureBranchRef normalizes a value to a proper #branch: ref if it isn't already a recognized ref type.

func ExtractBranchFromRemote

func ExtractBranchFromRemote(remoteBranch string) string

ExtractBranchFromRemote extracts branch name from remote ref.

func ExtractCleanContent

func ExtractCleanContent(message string) string

ExtractCleanContent extracts user content without protocol metadata.

func ExtractDomain

func ExtractDomain(rawURL string) string

ExtractDomain extracts the domain from a repository URL.

func FileURL

func FileURL(repoURL, branch, filePath string) string

FileURL generates a host-specific URL for viewing a file in the web UI.

func FormatMessage

func FormatMessage(content string, header Header, references []Ref) string

FormatMessage assembles content, header, and refs into a commit message.

func FormatShortRef

func FormatShortRef(ref, workspaceURL string) string

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

func GetDisplayName(rawURL string) string

GetDisplayName returns the repository name for display.

func GetFullDisplayName

func GetFullDisplayName(rawURL string) string

GetFullDisplayName returns owner/repo for display.

func IsClosingTrailer

func IsClosingTrailer(key string) bool

IsClosingTrailer returns true if the trailer key implies closing/completing an item.

func IsMessageType

func IsMessageType(header *Header, ext, msgType string) bool

IsMessageType checks if a header matches extension and type.

func LocalizeRef

func LocalizeRef(ref, workspaceRepoURL string) string

LocalizeRef strips the repository URL from a ref if it belongs to the workspace repo. Remote refs are returned unchanged.

func NormalizeHash

func NormalizeHash(hash string) (string, error)

NormalizeHash normalizes a commit hash to lowercase 12 chars.

func NormalizeRef

func NormalizeRef(ref string) string

NormalizeRef normalizes a ref string to canonical format.

func NormalizeRefWithContext

func NormalizeRefWithContext(ref string, currentRepository string, branch string) string

NormalizeRefWithContext normalizes a ref with repository context.

func NormalizeURL

func NormalizeURL(rawURL string) string

NormalizeURL normalizes repository URLs to HTTPS format.

func OriginDisplayAuthor added in v0.15.0

func OriginDisplayAuthor(origin *Origin) string

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

func QuoteContent(content string) string

QuoteContent prefixes each line with "> " for blockquote formatting in GitMsg-Ref metadata.

func SplitSubjectBody

func SplitSubjectBody(content string) (subject, body string)

SplitSubjectBody splits content into a subject (first line) and body (rest).

func StripRepoFromRef

func StripRepoFromRef(ref string) string

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

func UnquoteContent(metadata string) string

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

func ValidateHash(hash string) bool

ValidateHash checks if a hash is a valid 12-char hex string.

Types

type Header struct {
	Ext        string
	V          string
	Fields     map[string]string
	FieldOrder []string // extension-declared priority fields placed before alphabetical remainder
}

func ParseHeader

func ParseHeader(headerLine string) *Header

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

type Message struct {
	Content    string
	Header     Header
	References []Ref
}

func ParseMessage

func ParseMessage(message string) *Message

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

func ExtractOrigin(header *Header) *Origin

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)
}

func ParseRef

func ParseRef(ref string) ParsedRef

ParseRef parses a ref string into its components.

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

func ParseRefSection(refSection string) *Ref

ParseRefSection parses a GitMsg-Ref trailer with continuation lines into a Ref struct.

type RefType

type RefType string
const (
	RefTypeCommit  RefType = "commit"
	RefTypeBranch  RefType = "branch"
	RefTypeTag     RefType = "tag"
	RefTypeFile    RefType = "file"
	RefTypeList    RefType = "list"
	RefTypeUnknown RefType = "unknown"
)

type RepoInfo

type RepoInfo struct {
	Owner string
	Repo  string
}

func ParseRepo

func ParseRepo(rawURL string) *RepoInfo

ParseRepo extracts owner and repo name from a URL.

type RepositoryID

type RepositoryID struct {
	Repository string
	Branch     string
}

func ParseRepositoryID

func ParseRepositoryID(identifier string) RepositoryID

ParseRepositoryID parses a repository identifier into URL and branch.

type ResolvedRef

type ResolvedRef struct {
	RepoURL string
	Hash    string
	Branch  string
}

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

func ExtractTrailers(message string) []Trailer

ExtractTrailers parses recognized git trailers from the commit message footer. Returns nil if no trailers are found.

Jump to

Keyboard shortcuts

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