Documentation
¶
Overview ¶
Package app is the platui service layer: scenarios on top of plane, gitbranch, forge and cache, shared by the TUI and the CLI (contract C5 v1).
Index ¶
- Constants
- Variables
- func FormatDuration(d time.Duration) string
- func IsCertError(err error) bool
- func IsNetworkError(err error) bool
- func Match(f config.Filter, it plane.WorkItem, m Meta, meID string) bool
- func NextPoll(base, prev time.Duration, err error) time.Duration
- func ParseRef(s, defaultProject string) (identifier string, seq int, ok bool)
- func RenderCommand(tmpl string, v CommandVars) string
- func SearchDocs(m Meta, items []plane.WorkItem) []search.Doc
- func StateTabs(cfg *config.Config, states []plane.State) []plane.State
- type App
- func (a *App) Bookmarks(projectID string) []string
- func (a *App) Branch(p plane.Project, it plane.WorkItem, name string, worktree *bool, ...) (gitbranch.Result, error)
- func (a *App) BranchName(p plane.Project, it plane.WorkItem) (string, error)
- func (a *App) BranchStatuses(p plane.Project, items []plane.WorkItem) (map[string]gitbranch.BranchStatus, error)
- func (a *App) BulkAssign(ctx context.Context, projectID string, items []plane.WorkItem, memberID string, ...) map[string]error
- func (a *App) BulkLabel(ctx context.Context, projectID string, items []plane.WorkItem, labelID string, ...) map[string]error
- func (a *App) BulkPatch(ctx context.Context, projectID string, ids []string, p plane.WorkItemPatch) map[string]error
- func (a *App) CachedItems(projectID string) ([]plane.WorkItem, time.Time, bool)
- func (a *App) CachedMRs(itemID string) ([]forge.MR, bool)
- func (a *App) CommandVars(p plane.Project, it plane.WorkItem) CommandVars
- func (a *App) Comment(ctx context.Context, projectID, itemID, markdown string) (plane.Comment, error)
- func (a *App) Comments(ctx context.Context, projectID, itemID string) ([]plane.Comment, error)
- func (a *App) CopyItems(p plane.Project, it plane.WorkItem) CopyItems
- func (a *App) CreateQuick(ctx context.Context, projectID, line, descMarkdown string) (plane.WorkItem, error)
- func (a *App) CurrentItem(ctx context.Context) (plane.Project, plane.WorkItem, error)
- func (a *App) DeleteBranches(names []string, force bool) map[string]error
- func (a *App) DiffStat(p plane.Project, it plane.WorkItem) (gitbranch.Stat, bool, error)
- func (a *App) Find(ctx context.Context, identifier string, seq int) (plane.Project, plane.WorkItem, error)
- func (a *App) Invalidate(projectID string)
- func (a *App) Item(ctx context.Context, projectID, itemID string) (plane.WorkItem, error)
- func (a *App) MRs(ctx context.Context, p plane.Project, it plane.WorkItem, fresh bool) ([]forge.MR, error)
- func (a *App) Me(ctx context.Context) (plane.Member, error)
- func (a *App) Meta(ctx context.Context, projectID string) (Meta, error)
- func (a *App) Offline() (bool, time.Time)
- func (a *App) Project(ctx context.Context, identifier string) (plane.Project, error)
- func (a *App) Projects(ctx context.Context) ([]plane.Project, error)
- func (a *App) Prompt() string
- func (a *App) RefreshItems(ctx context.Context, projectID string) ([]plane.WorkItem, Changes, error)
- func (a *App) Reload(ctx context.Context, projectID string) (Meta, []plane.WorkItem, Changes, error)
- func (a *App) Review(ctx context.Context, p plane.Project, it plane.WorkItem) (ReviewResult, error)
- func (a *App) RunCommand(ctx context.Context, c config.Command, v CommandVars) (runner.Result, error)
- func (a *App) ServerSearch(ctx context.Context, query, projectID string) ([]plane.SearchHit, error)
- func (a *App) SetDescription(ctx context.Context, projectID, itemID, markdown string) (plane.WorkItem, error)
- func (a *App) StaleBranches(ctx context.Context, p plane.Project) ([]Stale, error)
- func (a *App) Start(ctx context.Context, p plane.Project, it plane.WorkItem, o StartOptions) (StartResult, error)
- func (a *App) StartTimer(projectID, itemID string) error
- func (a *App) StopTimer(ctx context.Context, projectID, itemID, note string) (time.Duration, error)
- func (a *App) Timers() []Timer
- func (a *App) ToggleBookmark(projectID, itemID string) (bool, error)
- func (a *App) Update(ctx context.Context, projectID, itemID string, p plane.WorkItemPatch) (plane.WorkItem, error)
- type Changes
- type CommandVars
- type CopyItems
- type Deps
- type Meta
- type Node
- type ReviewResult
- type Stale
- type StartOptions
- type StartResult
- type Timer
Constants ¶
const CertHint = "server certificate is not trusted — set the CA in http.ca_file"
CertHint is the hint for a server certificate verification error (C10 v5).
Variables ¶
var ( ErrNoRepo = errors.New("not in a git repository") ErrNoItemForBranch = errors.New("current branch does not reference a work item") ErrItemNotFound = errors.New("work item not found") ErrProjectNotFound = errors.New("project not found") ErrUnknownMember = errors.New("unknown member") ErrUnknownLabel = errors.New("unknown label") ErrNoTimer = errors.New("no running timer") )
Scenario errors.
Functions ¶
func IsCertError ¶
IsCertError reports a server certificate verification error (including one that lost its type: matched by the "x509:" text).
func IsNetworkError ¶
IsNetworkError reports a network error per C10 v4 (exit code 4): *url.Error, net.Error, context.DeadlineExceeded, a dropped connection (io.ErrUnexpectedEOF, ECONNRESET), TLS/x509, APIError with status >= 500, plane.ErrRateLimited. Authorization, 404, cancellation, response parsing and other errors are not network errors. An error that lost its type when wrapped as text is recognized by the network stack's characteristic messages.
func Match ¶
Match checks a task against a saved filter: criteria are ANDed, values within a list are ORed. The caller applies the filter's Project field itself (project selection).
func NextPoll ¶
NextPoll is the next polling interval: doubles on error (429 up to 10m, otherwise up to 5m).
func RenderCommand ¶
func RenderCommand(tmpl string, v CommandVars) string
RenderCommand substitutes the placeholders; values are escaped for sh (single quotes), and the substituted text is not interpreted again.
func SearchDocs ¶
SearchDocs prepares documents for local search (C9 v4): only ID, key and title.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the service layer; safe to call from multiple goroutines.
func (*App) Bookmarks ¶
Bookmarks returns the project's bookmarked IDs in the order they were added.
func (*App) Branch ¶
func (a *App) Branch(p plane.Project, it plane.WorkItem, name string, worktree *bool, switchExisting bool) (gitbranch.Result, error)
Branch creates a task branch (or worktree) without changes in Plane (the b key, C5 v4). Empty name means BranchName; nil worktree means cfg.Branch.Worktree; an existing branch is switched to only with switchExisting, otherwise it returns Result{Name} and ErrBranchExists.
func (*App) BranchName ¶
BranchName returns the task branch name from the template.
func (*App) BranchStatuses ¶
func (a *App) BranchStatuses(p plane.Project, items []plane.WorkItem) (map[string]gitbranch.BranchStatus, error)
BranchStatuses returns task branch statuses (key is the task ID): the template branch and local branches with the same task ID. Tasks without branches are skipped.
func (*App) BulkAssign ¶
func (a *App) BulkAssign(ctx context.Context, projectID string, items []plane.WorkItem, memberID string, add bool) map[string]error
BulkAssign adds or removes an assignee.
func (*App) BulkLabel ¶
func (a *App) BulkLabel(ctx context.Context, projectID string, items []plane.WorkItem, labelID string, add bool) map[string]error
BulkLabel adds or removes a label.
func (*App) BulkPatch ¶
func (a *App) BulkPatch(ctx context.Context, projectID string, ids []string, p plane.WorkItemPatch) map[string]error
BulkPatch applies one patch to the tasks.
func (*App) CachedItems ¶
CachedItems returns tasks from memory, otherwise from disk, with the save time.
func (*App) CommandVars ¶
CommandVars builds the placeholders: ID is the task identifier in Plane, Key is PROJ-N, MRURL is the first MR from the cache or "".
func (*App) Comment ¶
func (a *App) Comment(ctx context.Context, projectID, itemID, markdown string) (plane.Comment, error)
Comment adds a comment from Markdown.
func (*App) CreateQuick ¶
func (a *App) CreateQuick(ctx context.Context, projectID, line, descMarkdown string) (plane.WorkItem, error)
CreateQuick creates a task from the line "title !prio @user #label".
func (*App) CurrentItem ¶
CurrentItem is the task the current branch points to.
func (*App) DeleteBranches ¶
DeleteBranches deletes branches; the result is an error per name.
func (*App) DiffStat ¶
DiffStat is the size of the task branch changes relative to cfg.Branch.Base. The branch is determined as in BranchStatuses; no local branch or nil Git → ok=false.
func (*App) Find ¶
func (a *App) Find(ctx context.Context, identifier string, seq int) (plane.Project, plane.WorkItem, error)
Find looks up a task by project key and number.
func (*App) Invalidate ¶
Invalidate drops the project's in-memory Meta.
func (*App) MRs ¶
func (a *App) MRs(ctx context.Context, p plane.Project, it plane.WorkItem, fresh bool) ([]forge.MR, error)
MRs returns the task's MRs via glab; the result is cached for cfg.GitLab.MRCache (fresh bypasses the cache).
func (*App) Offline ¶
Offline is true if the last network attempt failed and the data came from the cache; the time is the saved time of the oldest cache served.
func (*App) Prompt ¶
Prompt returns the line for a shell/tmux prompt: cache and git only, no network.
func (*App) RefreshItems ¶
func (a *App) RefreshItems(ctx context.Context, projectID string) ([]plane.WorkItem, Changes, error)
RefreshItems loads tasks, computes the differences from the previous snapshot (memory, otherwise cache) and saves. No previous snapshot: Changes is empty.
func (*App) Reload ¶
func (a *App) Reload(ctx context.Context, projectID string) (Meta, []plane.WorkItem, Changes, error)
Reload refreshes bypassing the cache; an error leaves the previous data untouched.
func (*App) Review ¶
Review pushes the branch, creates an MR (GitLab), comments on the task and moves it to review.
func (*App) RunCommand ¶
func (a *App) RunCommand(ctx context.Context, c config.Command, v CommandVars) (runner.Result, error)
RunCommand runs the command at the repository root (nil Git: in the current directory).
func (*App) ServerSearch ¶
ServerSearch is a server-side search (up to 50 results); empty projectID means the whole workspace.
func (*App) SetDescription ¶
func (a *App) SetDescription(ctx context.Context, projectID, itemID, markdown string) (plane.WorkItem, error)
SetDescription replaces the task description (Markdown → HTML).
func (*App) StaleBranches ¶
StaleBranches returns branches of the project's tasks in completed|cancelled groups, except the current one.
func (*App) Start ¶
func (a *App) Start(ctx context.Context, p plane.Project, it plane.WorkItem, o StartOptions) (StartResult, error)
Start creates a branch (or worktree), writes the commit template and moves the task to in progress.
func (*App) StartTimer ¶
StartTimer starts a timer; if one is already running, nothing changes.
func (*App) StopTimer ¶
StopTimer comments the time spent and removes the timer (only after a successful comment).
func (*App) ToggleBookmark ¶
ToggleBookmark sets or clears a bookmark; on reports whether it is set after the call. A cache write failure is returned as an error; the in-memory state is kept.
type Changes ¶
Changes are the differences between two task list snapshots (by ID).
type CommandVars ¶
type CommandVars struct{ ID, Key, Branch, URL, Title, MRURL string }
CommandVars holds the placeholder values for custom commands.
type CopyItems ¶
type CopyItems struct{ ID, URL, Title, Branch, Markdown string }
CopyItems holds the lines for the clipboard.
type Deps ¶
type Deps struct {
API plane.API
Git gitbranch.Git // nil: not a git repository, git scenarios return ErrNoRepo
Forge forge.Tool // nil: forge.New from cfg.GitLab
Store cache.Store // nil: no cache
Config *config.Config
Now func() time.Time // nil → time.Now
Shell runner.Shell // nil → runner.Default()
}
Deps are the external dependencies of the scenarios.
type Meta ¶
type Meta struct {
Project plane.Project
States []plane.State
Members []plane.Member
Labels []plane.Label
}
Meta holds the project reference data.
type ReviewResult ¶
ReviewResult is the outcome of "ready for review".
type StartOptions ¶
type StartOptions struct {
Branch string // empty: BranchName
Worktree *bool // nil — cfg.Branch.Worktree
}
StartOptions are the parameters of "start work".