Documentation
¶
Overview ¶
Package trail provides types and helpers for managing trail metadata. Trails are branch-centric work tracking abstractions stored on the entire/trails/v1 orphan branch. They answer "why/what" (human intent) while checkpoints answer "how/when" (machine snapshots).
Index ¶
- Variables
- func HumanizeBranchName(branch string) string
- func ValidateID(s string) error
- type Author
- type CheckpointRef
- type Checkpoints
- type Comment
- type CommentReply
- type Discussion
- type ID
- type Metadata
- type Priority
- type Reviewer
- type ReviewerStatus
- type Status
- type Store
- func (s *Store) AddCheckpoint(ctx context.Context, trailID ID, ref CheckpointRef) error
- func (s *Store) Delete(ctx context.Context, trailID ID) error
- func (s *Store) EnsureBranch(ctx context.Context) error
- func (s *Store) FindByBranch(branchName string) (*Metadata, error)
- func (s *Store) List() ([]*Metadata, error)
- func (s *Store) Read(trailID ID) (*Metadata, *Discussion, *Checkpoints, error)
- func (s *Store) Update(ctx context.Context, trailID ID, updateFn func(*Metadata)) error
- func (s *Store) Write(ctx context.Context, metadata *Metadata, discussion *Discussion, ...) error
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrTrailNotFound = errors.New("trail not found")
ErrTrailNotFound is returned when a trail cannot be found.
Functions ¶
func HumanizeBranchName ¶
HumanizeBranchName converts a branch name into a human-readable title. It strips common prefixes (feature/, fix/, etc.), replaces dashes/underscores with spaces, and capitalizes the first word.
func ValidateID ¶
ValidateID checks if a string is a valid trail ID format.
Types ¶
type Author ¶ added in v0.6.0
Author identifies the user who created a trail. On the wire the whole object may be null when the original author can no longer be resolved (e.g. the GitHub user no longer exists), and login may independently be null while the id is retained.
type CheckpointRef ¶
type CheckpointRef struct {
CheckpointID string `json:"checkpoint_id"`
CommitSHA string `json:"commit_sha"`
CreatedAt time.Time `json:"created_at"`
Summary *string `json:"summary"`
}
CheckpointRef links a checkpoint to a trail.
type Checkpoints ¶
type Checkpoints struct {
Checkpoints []CheckpointRef `json:"checkpoints"`
}
Checkpoints holds the list of checkpoint references for a trail.
type Comment ¶
type Comment struct {
ID string `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
Resolved bool `json:"resolved"`
ResolvedBy *string `json:"resolved_by"`
ResolvedAt *time.Time `json:"resolved_at"`
Replies []CommentReply `json:"replies,omitempty"`
}
Comment represents a single comment on a trail.
type CommentReply ¶
type CommentReply struct {
ID string `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
}
CommentReply represents a reply to a comment.
type Discussion ¶
type Discussion struct {
Comments []Comment `json:"comments"`
}
Discussion holds the discussion/comments for a trail.
type ID ¶
type ID string
ID is a 12-character hex identifier for trails.
const EmptyID ID = ""
EmptyID represents an unset or invalid trail ID.
func GenerateID ¶
GenerateID creates a new random 12-character hex trail ID.
func (ID) Path ¶
Path returns the sharded storage path for this trail ID. Uses first 2 characters as shard (256 buckets), remaining as folder name. Example: "a3b2c4d5e6f7" -> "a3/b2c4d5e6f7"
func (ID) ShardParts ¶
ShardParts returns the shard prefix and suffix separately. Example: "a3b2c4d5e6f7" -> ("a3", "b2c4d5e6f7")
type Metadata ¶
type Metadata struct {
TrailID ID `json:"trail_id"`
Branch string `json:"branch"`
Base string `json:"base"`
Title string `json:"title"`
Body string `json:"body"`
Status Status `json:"status"`
Author *Author `json:"author"`
Assignees []string `json:"assignees"`
Labels []string `json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MergedAt *time.Time `json:"merged_at"`
Priority Priority `json:"priority,omitempty"`
Type Type `json:"type,omitempty"`
Reviewers []Reviewer `json:"reviewers,omitempty"`
}
Metadata represents the metadata for a trail, matching the web PR format.
func (*Metadata) AuthorLogin ¶ added in v0.6.0
AuthorLogin returns the trail author's login, or an empty string if the author is unknown (object null) or the login is null.
type Reviewer ¶
type Reviewer struct {
Login string `json:"login"`
Status ReviewerStatus `json:"status"`
}
Reviewer represents a reviewer assigned to a trail.
type ReviewerStatus ¶
type ReviewerStatus string
ReviewerStatus represents the review status for a reviewer.
const ( ReviewerPending ReviewerStatus = "pending" ReviewerApproved ReviewerStatus = "approved" ReviewerChangesRequested ReviewerStatus = "changes_requested" )
type Status ¶
type Status string
Status represents the lifecycle status of a trail.
func ValidStatuses ¶
func ValidStatuses() []Status
ValidStatuses returns all valid trail statuses in lifecycle order.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides CRUD operations for trail metadata on the entire/trails/v1 branch.
func NewStore ¶
func NewStore(repo *git.Repository) *Store
NewStore creates a new trail store backed by the given git repository.
func (*Store) AddCheckpoint ¶
AddCheckpoint prepends a checkpoint reference to a trail's checkpoints list (newest first). Only reads and writes the checkpoints.json file — metadata and discussion are untouched.
func (*Store) EnsureBranch ¶
EnsureBranch creates the entire/trails/v1 orphan branch if it doesn't exist.
func (*Store) FindByBranch ¶
FindByBranch finds a trail for the given branch name. Returns (nil, nil) if no trail exists for the branch.
func (*Store) Read ¶
func (s *Store) Read(trailID ID) (*Metadata, *Discussion, *Checkpoints, error)
Read reads a trail by its ID from the entire/trails/v1 branch.
func (*Store) Update ¶
Update updates an existing trail's metadata. It reads the current metadata, applies the provided update function, and writes it back.
func (*Store) Write ¶
func (s *Store) Write(ctx context.Context, metadata *Metadata, discussion *Discussion, checkpoints *Checkpoints) error
Write writes trail metadata, discussion, and checkpoints to the entire/trails/v1 branch. If checkpoints is nil, an empty checkpoints list is written.