hooks

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 38 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 hooks is the Hooks page's service: the clones in the repository locations with a go-pre-commit config, the pre-commit hook in each, and what go-pre-commit does in them on the user's click, installing, updating, replacing, or removing the hook, and running the checks.

The scan reads, for each clone with a config inside it (a .github/env/*.env file, or .github/.env.base; go-pre-commit also searches the folders above, the app doesn't), where git runs its hooks (gitread's HookPaths, which leaves core.hooksPath alone), its pre-commit hook (missing, go-pre-commit's by its marker, or another tool's, named where its text tells), and ENABLE_GO_PRE_COMMIT and the checks' switches from the config files themselves. A hooks folder outside both the clone's git folder and its work tree is shared, and the scan counts the clones that use it. Whether go-pre-commit's own hook is current is a byte comparison with the hook that copy writes, which only `go-pre-commit status` makes; it runs in a scratch repository of the app's own that holds the hook's bytes, never in a clone, whose .env files go-pre-commit would load into its environment, PATH included, before it runs git. The answer is kept per copy and per hook's SHA-256, so status runs once for bytes no one judged, never once per clone. Four clones are scanned at once, and the scan runs no program a clone names.

Every action and every checks run goes through scriptrun, which holds the clone's lock, and its spec's Before reads the clone again under that lock. A shared hooks folder blocks every action until the user confirms that folder. An action is judged afterwards from the hook file itself, never from the exit status alone: go-pre-commit 1.13 exits 0 even when another tool's hook stopped it. A checks run takes git's porcelain v2 status of the clone before and after, with every dirty file's SHA-256, so the result names each file the checks changed or staged, one that was already dirty included.

go-pre-commit 1.13's output is read as text, from patterns recorded in testdata/go-pre-commit-1.13.1; a copy whose Definition.Features has StatusJSON or RunJSON is asked for JSON instead.

Nothing here changes a clone, nor runs git that could: go-pre-commit does, on the user's click. Nothing here reaches the network.

Index

Constants

View Source
const (

	// FreshFor is how long a scan is served before Repos scans every clone again. A clone
	// an action or a check ran in is scanned again at once.
	FreshFor = 5 * time.Minute

	// ScanTimeout bounds a scan the page's callers share. A scan runs apart from the
	// caller that started it, so a window that asks again (as it does when a run starts or
	// ends) or closes doesn't throw away a scan half done: the caller stops waiting, and
	// the scan goes on and is kept for the next one. The app's quit ends it sooner (Scans).
	ScanTimeout = 5 * time.Minute
)

Variables

View Source
var (
	// ErrNotSetUp is returned by an action or a run on a Service built without the runner,
	// or a clone with no go-pre-commit config.
	ErrNotSetUp = errors.New("hooks are not set up")

	// ErrNoTool is returned when no usable copy of go-pre-commit is found, or the user
	// turned it off.
	ErrNoTool = errors.New("go-pre-commit can't be used")

	// ErrNoClone is returned for a folder that isn't a clone in the repository locations.
	ErrNoClone = errors.New("not a clone in the repository locations")

	// ErrInvalidRequest is returned for an action, a scope, a check, or a place to run
	// that isn't one.
	ErrInvalidRequest = errors.New("invalid hooks request")

	// ErrSharedFolder is returned for an action in a clone whose hooks folder other
	// repositories share, unless the request confirms that folder.
	ErrSharedFolder = errors.New("the hooks folder is shared")

	// ErrNoResult is returned by ActionResult and ChecksResult for a run of another kind,
	// one still going, or one that ended without a result.
	ErrNoResult = errors.New("the run has no result to show")
)
View Source
var ErrNoFinder = errors.New("finder can't show a folder here")

ErrNoFinder is returned where Finder can't show a folder, as on Linux.

Functions

This section is empty.

Types

type Action

type Action string

Action is what go-pre-commit is asked to do with a clone's hook.

const (
	// ActionInstall installs the hook where there's none.
	ActionInstall Action = "install"

	// ActionUpdate writes the current hook over an outdated one of go-pre-commit's.
	ActionUpdate Action = "update"

	// ActionReinstall writes go-pre-commit's hook again.
	ActionReinstall Action = "reinstall"

	// ActionReplace moves another tool's hook aside, as pre-commit.backup.<number>, and
	// installs go-pre-commit's.
	ActionReplace Action = "replace"

	// ActionUninstall removes every hook of go-pre-commit's, and puts back the hook it
	// replaced.
	ActionUninstall Action = "uninstall"
)

The actions.

func Actions

func Actions() []Action

Actions returns every action.

func (Action) Valid

func (a Action) Valid() bool

Valid reports whether a is one of Actions.

type ActionIntent

type ActionIntent struct {
	Action  Action `json:"action"`
	Confirm string `json:"confirm"`
}

ActionIntent is what a hooks action sets out to do, written into its run's result as it starts, so Run again does the same.

type ActionOutcome

type ActionOutcome string

ActionOutcome is what a hooks action did, as the hook files say once it ended.

const (
	// OutcomeInstalled is go-pre-commit's hook where there was none.
	OutcomeInstalled ActionOutcome = "installed"

	// OutcomeUpdated is go-pre-commit's hook written over an older one of its own.
	OutcomeUpdated ActionOutcome = "updated"

	// OutcomeCurrent is go-pre-commit's current hook, already there.
	OutcomeCurrent ActionOutcome = "alreadyCurrent"

	// OutcomeReplaced is go-pre-commit's hook in place of another tool's, which it set
	// aside.
	OutcomeReplaced ActionOutcome = "replaced"

	// OutcomeBlocked is nothing installed: another tool's hook is in the way, though
	// go-pre-commit 1.13 exits 0.
	OutcomeBlocked ActionOutcome = "nothingInstalled"

	// OutcomeUninstalled is every hook of go-pre-commit's removed, and the one it
	// replaced put back.
	OutcomeUninstalled ActionOutcome = "uninstalled"

	// OutcomeNoneToRemove is an uninstall that found no hook of go-pre-commit's.
	OutcomeNoneToRemove ActionOutcome = "nothingToUninstall"

	// OutcomeFailed is an action that didn't do what it was asked.
	OutcomeFailed ActionOutcome = "failed"

	// OutcomeUnverified is an action whose result couldn't be read from the hooks.
	OutcomeUnverified ActionOutcome = "unverified"

	// OutcomeSkipped is a clone Install and update all left alone.
	OutcomeSkipped ActionOutcome = "skipped"
)

The outcomes of a hooks action.

type ActionRequest

type ActionRequest struct {
	// Dir is the clone, as the page lists it (Repo.Dir), with ~.
	Dir string `json:"dir"`

	// Confirm is the shared hooks folder the user agreed to change for every repository
	// that uses it, as the page showed it (Repo.HooksDir), or "". An action in a clone
	// whose hooks folder is shared is refused without it.
	Confirm string `json:"confirm"`

	// RunsIn is where it runs, or "" for the setting.
	RunsIn integrationprefs.RunsIn `json:"runsIn"`
}

ActionRequest is a hooks action the window asks for in one clone.

type ActionResult

type ActionResult struct {
	// Action is what was asked, Outcome what the hooks say happened, and Message says so
	// in a sentence.
	Action  Action        `json:"action"`
	Outcome ActionOutcome `json:"outcome"`
	Message string        `json:"message"`

	// Repo is the clone's repository, "owner/name", or ""; Name is what the page calls
	// it; Dir and HooksDir are its folder and its hooks folder, with ~.
	Repo     string `json:"repo"`
	Name     string `json:"name"`
	Dir      string `json:"dir"`
	HooksDir string `json:"hooksDir"`

	// Shared reports a hooks folder other repositories use too, as Repo.Shared does, and
	// SharedWith how many of the clones in the repository locations use it, so the window can ask
	// before an action there, as the row does.
	Shared     bool `json:"shared"`
	SharedWith int  `json:"sharedWith"`

	// OtherTool names the other tool whose hook was in the way, replaced, or put back:
	// husky, pre-commit, lefthook, or "" when it can't be told.
	OtherTool string `json:"otherTool"`

	// Backup is the name go-pre-commit gave the hook it replaced, as in
	// pre-commit.backup.64138, and Restored reports an uninstall that put that hook back.
	Backup   string `json:"backup"`
	Restored bool   `json:"restored"`

	// Removed are the hook types an uninstall removed.
	Removed []string `json:"removed"`

	// NotExecutable reports go-pre-commit's hook left without its executable bit.
	NotExecutable bool `json:"notExecutable"`

	// Error is go-pre-commit's last error line, or why the hooks couldn't be read.
	Error string `json:"error"`
}

ActionResult is a hooks action's result for the window: its run's outcome detail (scriptrun.Result.Outcome), read from the hook files once go-pre-commit ended, never from its exit status alone.

type ChangedFile

type ChangedFile struct {
	// Path is the file, relative to the clone's folder.
	Path string `json:"path"`

	// Staged reports that the run changed what the index holds for it, as whitespace's
	// fixes do, and WasDirty that it had uncommitted changes before the run, which the run
	// may have mixed its own into.
	Staged   bool `json:"staged"`
	WasDirty bool `json:"wasDirty"`

	// By are the checks go-pre-commit said changed it (run --json only), or [].
	By []Check `json:"by"`
}

ChangedFile is a file a checks run changed: rewritten, staged, or both.

type Check

type Check string

Check is one of go-pre-commit's checks.

const (
	CheckEOF        Check = "eof"
	CheckFumpt      Check = "fumpt"
	CheckGitleaks   Check = "gitleaks"
	CheckLint       Check = "lint"
	CheckModTidy    Check = "mod-tidy"
	CheckWhitespace Check = "whitespace"
)

The checks go-pre-commit 1.13 runs, in its own order.

func Checks

func Checks() []Check

Checks returns every check, in go-pre-commit's order.

func (Check) Valid

func (c Check) Valid() bool

Valid reports whether c is one of Checks.

type CheckResult

type CheckResult struct {
	Name  Check      `json:"name"`
	State CheckState `json:"state"`

	// DurationMs is how long it took, as go-pre-commit said.
	DurationMs int64 `json:"durationMs"`

	// Error and Suggestion are what go-pre-commit said went wrong and how to fix it, and
	// Detail the lines it showed from the check's own output, for a check that failed or
	// was skipped.
	Error      string   `json:"error"`
	Suggestion string   `json:"suggestion"`
	Detail     []string `json:"detail"`

	// ChangedFiles are the files go-pre-commit said the check changed (run --json only);
	// [] when it doesn't say.
	ChangedFiles []string `json:"changedFiles"`
}

CheckResult is one check in a checks run's result.

type CheckSetting

type CheckSetting struct {
	Name Check `json:"name"`
	On   bool  `json:"on"`
}

CheckSetting is one check and whether the repository turns it on.

type CheckState

type CheckState string

CheckState is how one check came out of a checks run.

const (
	// CheckPassed and CheckFailed are a check that ran.
	CheckPassed CheckState = "passed"
	CheckFailed CheckState = "failed"

	// CheckSkipped is a check go-pre-commit couldn't run and skipped.
	CheckSkipped CheckState = "skipped"

	// CheckOff is a check the repository turns off.
	CheckOff CheckState = "off"

	// CheckNotRun is a check that is on but this run didn't run: another was asked for,
	// there were no files, or the run stopped first.
	CheckNotRun CheckState = "notRun"
)

The states of a check.

type ChecksIntent

type ChecksIntent struct {
	Scope Scope `json:"scope"`
	Check Check `json:"check"`
}

ChecksIntent is what a checks run sets out to do, written into its run's result as it starts, so Run again does the same.

type ChecksRequest

type ChecksRequest struct {
	// Dir is the clone, as the page lists it (Repo.Dir), with ~.
	Dir string `json:"dir"`

	// Scope is which files: every tracked file, the staged ones, or one check on every
	// tracked file, Check.
	Scope Scope `json:"scope"`
	Check Check `json:"check"`

	// RunsIn is where it runs, or "" for the setting.
	RunsIn integrationprefs.RunsIn `json:"runsIn"`
}

ChecksRequest is a checks run the window asks for in one clone.

type ChecksResult

type ChecksResult struct {
	// Scope and Check are what was asked; Name and Dir are the clone, as in ActionResult.
	Scope Scope  `json:"scope"`
	Check Check  `json:"check"`
	Name  string `json:"name"`
	Dir   string `json:"dir"`

	// Message sums the run up in a sentence.
	Message string `json:"message"`

	// Checks are every check: each that ran, then each the repository turns off, then
	// each that didn't run.
	Checks []CheckResult `json:"checks"`

	// Passed, Failed, and Skipped count the checks that ran, Files the files they
	// checked, and DurationMs how long they took, as go-pre-commit said.
	Passed     int   `json:"passed"`
	Failed     int   `json:"failed"`
	Skipped    int   `json:"skipped"`
	Files      int   `json:"files"`
	DurationMs int64 `json:"durationMs"`

	// NoFiles reports nothing to check, as with nothing staged, and Disabled a config
	// that turns go-pre-commit off.
	NoFiles  bool `json:"noFiles"`
	Disabled bool `json:"disabled"`

	// Changed are the files the run changed or staged, a file already dirty before it
	// included. ChangedKnown reports that git's status was read before and after, so
	// Changed is the whole list; ChangedError says why it wasn't.
	Changed      []ChangedFile `json:"changed"`
	ChangedKnown bool          `json:"changedKnown"`
	ChangedError string        `json:"changedError"`

	// Installs are the tools go-pre-commit installed for the checks, as in
	// "gofumpt@v0.12.0", and Errors its own errors, apart from the failed checks.
	Installs []string `json:"installs"`
	Errors   []string `json:"errors"`
}

ChecksResult is a checks run's result for the window: its run's outcome detail (scriptrun.Result.Outcome), from what go-pre-commit said and what git says of the clone before and after.

type Clone

type Clone struct {
	Name string `json:"name"`
	Dir  string `json:"dir"`
}

Clone is a clone without a go-pre-commit config: its folder's name, and its folder, with ~.

type Clones

type Clones interface {
	Roots(ctx context.Context) (localrepos.Roots, error)
	Dirs(ctx context.Context, roots localrepos.Roots) ([]string, error)
	Origin(ctx context.Context, dir string) (name repo.Name, onGitHub bool, err error)
}

Clones finds the clones in the repository locations: Roots is the clone root and the other locations as set now, Dirs lists the clones in them, reading no git (localrepos.Roots.Clones), and Origin reads which GitHub repository a clone's origin is, if any. Core adapts the settings and localrepos.

type Config

type Config struct {
	Clones  Clones
	Git     Git
	Tools   ToolSource
	Locks   LockHolders
	Runs    Runs
	History RunHistory
	Places  Places
	Memory  Memory

	// Env returns the login shell's environment, and whether it was read
	// (shellenv.Reader.Env): go-pre-commit runs with it, and the PATH warning reads GOPATH
	// from it. It defaults to the app's own, counted as read.
	Env func() ([]string, bool)

	// Ready, when set, returns a channel closed once the login shell's environment has
	// first been read (shellenv.Reader.Ready). A run from before a restart waits for it
	// before it is judged (Verifier), so git and go-pre-commit run with the user's own.
	Ready func() <-chan struct{}

	// Runner returns what runs go-pre-commit's status with env, in the folder dir: a scratch
	// repository of the app's own. It defaults to an execpath.Exec with env and dir.
	Runner func(env []string, dir string) execpath.Runner

	// Scratch is the folder the scratch repositories go-pre-commit's status judges a hook
	// in are made in, and removed from; "" is the system's temporary folder.
	Scratch string

	// Terminal opens the user's terminal in a clone, for a row's Open in terminal, and
	// Reveal shows a clone's config in Finder, for its Open the config. Without them,
	// each says it can't.
	Terminal scriptrun.FolderOpener
	Reveal   Revealer

	Home   string
	Clock  clock.Clock
	Events event.Sink
	Logger *slog.Logger
}

Config holds a Service's dependencies. Clones and Git are required; the actions and the checks also need Runs, and the results History.

type Git

type Git interface {
	HookPaths(ctx context.Context, dir string) (gitread.HookPaths, error)
	Entries(ctx context.Context, dir string) ([]gitread.Entry, error)
}

Git is the read-only git the page reads clones with: *gitread.Git.

type Group

type Group string

Group is where the page lists a clone with a go-pre-commit config.

const (
	// GroupAttention is a clone whose pre-commit hook is missing, outdated, not
	// executable, another tool's, or couldn't be read.
	GroupAttention Group = "attention"

	// GroupReady is a clone with go-pre-commit's current hook, executable.
	GroupReady Group = "ready"

	// GroupOff is a clone whose config turns go-pre-commit off (ENABLE_GO_PRE_COMMIT=false).
	GroupOff Group = "off"
)

The groups.

type InstallAllResult

type InstallAllResult struct {
	Lines   []InstallLine `json:"lines"`
	Message string        `json:"message"`
}

InstallAllResult is Install and update all's result: one line per clone, in the order asked, and a sentence that sums them up.

type InstallLine

type InstallLine struct {
	// Name is what the page calls the clone, and Dir its folder, with ~.
	Name string `json:"name"`
	Dir  string `json:"dir"`

	// Action is what ran, or "" for a clone skipped; RunID is its run, or 0.
	Action Action `json:"action"`
	RunID  int64  `json:"runId"`

	// Outcome is what it did, or OutcomeSkipped, and Message says so, or why it was
	// skipped.
	Outcome ActionOutcome `json:"outcome"`
	Message string        `json:"message"`
}

InstallLine is one clone in Install and update all's result.

type LastRun

type LastRun struct {
	ID         int64            `json:"id"`
	Status     scriptrun.Status `json:"status"`
	Summary    string           `json:"summary"`
	FinishedAt string           `json:"finishedAt"`
}

LastRun is a run as a row mentions it: its ID, zero for none, how it ended, and when, RFC 3339.

type LockHolders

type LockHolders interface {
	Holder(path string) (clonelock.Holder, bool)
}

LockHolders says which job holds a clone, if any: a *clonelock.Set.

type Memory

type Memory interface {
	Get(ctx context.Context, key string) (value string, ok bool, err error)
	Set(ctx context.Context, key, value string) error
}

Memory keeps what the page remembers between runs of the app, the hooks.* preferences, which the hooks package alone writes: a *prefs.Store.

type Page

type Page struct {
	// Tool is go-pre-commit, as the page heads it.
	Tool ToolStatus `json:"tool"`

	// Root is the clone root, with ~.
	Root string `json:"root"`

	// Repos are the clones with a config, by group, then by name.
	Repos []Repo `json:"repos"`

	// NotSetUp are the clones without one, by name.
	NotSetUp []Clone `json:"notSetUp"`

	// PathWarning says the hook can't find go-pre-commit, and ToolNote that the checks
	// install their own tools.
	PathWarning PathWarning `json:"pathWarning"`
	ToolNote    ToolNote    `json:"toolNote"`

	// CheckedAt is when the clones were last scanned, RFC 3339; Error says why the last
	// scan failed while the one before it is shown.
	CheckedAt string `json:"checkedAt"`
	Error     string `json:"error"`
}

Page is the Hooks page: every clone in the repository locations with a go-pre-commit config, grouped, and those without one.

type PathWarning

type PathWarning struct {
	// Show reports the warning, and Dir is the folder of the copy in use, with ~, which
	// the user's shell's startup file should put on the PATH.
	Show bool   `json:"show"`
	Dir  string `json:"dir"`
}

PathWarning is the page's warning that the hook can't find go-pre-commit, so commits fail: the hook looks on the PATH of the shell git runs it from, and in $(go env GOPATH)/bin, never in a folder such as ~/.local/bin that isn't on the PATH.

type Places

type Places interface {
	RunsIn(ctx context.Context) (integrationprefs.RunsIn, error)
}

Places reads where runs go, as the integrations.runsIn setting says. Core adapts the settings.

type Repo

type Repo struct {
	// Repo is its origin's repository, "owner/name", or "" when origin isn't on GitHub;
	// Name is what the row shows, the repository or else the folder's name; and Dir is
	// its folder, with ~, which every request names it by.
	Repo string `json:"repo"`
	Name string `json:"name"`
	Dir  string `json:"dir"`

	// Group is where the page lists it, State what its pre-commit hook is, and Action
	// what its button does, or "" for none.
	Group  Group  `json:"group"`
	State  State  `json:"state"`
	Action Action `json:"action"`

	// OtherTool names another tool's hook: husky, pre-commit, or lefthook; "" for one it
	// can't name, or go-pre-commit's own.
	OtherTool string `json:"otherTool"`

	// HooksDir is the folder git runs its hooks from, with ~. Shared reports one other
	// repositories use too, outside the clone's git folder and work tree, and SharedWith
	// how many of the clones in the repository locations use it, this one included; an action
	// there needs the user to confirm the folder.
	HooksDir   string `json:"hooksDir"`
	Shared     bool   `json:"shared"`
	SharedWith int    `json:"sharedWith"`

	// AlsoInstalled are the other hook types that carry go-pre-commit's hook, which
	// Uninstall removes too, and Backups the hooks go-pre-commit set aside when it
	// replaced another tool's, the last of which Uninstall puts back.
	AlsoInstalled []string `json:"alsoInstalled"`
	Backups       []string `json:"backups"`

	// CIVersion is the go-pre-commit the repository's CI pins (GO_PRE_COMMIT_VERSION),
	// without a leading v, or "".
	CIVersion string `json:"ciVersion"`

	// Checks are go-pre-commit's checks, each on or off in the repository.
	Checks []CheckSetting `json:"checks"`

	// Busy says what holds the clone now, as a sentence, or "".
	Busy string `json:"busy"`

	// LastChecks is the newest checks run in the clone, zero when there is none.
	LastChecks LastRun `json:"lastChecks"`

	// Error says why the clone's hooks couldn't be read, or "".
	Error string `json:"error"`
}

Repo is one clone with a go-pre-commit config, as the page lists it.

type Rerunner

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

Rerunner works Run again out for hooks actions and checks runs (scriptrun.Rerunner): the same action or checks, from its recorded intent, in the same clone, checked afresh as a click is. Core registers it with the runner for scriptrun.KindHooks and scriptrun.KindChecks. It is its own type, not a method of the Service, which the window binds.

func NewRerunner

func NewRerunner(s *Service) Rerunner

NewRerunner returns the Rerunner of s's runs.

func (Rerunner) Rerun

func (r Rerunner) Rerun(ctx context.Context, run scriptrun.Record) (scriptrun.Spec, error)

Rerun returns the spec of run again: a hooks action or a checks run, where it ran.

type Revealer

type Revealer interface {
	Reveal(ctx context.Context, path string) error
}

Revealer shows a file or a folder in Finder. Core adapts open -R, on macOS only.

type RunHistory

type RunHistory interface {
	Run(ctx context.Context, id int64) (scriptrun.Run, error)
	Runs(ctx context.Context, filter scriptrun.Filter) ([]scriptrun.Run, error)
}

RunHistory reads runs back from the runner's history: the scriptrun Service.

type Runs

type Runs interface {
	Start(ctx context.Context, spec scriptrun.Spec) (int64, error)
	Kept(id int64, into any) (bool, error)
}

Runs starts a run, and reads what a run from before a restart kept beside its record (scriptrun.Spec.Keep) for the Verifier: the scriptrun engine.

type Scans

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

Scans is the desktop worker that holds the Hooks page's calls to the app's lifetime: each Repos call, which reads the database, and the scan it shares, which runs apart from the window's call that started it, within ScanTimeout, so a window that asks again doesn't throw it away. The app's quit ends them all, and Run returns only once every one under way has, so the desktop shell, which waits for its workers before it closes the database, never leaves one reading behind it. It is not bound.

func NewScans

func NewScans(s *Service) Scans

NewScans returns the worker that holds s's calls and scans to the app's lifetime.

func (Scans) Run

func (w Scans) Run(ctx context.Context)

Run waits for ctx to end, then ends every call and scan under way, refuses any later one, and returns once those under way have.

type Scope

type Scope string

Scope is which files a checks run checks.

const (
	// ScopeAll checks every tracked file.
	ScopeAll Scope = "all"

	// ScopeStaged checks the staged files, as the hook does.
	ScopeStaged Scope = "staged"

	// ScopeOne runs one check on every tracked file.
	ScopeOne Scope = "one"
)

The scopes.

func Scopes

func Scopes() []Scope

Scopes returns every scope.

func (Scope) Valid

func (s Scope) Valid() bool

Valid reports whether s is one of Scopes.

type Service

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

Service lists the clones and their hooks, runs go-pre-commit's actions and checks in them, and reads their results back. The window binds it.

func NewService

func NewService(cfg Config) *Service

NewService returns a Service over cfg.

func (*Service) ActionResult

func (s *Service) ActionResult(ctx context.Context, runID int64) (ActionResult, error)

ActionResult returns a hooks action's result, as its run recorded it once the hooks were read: the run's Result.Outcome, typed, since the runner keeps it as plain JSON, which the window can't name. It fails for a run the history no longer holds (scriptrun.ErrNotFound), a run that isn't a hooks action, one still going, and one that ended without a result, as one that couldn't start (ErrNoResult).

func (*Service) ChecksResult

func (s *Service) ChecksResult(ctx context.Context, runID int64) (ChecksResult, error)

ChecksResult returns a checks run's result, as its run recorded it, typed, as ActionResult does a hooks action's.

func (*Service) Install

func (s *Service) Install(ctx context.Context, req ActionRequest) (int64, error)

Install installs go-pre-commit's pre-commit hook in the clone, and returns the run's ID.

func (*Service) InstallAll

func (s *Service) InstallAll(ctx context.Context, dirs []string) (InstallAllResult, error)

InstallAll installs or updates go-pre-commit's hook in each clone of dirs (folders as the page lists them, with ~), one at a time, each as its own run in the app, and returns a line per clone once all have ended. It never replaces another tool's hook, never touches a shared hooks folder, does a folder that two clones resolve to once, and skips a clone that is busy, turned off, current already, or without a config.

func (*Service) OpenTerminal

func (s *Service) OpenTerminal(ctx context.Context, dir string) error

OpenTerminal opens the terminal chosen for launches in the clone the page lists at dir (with ~), for a row's Open in terminal: the user looks at the clone or fixes it there. The app runs nothing in it (scriptrun.OpenFolder). Only a clone the repository locations hold is opened.

func (*Service) Reinstall

func (s *Service) Reinstall(ctx context.Context, req ActionRequest) (int64, error)

Reinstall writes go-pre-commit's hook again.

func (*Service) Replace

func (s *Service) Replace(ctx context.Context, req ActionRequest) (int64, error)

Replace has go-pre-commit set another tool's hook aside, as pre-commit.backup.<number>, and install its own.

func (*Service) Repos

func (s *Service) Repos(ctx context.Context, refresh bool) (Page, error)

Repos returns the Hooks page. It serves the last scan while it is under FreshFor old, was read from the repository locations as set now, and no copy of go-pre-commit took the place of the one it judged with, scanning again first only the clones an action or a check ran in; refresh, or anything else, scans every clone again and emits event.HooksUpdated. A scan that fails keeps the last page, with its error, until one succeeds. A scan runs apart from the caller that started it, within ScanTimeout: a caller whose context ends stops waiting, and the scan goes on for the next. What holds each clone, and its newest checks run, are read for every call. The whole call, its scan included, runs within the app's lifetime (Scans): the app's quit ends it, and refuses one after it.

func (*Service) RunChecks

func (s *Service) RunChecks(ctx context.Context, req ChecksRequest) (int64, error)

RunChecks runs go-pre-commit's checks in the clone req names, and returns the run's ID. The run's Before takes git's status of the clone under its lock, and its Finish again once the checks end, so the result names the files they changed.

func (*Service) ShowConfig

func (s *Service) ShowConfig(ctx context.Context, dir string) error

ShowConfig shows the go-pre-commit config of the clone the page lists at dir (with ~) in Finder, for a row's Open the config: its .github/env folder, or the legacy .github/.env.base. Only a clone the repository locations hold, with a config, is shown.

func (*Service) Uninstall

func (s *Service) Uninstall(ctx context.Context, req ActionRequest) (int64, error)

Uninstall has go-pre-commit remove every hook of its own, listing each hook type that carries its marker, and put back the hook it replaced.

func (*Service) Update

func (s *Service) Update(ctx context.Context, req ActionRequest) (int64, error)

Update writes go-pre-commit's current hook over an outdated one.

type State

type State string

State is what a clone's pre-commit hook is.

const (
	// StateMissing is no pre-commit hook.
	StateMissing State = "missing"

	// StateReady is go-pre-commit's hook, current and executable.
	StateReady State = "ready"

	// StateOutdated is go-pre-commit's hook from another release.
	StateOutdated State = "outdated"

	// StateNotExecutable is go-pre-commit's hook without its executable bit, which git
	// skips.
	StateNotExecutable State = "notExecutable"

	// StateOther is another tool's hook.
	StateOther State = "other"

	// StateUnknown is go-pre-commit's hook when no usable copy of go-pre-commit can say
	// whether it is current.
	StateUnknown State = "unknown"

	// StateUnreadable is a clone whose hooks folder or hook couldn't be read.
	StateUnreadable State = "unreadable"
)

The states.

type ToolFacts

type ToolFacts struct {
	integrations.CopyFacts

	// Copies are every copy found, the one in use first, and OnPath reports that the
	// user's shell finds one of them on its PATH.
	Copies []string
	OnPath bool

	// ShellRead reports that the user's login shell's environment was read, so OnPath
	// says what their shell finds.
	ShellRead bool
}

ToolFacts is what Hooks knows of go-pre-commit: the copy in use, what it can do (integrations.CopyFacts), and where the user's shell finds copies of it.

func ToolFactsOf

func ToolFactsOf(def integrations.Definition, tool integrations.Tool, shellRead bool) ToolFacts

ToolFactsOf reads go-pre-commit's facts from the integrations' view of it: def is its definition, tool what the settings show of it, and shellRead whether the user's shell's environment was read.

type ToolNote

type ToolNote struct {
	// Show reports the note, and Open that it shows unfolded, until a checks run has
	// ended in the app.
	Show bool `json:"show"`
	Open bool `json:"open"`
}

ToolNote is the page's note that the checks install their own tools: gofumpt, golangci-lint, and gitleaks, without checking them, until go-pre-commit has FeatureVerifiedTools.

type ToolSource

type ToolSource interface {
	HooksTool(ctx context.Context) ToolFacts
}

ToolSource reads what the app knows of go-pre-commit. Core adapts the integrations service, with ToolFactsOf. It never fails: a copy it can't read is missing.

type ToolStatus

type ToolStatus struct {
	// Version is the copy in use's version, and Path where it is, with ~; both are ""
	// without one.
	Version string `json:"version"`
	Path    string `json:"path"`

	// State is what the settings say of it, Off that the user turned it off, and Usable
	// that the page can run it.
	State  integrations.State `json:"state"`
	Off    bool               `json:"off"`
	Usable bool               `json:"usable"`
}

ToolStatus is go-pre-commit as the page heads it.

type Verifier

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

Verifier settles the hooks actions and the checks runs from before the app restarted (scriptrun.Verifier): one orphaned, still running, or interrupted gets an output reader, a Finish, a Recorded, and a Released again, built from its record and from what its Before kept beside it (scriptrun.Spec.Keep, which the runner removes once the run's end is recorded), so it is read and judged as one the app started is. An action's Finish reads the hook files against the hooks its Before read, judged with the copy of go-pre-commit that ran; a checks run's reads git's status of the clone against the snapshot its Before took, with the config it ran with. Core registers it with the runner for scriptrun.KindHooks and scriptrun.KindChecks. It is its own type, not a method of the Service, which the window binds.

func NewVerifier

func NewVerifier(s *Service) Verifier

NewVerifier returns the Verifier of s's runs.

func (Verifier) Verify

Verify gives a hooks action or a checks run from before the app restarted what its Spec gave it; its Finish first waits for the login shell's environment (Config.Ready). A record whose intent can't be read gets none: the runner's own outcome stands.

Jump to

Keyboard shortcuts

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