Documentation
¶
Overview ¶
Package services answers the runtime's routes that only call external services with the person's tokens: a session's pushes and merge requests on GitLab, a merge request or commit with its diff, link previews (tracker issues, merge requests, published documents), tracker avatars, project keys and task cards, and site icons. The organizer (a small file of the person's own) and the page's start data are here too. Answers, caches and their lifetimes are the previous runtime's; the GitLab walk asks git only what it needs, runs its requests in parallel and keeps their answers a few seconds.
Index ¶
- Constants
- Variables
- func AvatarLink(route, src string) string
- func GitLabSelfToken(cfg Config) string
- func OriginOf(raw string) string
- func TrackerToken(cfg Config) string
- func ValidIconHost(host string) bool
- func ValidPick(p PickRequest) string
- type Bootstrap
- type Config
- type Handlers
- func (h *Handlers) Avatar(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) ChangeView(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Favicon(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) ForgeAvatar(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GitLab(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GitLabPick(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GitLabView(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) LinkMeta(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Organizer(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Projects(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Task(w http.ResponseWriter, r *http.Request)
- type Image
- type MergeRequestInfo
- type OrganizerError
- type PickRequest
- type Service
- func (s *Service) ApplyOrganizer(ops []*organizerOp, nowMs float64) (*jsvalue.Object, *OrganizerError, error)
- func (s *Service) Apps(ctx context.Context, only ...wire.AppID) wire.AppsFeed
- func (s *Service) BareTask(ctx context.Context, key string) (*jsvalue.Object, string)
- func (s *Service) ChangeFile(ctx context.Context, raw, oldPath, newPath string) (*jsvalue.Object, error)
- func (s *Service) ChangeView(ctx context.Context, raw string) (*jsvalue.Object, error)
- func (s *Service) ConnTask(ctx context.Context, conn, key string) (*jsvalue.Object, string)
- func (s *Service) ConnTaskKey(conn, key string) bool
- func (s *Service) ForgeAvatar(ctx context.Context, src string, extra []string) (*Image, error)
- func (s *Service) GitLabPick(ctx context.Context, p PickRequest) *jsvalue.Object
- func (s *Service) GitLabView(ctx context.Context, raw string) (*jsvalue.Object, error)
- func (s *Service) IsChangeRef(raw string) bool
- func (s *Service) IsGitLabRef(raw string) bool
- func (s *Service) IsTaskKey(v any) bool
- func (s *Service) MergeRequest(ctx context.Context, host, project string, iid int) (MergeRequestInfo, bool)
- func (s *Service) Organizer() (*jsvalue.Object, error)
- func (s *Service) ProjectKeys(ctx context.Context) ([]any, error)
- func (s *Service) ProjectPaths(ctx context.Context, host, name string) []string
- func (s *Service) SessionGitLab(ctx context.Context, paths []string, since *float64, mentioned []string) (*jsvalue.Object, error)
- func (s *Service) SiteIcon(ctx context.Context, host string) *Image
- func (s *Service) Task(ctx context.Context, key string) (*jsvalue.Object, string)
- func (s *Service) TrackerAvatar(ctx context.Context, login string) (*Image, error)
Constants ¶
const ( PickProjects = "projects" PickMRs = "mrs" PickBranches = "branches" PickCommits = "commits" )
Pick lists: what `list=` asks for.
const ( PickOpen = "open" PickReview = "review" PickMine = "mine" )
Merge request filters: open ones, the ones waiting for my review, my own.
const ( TaskNotFound = "not-found" TaskNoToken = "no-token" TaskTracker = "tracker" TaskAccountRequired = "account-required" )
Task errors and their statuses.
Variables ¶
var ErrOrganizerUnreadable = errors.New("organizer-unreadable")
ErrOrganizerUnreadable: the file exists but cannot be trusted; the route answers 500.
var ( // HostRe is a host name the icon route serves. HostRe = regexp.MustCompile(`^[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})+$`) )
var LoginRe = regexp.MustCompile(`^[\w.@-]{1,100}$`)
LoginRe is a tracker login the avatar route serves.
Functions ¶
func AvatarLink ¶
AvatarLink is the address the page loads a code host's avatar by: route with the picture's own address in ?src=. Empty for an address that is not an https one.
func GitLabSelfToken ¶ added in v0.16.86
GitLabSelfToken is the token of the deployment's own GitLab (the first of GitLabHosts) as the GitLab routes read it; "" without one.
func OriginOf ¶
OriginOf is the origin of an http(s) address (scheme, host and non-default port), "" for anything else. A deployment names its documents and boards services by it.
func TrackerToken ¶ added in v0.16.86
TrackerToken is the deployment tracker's token as the tracker routes read it (YOUTRACK_TOKEN, else a youtrack-token file in a secret folder of a home); "" without a tracker or a token. Read on every call.
func ValidIconHost ¶
ValidIconHost: a public name, not an address, not a local or internal one.
func ValidPick ¶
func ValidPick(p PickRequest) string
ValidPick says why a request cannot be asked; "" when it can.
Types ¶
type Bootstrap ¶
type Bootstrap struct {
DataDir string
// ConfigFile is the runtime's settings file.
ConfigFile string
// HostLocked: the deployment fixed the listening address (the previous runtime's HOST).
HostLocked bool
// BindLocal: the previous runtime listens on loopback only.
BindLocal bool
// Owner is the person a request's session names (its token's sub), nil without one.
Owner func(*http.Request) any
// Tools reports whether tmux (a compatible one) and git are installed; it may be slow.
Tools func() bool
// CreateFirst makes the machine's first workspace when it has none, before the answer is read; nil leaves an empty
// machine empty.
CreateFirst func() error
Now func() time.Time
// contains filtered or unexported fields
}
Bootstrap answers the page's start data from this machine's files: the person, whether tmux and git are usable, the workspaces, the settings without their secrets, the quick prompts and the sidebar items. Creating the first workspace of an empty machine is the layout store's work (CreateFirst).
func (*Bootstrap) HasWorkspaces ¶
HasWorkspaces: the machine has a workspace already, so the answer needs no new one.
type Config ¶
type Config struct {
// Home is the runtime user's home: Claude Code and Codex transcripts are under it.
Home string
// SecretDirs are home-relative folders that hold token files (".config/<app>"), searched in order.
SecretDirs []string
// GitLabHosts are the GitLabs links and remotes may point at; the first is the self-hosted one, which reads its
// own token.
GitLabHosts []string
// GitLabAPI is the origin the GitLab API is read from when it is not https://<host> (a stand-in in the browser
// tests); empty for the GitLabs themselves.
GitLabAPI string
// GitHubHost is the GitHub whose pull requests, commits and issues a tab shows ("" is github.com); GitHubAPI the
// origin its API is read from when it is not the host's own (a stand-in in tests). GitHubTokenCmd asks for the
// person's token (nil is `gh auth token`).
GitHubHost, GitHubAPI string
GitHubTokenCmd []string
// TrackerURL is the issue tracker's origin (https://tracker.example.com); TrackerHosts the hosts its issue links use.
TrackerURL string
TrackerHosts []string
// DocsHost serves published documents (/a/<slug>) and boards (/b/<slug>); ReaderHost and ReaderPath are where the
// platform shows the same document.
// StandDomain: every <name>.<StandDomain> is a feature stand, whose card says whether it answers.
StandDomain string
DocsHost string
// PortalOrigins are the origins (scheme, host and port) of the documents and boards services when they are not one
// https host: a workspace on http://localhost with a port per service. Links on them get the same metadata as links
// on DocsHost. The first one is where the platform's reader links are mapped to.
PortalOrigins []string
ReaderHost string
ReaderPath string
// TaskKey is a task key the task card serves.
TaskKey *regexp.Regexp
// AvatarPath is the route that serves tracker avatars, as the page loads it.
AvatarPath string
// ForgeAvatarPath is the route that serves the avatars of code hosts' people, as the page loads it.
ForgeAvatarPath string
// IconAgent is the User-Agent of site icon requests.
IconAgent string
// OrganizerFile is the person's organizer.
OrganizerFile string
// Transport carries every outgoing request; nil is the default one.
Transport http.RoundTripper
// Connections are the person's trackers and wikis (internal/connections); nil for none. The tracker app, task cards
// and link previews read a connection that is not the deployment's tracker through it.
Connections *connections.Service
// StrictConnections requires an unambiguous account for native tracker cards, previews and the tracker feed.
StrictConnections bool
}
Config is what the deployment names.
type Handlers ¶
type Handlers struct {
S *Service
// Session: the request carries a page session (a cli-token alone is not a person).
Session func(*http.Request) bool
// Now is the clock of the organizer's timestamps; nil is time.Now.
Now func() time.Time
// ForgeHosts are the hosts of the person's code host connections, whose avatars the avatar route also serves.
ForgeHosts func() []string
ManagedChange func(http.ResponseWriter, *http.Request, string) bool
}
Handlers answer the routes as the previous runtime's dispatcher and handlers did, after the caller passed the API's own check (a page session or the cli-token): the body read first (413, "Invalid JSON"), then each handler's session check, statuses, headers, JSON with its ETag and 304, and the plain 500 of a handler that threw.
func (*Handlers) Avatar ¶
func (h *Handlers) Avatar(w http.ResponseWriter, r *http.Request)
Avatar: ?login=, a tracker user's avatar, any method.
func (*Handlers) ChangeView ¶ added in v0.15.40
func (h *Handlers) ChangeView(w http.ResponseWriter, r *http.Request)
ChangeView: GET ?url=, a merge request, pull request, commit or issue of GitLab or GitHub with its checks, discussion and diff. A GitHub link that cannot be read answers a card with the reason (200), so the tab is never empty.
func (*Handlers) Favicon ¶
func (h *Handlers) Favicon(w http.ResponseWriter, r *http.Request)
Favicon: ?host=, a public site's icon, any method.
func (*Handlers) ForgeAvatar ¶
func (h *Handlers) ForgeAvatar(w http.ResponseWriter, r *http.Request)
ForgeAvatar: ?src=, the avatar of a code host's person at the address the host gave, any method.
func (*Handlers) GitLab ¶
func (h *Handlers) GitLab(w http.ResponseWriter, r *http.Request)
GitLab: POST {paths, jsonlPath, mrs}, a session's pushes and merge requests with live pipeline status.
func (*Handlers) GitLabPick ¶
func (h *Handlers) GitLabPick(w http.ResponseWriter, r *http.Request)
GitLabPick: GET ?list=projects|mrs|branches|commits&project=&filter=open|review|mine&q=&ref=, one list of the review picker. A GitLab that is off or refuses answers its state (200) with no items.
func (*Handlers) GitLabView ¶
func (h *Handlers) GitLabView(w http.ResponseWriter, r *http.Request)
GitLabView: GET ?url=, a merge request or a commit with its diff.
func (*Handlers) LinkMeta ¶
func (h *Handlers) LinkMeta(w http.ResponseWriter, r *http.Request)
LinkMeta: GET ?url= (a tracker issue, a merge request, a published document) or ?key= (a bare task key).
func (*Handlers) Organizer ¶
func (h *Handlers) Organizer(w http.ResponseWriter, r *http.Request)
Organizer: GET reads the person's projects and pins, PATCH {ops} changes them.
type MergeRequestInfo ¶ added in v0.15.40
type MergeRequestInfo struct {
URL string
Title string
// UpdatedAt is when it last changed, as GitLab wrote it (RFC 3339); "" when it did not say.
UpdatedAt string
}
MergeRequestInfo is a merge request GitLab gave: where it lives now (a renamed project answers under its new path) and what it is called.
type OrganizerError ¶
OrganizerError is a refused change: its status and body.
func ParseOrganizerOps ¶
func ParseOrganizerOps(body any) ([]*organizerOp, *OrganizerError)
ParseOrganizerOps validates a PATCH body: {ops: [1..50 ops]}.
type PickRequest ¶
type PickRequest struct {
List string
Project string // group/sub/project
Filter string // mrs: open, review, mine
Query string
Ref string // commits: the branch
}
PickRequest is one question of the picker.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds the caches the answers share.
func (*Service) ApplyOrganizer ¶
func (s *Service) ApplyOrganizer(ops []*organizerOp, nowMs float64) (*jsvalue.Object, *OrganizerError, error)
ApplyOrganizer applies every op, all or nothing, and writes the file only when something changed.
func (*Service) Apps ¶ added in v0.15.40
Apps reads the apps of the screen (`only` of them; none: all), in parallel. An answer is kept for appsFresh, and shown at once for appsKeep while a new read runs behind it; one that is not ready is not kept, so a token put in place is taken on the next look.
func (*Service) BareTask ¶
BareTask keeps the primary connection and the deployment's tracker first. After both miss or lack access, it looks for the same key in the person's other trackers, in connection order.
func (*Service) ChangeFile ¶
func (s *Service) ChangeFile(ctx context.Context, raw, oldPath, newPath string) (*jsvalue.Object, error)
ChangeFile is both versions of one file of a GitLab merge request or commit, read at the change's base and head commits: oldContent, newContent, truncated, binary. An empty path is an empty side (an added or a deleted file). nil when the link is not GitLab's or the token does not reach the change.
func (*Service) ChangeView ¶ added in v0.15.40
ChangeView is the change a link names with its checks and discussion. nil when the service does not give it to this token (GitLab) — GitHub answers a card with the reason instead, so the tab never stays empty.
func (*Service) ConnTask ¶ added in v0.16.86
ConnTask is one issue of a connection for the card, kept and shared like Task. Callers check ConnTaskKey first.
func (*Service) ConnTaskKey ¶ added in v0.16.86
ConnTaskKey says whether the card serves key from a connection: conn names it ("" is the personal one), and the key is not one the deployment's tracker serves.
func (*Service) ForgeAvatar ¶
ForgeAvatar is the picture at src, an avatar address a code host gave; nil when it is not one this runtime fetches or the host gave no picture. extra are the hosts of the person's code host connections.
func (*Service) GitLabPick ¶
GitLabPick answers one list of the picker.
func (*Service) GitLabView ¶
GitLabView is what a tab shows of a merge request or a commit; nil when GitLab does not give it to this token.
func (*Service) IsChangeRef ¶ added in v0.15.40
IsChangeRef: the change view serves this link.
func (*Service) IsGitLabRef ¶
IsGitLabRef: the view route serves this link.
func (*Service) MergeRequest ¶ added in v0.15.40
func (s *Service) MergeRequest(ctx context.Context, host, project string, iid int) (MergeRequestInfo, bool)
MergeRequest asks the GitLab at host, with its own token, for the merge request numbered iid of a project path. false for any "no": the merge request or the project is not there, the token cannot see it, there is no token, the GitLab is not reachable or is not one of the deployment's. The answers are shared with the tab that shows it.
func (*Service) ProjectKeys ¶
ProjectKeys are the short names of the tracker's live projects, kept an hour; a failed read gives the last list.
func (*Service) ProjectPaths ¶ added in v0.15.40
ProjectPaths are the paths (group/sub/project) of the projects of the GitLab at host whose last segment is name, as its search finds them with the host's own token; nil for any "no". The answer is shared like the rest.
func (*Service) SessionGitLab ¶
func (s *Service) SessionGitLab(ctx context.Context, paths []string, since *float64, mentioned []string) (*jsvalue.Object, error)
SessionGitLab is what a session sent to GitLab: its branches with their last pipeline, and the merge requests with theirs. since is the session's start (ms), nil without a transcript; a commit of the session is what makes a repository count, so without one no git or GitLab work is needed for the repositories.