app

package
v0.0.0-...-9208c1c Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration — "1h 25m", "45m".

func IsCertError

func IsCertError(err error) bool

IsCertError reports a server certificate verification error (including one that lost its type: matched by the "x509:" text).

func IsNetworkError

func IsNetworkError(err error) bool

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

func Match(f config.Filter, it plane.WorkItem, m Meta, meID string) bool

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

func NextPoll(base, prev time.Duration, err error) time.Duration

NextPoll is the next polling interval: doubles on error (429 up to 10m, otherwise up to 5m).

func ParseRef

func ParseRef(s, defaultProject string) (identifier string, seq int, ok bool)

ParseRef parses "PROJ-42", "proj-42" or "42" (with defaultProject).

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

func SearchDocs(m Meta, items []plane.WorkItem) []search.Doc

SearchDocs prepares documents for local search (C9 v4): only ID, key and title.

func StateTabs

func StateTabs(cfg *config.Config, states []plane.State) []plane.State

StateTabs returns the states for tabs (C1 v3).

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the service layer; safe to call from multiple goroutines.

func New

func New(d Deps) *App

New creates an App.

func (*App) Bookmarks

func (a *App) Bookmarks(projectID string) []string

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

func (a *App) BranchName(p plane.Project, it plane.WorkItem) (string, error)

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

func (a *App) CachedItems(projectID string) ([]plane.WorkItem, time.Time, bool)

CachedItems returns tasks from memory, otherwise from disk, with the save time.

func (*App) CachedMRs

func (a *App) CachedMRs(itemID string) ([]forge.MR, bool)

CachedMRs returns MRs from memory or cache without calling glab.

func (*App) CommandVars

func (a *App) CommandVars(p plane.Project, it plane.WorkItem) 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) Comments

func (a *App) Comments(ctx context.Context, projectID, itemID string) ([]plane.Comment, error)

Comments returns all task comments ordered by CreatedAt.

func (*App) CopyItems

func (a *App) CopyItems(p plane.Project, it plane.WorkItem) CopyItems

CopyItems prepares the values to copy.

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

func (a *App) CurrentItem(ctx context.Context) (plane.Project, plane.WorkItem, error)

CurrentItem is the task the current branch points to.

func (*App) DeleteBranches

func (a *App) DeleteBranches(names []string, force bool) map[string]error

DeleteBranches deletes branches; the result is an error per name.

func (*App) DiffStat

func (a *App) DiffStat(p plane.Project, it plane.WorkItem) (gitbranch.Stat, bool, error)

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

func (a *App) Invalidate(projectID string)

Invalidate drops the project's in-memory Meta.

func (*App) Item

func (a *App) Item(ctx context.Context, projectID, itemID string) (plane.WorkItem, error)

Item loads a task from the network and replaces it in memory and cache.

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

func (a *App) Me(ctx context.Context) (plane.Member, error)

Me returns the current user; one request per App lifetime.

func (*App) Meta

func (a *App) Meta(ctx context.Context, projectID string) (Meta, error)

Meta returns the project reference data (memory, otherwise network).

func (*App) Offline

func (a *App) Offline() (bool, time.Time)

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

func (a *App) Project(ctx context.Context, identifier string) (plane.Project, error)

Project finds a project by identifier, case-insensitively.

func (*App) Projects

func (a *App) Projects(ctx context.Context) ([]plane.Project, error)

Projects returns the workspace projects (in memory for the App lifetime).

func (*App) Prompt

func (a *App) Prompt() string

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

func (a *App) Review(ctx context.Context, p plane.Project, it plane.WorkItem) (ReviewResult, error)

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

func (a *App) ServerSearch(ctx context.Context, query, projectID string) ([]plane.SearchHit, error)

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

func (a *App) StaleBranches(ctx context.Context, p plane.Project) ([]Stale, error)

StaleBranches returns branches of the project's tasks in completed|cancelled groups, except the current one.

func (*App) Start

Start creates a branch (or worktree), writes the commit template and moves the task to in progress.

func (*App) StartTimer

func (a *App) StartTimer(projectID, itemID string) error

StartTimer starts a timer; if one is already running, nothing changes.

func (*App) StopTimer

func (a *App) StopTimer(ctx context.Context, projectID, itemID, note string) (time.Duration, error)

StopTimer comments the time spent and removes the timer (only after a successful comment).

func (*App) Timers

func (a *App) Timers() []Timer

Timers returns the running timers by start time.

func (*App) ToggleBookmark

func (a *App) ToggleBookmark(projectID, itemID string) (bool, error)

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.

func (*App) Update

func (a *App) Update(ctx context.Context, projectID, itemID string, p plane.WorkItemPatch) (plane.WorkItem, error)

Update applies a patch and replaces the task in memory and cache.

type Changes

type Changes struct {
	New, Updated []plane.WorkItem
	Removed      []string
}

Changes are the differences between two task list snapshots (by ID).

func Diff

func Diff(old, cur []plane.WorkItem) Changes

Diff compares snapshots; Updated means UpdatedAt changed.

func (Changes) Empty

func (c Changes) Empty() bool

Empty reports no changes.

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 Node

type Node struct {
	Item     plane.WorkItem
	Children []*Node
	Depth    int
}

Node is a task in the subtask tree.

func Tree

func Tree(items []plane.WorkItem) []*Node

Tree builds a forest by ParentID within items; a parent outside the list makes the task a root; tasks on a cycle become roots. Order is as in the input.

type ReviewResult

type ReviewResult struct {
	MRURL, State string
	Warnings     []string
}

ReviewResult is the outcome of "ready for review".

type Stale

type Stale struct {
	Branch string
	Item   plane.WorkItem
}

Stale is a local task branch that can be removed.

type StartOptions

type StartOptions struct {
	Branch   string // empty: BranchName
	Worktree *bool  // nil — cfg.Branch.Worktree
}

StartOptions are the parameters of "start work".

type StartResult

type StartResult struct {
	Branch   gitbranch.Result
	State    string // name of the new state; "" if unchanged
	Assigned bool
	Warnings []string
}

StartResult is the outcome of "start work".

type Timer

type Timer struct {
	ProjectID, ItemID string
	Started           time.Time
}

Timer is a running task timer.

Jump to

Keyboard shortcuts

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