forge

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package forge applies what reaches a forge — comments, labels, issues, merge requests — on GitHub, GitLab, or a simulated forge for the tests. Every write is idempotent, so a run interrupted half-way can be resumed.

Index

Constants

View Source
const Missing = "" /* 128-byte string literal not displayed */

Missing says what to do when a write needs a forge and the project has none.

Variables

View Source
var ErrUnreachable = errors.New("forge unreachable")

ErrUnreachable marks a forge that did not answer: the run is blocked by something outside the role.

Functions

func InCI added in v0.2.2

func InCI() string

InCI names the variable that says the run is in CI, or "" outside it.

func KeepsBranches added in v0.2.2

func KeepsBranches(f Forge) bool

KeepsBranches says whether f's merge requests come from local branches: nothing is pushed to a remote, nor fetched from one.

func Marker

func Marker(key string) string

Marker is the hidden text that makes a comment findable again.

Types

type Backlog added in v0.5.0

type Backlog interface {
	// Issues lists the open issues, merge requests left out, by number.
	Issues() ([]Issue, error)
	// Comments lists the comments on t, oldest first.
	Comments(t Target) ([]string, error)
	// Close closes an issue: as a duplicate of dup when dup > 0, else as
	// completed. Closing one already closed changes nothing.
	Close(id, dup int) error
	// Milestones lists the titles of the open milestones.
	Milestones() ([]string, error)
	// SetMilestone puts an issue in the open milestone with this title,
	// creating it when there is none.
	SetMilestone(id int, title string) error
	// SetBody rewrites an issue's body.
	SetBody(id int, body string) error
	// EnsureLabel creates a label when the project has none of that name,
	// so a person finds it in the forge's list to set.
	EnsureLabel(name, color, description string) error
}

Backlog is what a role acting on a project's issues needs from its forge (docs/spec/backlog-acts.md). Every forge workline speaks has it.

type Fake

type Fake struct{ Path string }

Fake is a forge kept in a JSON file, shared between processes, for the conformance tests. It can be told to fail its N-th write, once.

func (*Fake) Close added in v0.5.0

func (f *Fake) Close(id, dup int) error

func (*Fake) Comment

func (f *Fake) Comment(t Target, body, marker string) error

func (*Fake) Comments added in v0.5.0

func (f *Fake) Comments(t Target) ([]string, error)

func (*Fake) EnsureLabel added in v0.7.0

func (f *Fake) EnsureLabel(name, color, description string) error

func (*Fake) Issue

func (f *Fake) Issue(id int) (*Issue, error)

func (*Fake) Issues added in v0.5.0

func (f *Fake) Issues() ([]Issue, error)

func (*Fake) KeepIssue

func (f *Fake) KeepIssue(title, body string, create bool) (int, error)

func (*Fake) Label

func (f *Fake) Label(t Target, add, remove []string) error

func (*Fake) MergeRequest added in v0.4.0

func (f *Fake) MergeRequest(id int) (MergeRequest, error)

func (*Fake) Milestones added in v0.5.0

func (f *Fake) Milestones() ([]string, error)

func (*Fake) OpenIssue

func (f *Fake) OpenIssue(title, body, marker string) (int, error)

func (*Fake) OpenMergeRequest

func (f *Fake) OpenMergeRequest(branch, base, title, body string) (int, error)

func (*Fake) OpenMergeRequests

func (f *Fake) OpenMergeRequests(prefix string) ([]string, error)

func (*Fake) SetBody added in v0.6.0

func (f *Fake) SetBody(id int, body string) error

func (*Fake) SetMilestone added in v0.5.0

func (f *Fake) SetMilestone(id int, title string) error

func (*Fake) Sticky

func (f *Fake) Sticky(t Target, body, marker string, create bool) error

type FakeItem

type FakeItem struct {
	ID        int      `json:"id"`
	Branch    string   `json:"branch,omitempty"` // a merge request's source branch
	Base      string   `json:"base,omitempty"`
	Closed    bool     `json:"closed,omitempty"`
	Reason    string   `json:"reason,omitempty"` // why it was closed: completed or duplicate
	Milestone string   `json:"milestone,omitempty"`
	Fork      bool     `json:"fork,omitempty"` // a merge request from a fork
	Title     string   `json:"title,omitempty"`
	Body      string   `json:"body,omitempty"`
	Labels    []string `json:"labels"`
	Comments  []string `json:"comments"`
	Author    string   `json:"author,omitempty"`
	Insider   bool     `json:"insider,omitempty"`
}

FakeItem is an issue or a merge request.

type FakeState

type FakeState struct {
	Issues        []FakeItem `json:"issues"`
	MergeRequests []FakeItem `json:"merge-requests"`
	Milestones    []string   `json:"milestones,omitempty"`    // open milestones, by title
	Labels        []FakeItem `json:"labels,omitempty"`        // labels defined, their name as id
	FailOnWrite   int        `json:"fail-on-write,omitempty"` // the write that fails, counting from 1
	Writes        int        `json:"writes"`
}

FakeState is the file's content.

type Forge

type Forge interface {
	Issue(id int) (*Issue, error)
	// Comment posts body on t unless a comment carrying marker is already there.
	Comment(t Target, body, marker string) error
	// Sticky keeps one comment carrying marker on t, edited to body on each
	// run instead of a new one each time; with create false, it only edits
	// one already there.
	Sticky(t Target, body, marker string, create bool) error
	// Label adds and removes labels; adding one already there changes nothing.
	Label(t Target, add, remove []string) error
	// OpenIssue creates an issue, or comments on an open one with the same title.
	OpenIssue(title, body, marker string) (int, error)
	// KeepIssue rewrites the body of the open issue with this title, or opens
	// it when there is none and create is true: one issue, kept in place.
	KeepIssue(title, body string, create bool) (int, error)
	// OpenMergeRequest opens a merge request from branch into base, or
	// updates the title and body of the one already open from branch.
	OpenMergeRequest(branch, base, title, body string) (int, error)
	// OpenMergeRequests lists the branches of the open merge requests whose
	// branch starts with prefix, sorted.
	OpenMergeRequests(prefix string) ([]string, error)
	// MergeRequest says where a merge request comes from and goes.
	MergeRequest(id int) (MergeRequest, error)
}

Forge is what the engine needs from one.

func Open

func Open(spec, repo string) (Forge, error)

Open returns the forge named by spec: "github", "gitlab", "local" (kept in the clone), "cmd:<command>" (another forge, plugged by a command), "fake:<file>", or "" / "none" for no forge: what needs one is refused, and says so.

type Issue

type Issue struct {
	ID        int      `json:"id"`
	Title     string   `json:"title"`
	Body      string   `json:"body"`
	Labels    []string `json:"labels"`
	Closed    bool     `json:"closed,omitempty"`
	Milestone string   `json:"milestone,omitempty"` // the title of the milestone it is in, if any
	Author    string   `json:"author,omitempty"`    // who opened it
	Insider   bool     `json:"insider,omitempty"`   // its author has write access to the project; false when the forge does not say
}

Issue is what the line reads from a work item.

type Local added in v0.2.2

type Local struct{ Repo string }

Local is a forge kept in the clone, never committed: for a project with no forge, or one whose person works alone. Each issue is a Markdown file, .git/workline/issues/<n>.md; each merge request is a local branch, recorded the same way in .git/workline/merge-requests/<n>.md. Nothing is pushed: `workline issues` reads them. Writes are idempotent, as on any forge.

func (*Local) Close added in v0.5.0

func (l *Local) Close(id, dup int) error

Close closes an issue; the local forge keeps no reason, the engine's comment says it.

func (*Local) Comment added in v0.2.2

func (l *Local) Comment(t Target, body, marker string) error

func (*Local) Comments added in v0.5.0

func (l *Local) Comments(t Target) ([]string, error)

func (*Local) EnsureLabel added in v0.7.0

func (l *Local) EnsureLabel(name, color, description string) error

EnsureLabel: the local forge keeps no list of labels apart from its items.

func (*Local) Issue added in v0.2.2

func (l *Local) Issue(id int) (*Issue, error)

func (*Local) Issues added in v0.5.0

func (l *Local) Issues() ([]Issue, error)

func (*Local) Item added in v0.2.2

func (l *Local) Item(kind string, id int) (*LocalItem, error)

Item reads one issue or merge request.

func (*Local) Items added in v0.2.2

func (l *Local) Items(kind string) ([]*LocalItem, error)

Items lists the issues, or the merge requests, by number.

func (*Local) KeepIssue added in v0.2.2

func (l *Local) KeepIssue(title, body string, create bool) (int, error)

func (*Local) Label added in v0.2.2

func (l *Local) Label(t Target, add, remove []string) error

func (*Local) MergeRequest added in v0.4.0

func (l *Local) MergeRequest(id int) (MergeRequest, error)

func (*Local) Milestones added in v0.5.0

func (l *Local) Milestones() ([]string, error)

Milestones are the ones its open issues are in: the local forge keeps no milestone apart from them.

func (*Local) OpenIssue added in v0.2.2

func (l *Local) OpenIssue(title, body, marker string) (int, error)

func (*Local) OpenMergeRequest added in v0.2.2

func (l *Local) OpenMergeRequest(branch, base, title, body string) (int, error)

func (*Local) OpenMergeRequests added in v0.2.2

func (l *Local) OpenMergeRequests(prefix string) ([]string, error)

func (*Local) SetBody added in v0.6.0

func (l *Local) SetBody(id int, body string) error

func (*Local) SetMilestone added in v0.5.0

func (l *Local) SetMilestone(id int, title string) error

func (*Local) StateOf added in v0.2.2

func (l *Local) StateOf(it *LocalItem) string

StateOf is an item's state as it stands: a merge request whose branch is gone is closed, one whose branch its base holds is merged — the person merges it with git.

func (*Local) Sticky added in v0.2.2

func (l *Local) Sticky(t Target, body, marker string, create bool) error

type LocalItem added in v0.2.2

type LocalItem struct {
	ID        int      `yaml:"-"`
	Title     string   `yaml:"title"`
	State     string   `yaml:"state"` // open or closed, as written; see Local.StateOf
	Labels    []string `yaml:"labels,flow"`
	Milestone string   `yaml:"milestone,omitempty"`
	Branch    string   `yaml:"branch,omitempty"` // a merge request's local branch
	Base      string   `yaml:"base,omitempty"`
	Body      string   `yaml:"-"`
	Comments  []string `yaml:"-"`
}

LocalItem is an issue or a merge request of the local forge.

type MergeRequest added in v0.4.0

type MergeRequest struct {
	Branch string // the branch it comes from
	Base   string // the branch it goes into; "" when the forge does not say
	Here   bool   // the branch lives in this repository, not in a fork
}

MergeRequest is where a merge request comes from and where it goes.

type Target

type Target struct {
	Kind string `json:"kind" yaml:"kind"` // "issue" or "merge-request"
	ID   int    `json:"id" yaml:"id"`
}

Target is what a comment or a label goes on.

func (Target) String

func (t Target) String() string

Jump to

Keyboard shortcuts

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