handlers

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package handlers provides shared handler interfaces for CLI output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONRestackHandler

type JSONRestackHandler struct {
	Result *RestackJSONResult
	// contains filtered or unexported fields
}

JSONRestackHandler collects restack results for JSON output. All methods are mutex-protected so concurrent callers (parallel restack) are safe.

func NewJSONRestackHandler

func NewJSONRestackHandler() *JSONRestackHandler

NewJSONRestackHandler creates a new JSON handler

func (*JSONRestackHandler) OnRestackBranch

func (h *JSONRestackHandler) OnRestackBranch(branch string, result RestackResult, newRev string, prNumber *int, _ engine.LockReason, _ bool, _ bool, parent string, _ bool, _, _ string, rerereResolvedCount int)

OnRestackBranch implements RestackHandler.

func (*JSONRestackHandler) OnRestackComplete

func (h *JSONRestackHandler) OnRestackComplete(restacked, _ int, _ []string)

OnRestackComplete implements RestackHandler.

func (*JSONRestackHandler) OnRestackStart

func (h *JSONRestackHandler) OnRestackStart(branchCount int)

OnRestackStart implements RestackHandler.

func (*JSONRestackHandler) SetError

func (h *JSONRestackHandler) SetError(err error)

SetError sets the error status and message on the result. Call this when the restack action returns an error.

func (*JSONRestackHandler) SetLastBranchStackRoot

func (h *JSONRestackHandler) SetLastBranchStackRoot(branch, stackRoot string)

SetLastBranchStackRoot annotates the most recently added restacked or conflict entry for the given branch with its independent stack root. It also maintains the deduped top-level StackRoots list. Called outside the handler interface so only JSON output is enriched without touching all implementors.

type NullRestackHandler

type NullRestackHandler struct{}

NullRestackHandler is a no-op handler for testing or when output is not needed

func (*NullRestackHandler) OnRestackBranch

func (h *NullRestackHandler) OnRestackBranch(_ string, _ RestackResult, _ string, _ *int, _ engine.LockReason, _ bool, _ bool, _ string, _ bool, _, _ string, _ int)

OnRestackBranch implements RestackHandler.

func (*NullRestackHandler) OnRestackComplete

func (h *NullRestackHandler) OnRestackComplete(_, _ int, _ []string)

OnRestackComplete implements RestackHandler.

func (*NullRestackHandler) OnRestackStart

func (h *NullRestackHandler) OnRestackStart(_ int)

OnRestackStart implements RestackHandler.

type RestackBranchInfo

type RestackBranchInfo struct {
	Name                string `json:"name"`
	Parent              string `json:"parent"`
	StackRoot           string `json:"stack_root,omitempty"` // Independent stack root this branch belongs to
	NewRev              string `json:"new_rev,omitempty"`
	PRNumber            *int   `json:"pr_number,omitempty"`
	RerereResolvedCount int    `json:"rerere_resolved_count,omitempty"`
}

RestackBranchInfo represents info about a restacked branch

type RestackConflictInfo

type RestackConflictInfo struct {
	Branch    string `json:"branch"`
	Parent    string `json:"parent"`
	StackRoot string `json:"stack_root,omitempty"` // Independent stack root this branch belongs to
}

RestackConflictInfo represents a conflict during restack

type RestackHandler

type RestackHandler interface {
	// OnRestackStart is called at the beginning of restack with branch count
	OnRestackStart(branchCount int)

	// OnRestackBranch is called for each branch during restack
	OnRestackBranch(branch string, result RestackResult, newRev string, prNumber *int, lockReason engine.LockReason, frozen bool, isCurrent bool, parent string, reparented bool, oldParent, newParent string, rerereResolvedCount int)

	// OnRestackComplete is called when restack finishes
	OnRestackComplete(restacked, skipped int, conflicts []string)
}

RestackHandler abstracts TTY vs non-TTY output for restack operations This interface is shared between sync, get, and restack commands

type RestackJSONResult

type RestackJSONResult struct {
	Status        RestackJSONStatus     `json:"status"`
	Error         string                `json:"error,omitempty"`
	Restacked     []RestackBranchInfo   `json:"restacked,omitempty"`
	Skipped       []string              `json:"skipped,omitempty"`
	Conflicts     []RestackConflictInfo `json:"conflicts,omitempty"`
	StackRoots    []string              `json:"stack_roots,omitempty"` // Deduped independent stack roots that were processed
	TotalCount    int                   `json:"total_count"`
	RestackCount  int                   `json:"restack_count"`
	ConflictCount int                   `json:"conflict_count"`
}

RestackJSONResult represents the JSON output for restack operations

type RestackJSONStatus

type RestackJSONStatus string

RestackJSONStatus represents the aggregate outcome of a JSON restack operation.

const (
	RestackJSONStatusSuccess  RestackJSONStatus = "success"
	RestackJSONStatusConflict RestackJSONStatus = "conflict"
	RestackJSONStatusError    RestackJSONStatus = "error"
)

type RestackResult

type RestackResult string

RestackResult represents the outcome of a restack operation for a single branch

const (
	// RestackDone indicates the branch was successfully restacked
	RestackDone RestackResult = "done"
	// RestackUnneeded indicates the branch didn't need restacking
	RestackUnneeded RestackResult = "unneeded"
	// RestackConflict indicates the branch had a conflict
	RestackConflict RestackResult = "conflict"
)

Jump to

Keyboard shortcuts

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