Help us shape the future of Go! Take the 2026 Go Developer Survey

mergejob

package
v8.153.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mergejob keeps the detached merges of devctl pr merge --detach: one directory per merge under the user's state directory, named by the merge's handle, holding the job, the merge's log and, once it ended, its document.

Index

Constants

View Source
const (
	// StateRunning: the merge's process runs and has not written its
	// document.
	StateRunning = "running"
	// StateFinished: the merge wrote its document.
	StateFinished = "finished"
	// StateLost: the merge's process is gone without a document (killed,
	// the machine restarted); whether it merged is GitHub's to say.
	StateLost = "lost"
)

The states of a job.

View Source
const (

	// LogFile is the merge's stdout and stderr: its --progress lines and
	// the document.
	LogFile = "output.log"
)

The files of a job's directory.

View Source
const Retention = 30 * 24 * time.Hour

Retention is how long a finished or lost job is kept; Start removes older ones.

View Source
const StatusCommand = "pr merge status"

StatusCommand is the command of a status document.

Variables

This section is empty.

Functions

func Alive

func Alive(pid int) bool

Alive reports whether a process with pid runs.

func Detach

func Detach(cmd *exec.Cmd)

Detach makes cmd start in a session of its own, so it outlives its caller's terminal, process group and signals.

func Prune

func Prune(root string, now time.Time) error

Prune removes the jobs that ended before now minus Retention.

func ReadStatus added in v8.151.0

func ReadStatus(jobs Jobs, handle string, doc *StatusDocument) (agentcli.Verdict, error)

ReadStatus fills doc with the merge of handle, or the list of every merge without one, and returns the verdict of an exit 0, or the outcome: the merge's own once it ended, running while it runs, usage for a lost merge or an unknown handle.

func Root

func Root() (string, error)

Root is the directory the jobs live in: $XDG_STATE_HOME/devctl/merges, or ~/.local/state/devctl/merges without it.

func Shell

func Shell(script string) []string

Shell is the command line that runs script.

func ValidHandle

func ValidHandle(handle string) bool

ValidHandle reports whether handle can name a job: no path separator, no leading dot.

func WriteDocument

func WriteDocument(root, handle string, document []byte) error

WriteDocument stores the merge's document, atomically: a reader sees it whole or not at all.

func WriteOnDone

func WriteOnDone(root, handle string, o OnDone) error

WriteOnDone stores the --on-done command's outcome.

Types

type Dir added in v8.151.0

type Dir string

Dir is the job directories under a root: the detached merges of a laptop.

func (Dir) List added in v8.151.0

func (d Dir) List() ([]Status, error)

func (Dir) Load added in v8.151.0

func (d Dir) Load(handle string) (Status, error)

type Job

type Job struct {
	Handle     string    `json:"handle"`
	Repository string    `json:"repository"`
	Number     int       `json:"number"`
	PID        int       `json:"pid"`
	StartedAt  time.Time `json:"startedAt"`
	// Dir is the job's directory; not stored.
	Dir string `json:"-"`
}

Job is one detached merge.

func Create

func Create(root, owner, repo string, number int, now time.Time) (Job, error)

Create makes the directory of a new job for owner/repo#number started at now and returns the job; its handle is <owner>-<repo>-<number>-<UTC time>, with a suffix when a job of the same second exists.

func (Job) DocumentPath

func (j Job) DocumentPath() string

DocumentPath is the path the merge's document is written to.

func (Job) Log

func (j Job) Log() string

Log is the path of the job's log, empty for a job without a directory.

func (Job) Save

func (j Job) Save() error

Save writes the job's record.

type JobSummary added in v8.151.0

type JobSummary struct {
	Handle     string    `json:"handle"`
	Repository string    `json:"repository"`
	Number     int       `json:"number"`
	State      string    `json:"state"`
	StartedAt  time.Time `json:"startedAt"`
	ExitCode   *int      `json:"exitCode"`
}

JobSummary is one merge in the list.

type Jobs added in v8.151.0

type Jobs interface {
	// List returns every merge, the newest first.
	List() ([]Status, error)
	// Load returns the merge of handle, an error for an unknown one.
	Load(handle string) (Status, error)
}

Jobs is where the merges a status reads are kept.

type Memory added in v8.151.0

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

Memory is the merges a long-running process keeps for as long as it runs: the server's, which writes nothing to disk.

func (*Memory) List added in v8.151.0

func (m *Memory) List() ([]Status, error)

func (*Memory) Load added in v8.151.0

func (m *Memory) Load(handle string) (Status, error)

func (*Memory) Put added in v8.151.0

func (m *Memory) Put(s Status)

Put records s under its handle, replacing an earlier state.

type OnDone

type OnDone struct {
	Command  string `json:"command"`
	ExitCode int    `json:"exitCode"`
	Error    string `json:"error,omitempty"`
}

OnDone is how the --on-done command of a job ended.

type Status

type Status struct {
	Job
	State string
	// Document is the merge's JSON document, set when finished.
	Document json.RawMessage
	// OnDone is the --on-done command's outcome, nil when none ran (yet).
	OnDone *OnDone
}

Status is what a job's directory says about it.

func List

func List(root string) ([]Status, error)

List reads every job under root, the newest first.

func Load

func Load(root, handle string) (Status, error)

Load reads the job named handle and judges its state.

func Running

func Running(root, repository string, number int) (Status, bool, error)

Running returns the running job of repository#number, if there is one.

type StatusDocument added in v8.151.0

type StatusDocument struct {
	agentcli.Envelope
	Handle     string          `json:"handle,omitempty"`
	State      string          `json:"state,omitempty"`
	Repository string          `json:"repository,omitempty"`
	Number     int             `json:"number,omitempty"`
	PID        int             `json:"pid,omitempty"`
	Log        string          `json:"log,omitempty"`
	Merge      json.RawMessage `json:"merge"`
	OnDone     *OnDone         `json:"onDone"`
	Jobs       []JobSummary    `json:"jobs,omitempty"`
}

StatusDocument is the document of devctl pr merge status.

func NewStatusDocument added in v8.151.0

func NewStatusDocument(now time.Time) StatusDocument

NewStatusDocument is the document of a status read started at now.

Jump to

Keyboard shortcuts

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