linear

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 16 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 linear is the two-way Linear integration: outbound, an approved execution plan becomes one Linear issue per task under a parent issue per initiative, kept in sync as tasks and change sets move; inbound, a poll for issues carrying a label turns each into an initiative.

Polling rather than webhooks for the same reason Slack uses Socket Mode: the daemon is loopback-only and a webhook needs a public URL.

Index

Constants

View Source
const (
	// LinkInitiative: local = initiative id, remote = its parent issue (an
	// issue we created, or the labeled issue the initiative came FROM).
	LinkInitiative = "initiative"
	// LinkTask: local = task id, remote = the task's issue.
	LinkTask = "task"
	// LinkInboundRejected: local = remote = a labeled issue the daemon
	// refused to import (e.g. it contained a credential), so it is not
	// retried -- and not commented on -- every poll.
	LinkInboundRejected = "inbound_rejected"
)

Link kinds in integration_links.

View Source
const DefaultEndpoint = "https://api.linear.app/graphql"

DefaultEndpoint is Linear's GraphQL API.

View Source
const SubscriberName = "linear"

SubscriberName keys Linear's outbox rows, cursor and links.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	User        string `json:"user"`
	Team        string `json:"team"`
	Project     string `json:"project,omitempty"`
	LabelExists bool   `json:"label_exists"`
	Label       string `json:"label"`
}

CheckResult is what `idea integrations test linear` reports.

type Client

type Client struct {
	Endpoint string
	APIKey   string
	HTTP     *http.Client
}

Client is a minimal Linear GraphQL client over net/http: a handful of typed queries, no generated SDK.

func (*Client) Comment

func (c *Client) Comment(ctx context.Context, issueID, body string) error

Comment adds a comment to an issue.

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, in IssueInput) (*Issue, error)

CreateIssue creates an issue.

func (*Client) IssuesByID

func (c *Client) IssuesByID(ctx context.Context, ids []string) ([]Issue, error)

IssuesByID fetches the current state of up to 50 issues.

func (*Client) LabelExists

func (c *Client) LabelExists(ctx context.Context, name string) (bool, error)

LabelExists reports whether an issue label with this name exists.

func (*Client) LabeledIssues

func (c *Client) LabeledIssues(ctx context.Context, teamKey, label string) ([]Issue, error)

LabeledIssues lists a team's issues carrying label (case-insensitive), oldest first, at most 50 per poll -- a backlog drains over a few polls instead of one expensive query.

func (*Client) ProjectByName

func (c *Client) ProjectByName(ctx context.Context, name string) (string, error)

ProjectByName resolves a project name to its id.

func (*Client) SetIssueState

func (c *Client) SetIssueState(ctx context.Context, issueID, stateID string) error

SetIssueState moves an issue to a workflow state.

func (*Client) TeamByKey

func (c *Client) TeamByKey(ctx context.Context, key string) (*Team, error)

TeamByKey resolves a team key (ENG) to the team and its states.

func (*Client) Viewer

func (c *Client) Viewer(ctx context.Context) (string, error)

Viewer returns the API key's user, which validates the key.

type Issue

type Issue struct {
	ID          string `json:"id"`
	Identifier  string `json:"identifier"`
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
	State       State  `json:"state"`
}

Issue is the slice of a Linear issue this integration reads.

type IssueInput

type IssueInput struct {
	TeamID      string `json:"teamId"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	ParentID    string `json:"parentId,omitempty"`
	ProjectID   string `json:"projectId,omitempty"`
	StateID     string `json:"stateId,omitempty"`
}

IssueInput is issueCreate's input, trimmed to what is used.

type PollRecord

type PollRecord struct {
	Started, Finished time.Time
	Imported          int
	Manual            bool
	Err               error
}

PollRecord is one poll, as OnPoll reports it.

type PollState

type PollState struct {
	LastPollAt *time.Time `json:"last_poll_at,omitempty"`
	LastError  string     `json:"last_error,omitempty"`
}

PollState is the poller's health, for `idea integrations status`.

type State

type State struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Type is Linear's category: triage, backlog, unstarted, started,
	// completed, canceled.
	Type string `json:"type"`
}

State is a team workflow state.

type Syncer

type Syncer struct {
	ProjectID string
	Cfg       config.LinearConfig
	Client    *Client
	DB        *store.DB
	Actions   integrations.Actions
	// Why returns a task's provenance chain. Optional.
	Why func(ctx context.Context, initiativeID, taskID string) ([]WhyStep, error)
	// Redact scrubs known secrets from outbound text (issue bodies, comments).
	Redact func(string) string
	Log    *slog.Logger
	// OnPoll, when set, is told about every poll the poller runs: when it
	// started and finished, how many issues it imported, whether a person
	// asked for it (PollNow), and its error. The daemon keeps the ones worth
	// keeping as Automations history.
	OnPoll func(PollRecord)
	// contains filtered or unexported fields
}

Syncer is the Linear integration for one project: a bus Subscriber (outbound) and a poller (inbound).

func (*Syncer) Check

func (s *Syncer) Check(ctx context.Context) (CheckResult, error)

Check validates the key, the team, the project, the state mapping and the inbound label, writing nothing.

func (*Syncer) Deliver

func (s *Syncer) Deliver(ctx context.Context, ev integrations.Event) error

Deliver implements integrations.Subscriber.

func (*Syncer) Name

func (s *Syncer) Name() string

Name implements integrations.Subscriber.

func (*Syncer) Poll

func (s *Syncer) Poll(ctx context.Context) error

Poll runs one inbound pass: import newly labeled issues, then reflect Linear-side cancellations of linked issues as notes.

func (*Syncer) PollNow

func (s *Syncer) PollNow()

PollNow asks a running poller to poll at once instead of waiting out its interval ("Run now" in the Automations view). A no-op when one is already pending.

func (*Syncer) PollState

func (s *Syncer) PollState() PollState

PollState returns the poller's health.

func (*Syncer) RunPoller

func (s *Syncer) RunPoller(ctx context.Context)

RunPoller polls every poll_interval_seconds until ctx is cancelled, waiting out a rate limit's reset when Linear reports one.

func (*Syncer) SyncPlan

func (s *Syncer) SyncPlan(ctx context.Context, initiativeID string) error

SyncPlan creates the initiative's parent issue (unless it has one) and one issue per task that has none. Idempotent: every issue is linked the moment it exists, so a retry after a partial failure creates only what is still missing, and a re-approved plan picks up tasks a revision added.

func (*Syncer) Wants

func (s *Syncer) Wants(ev integrations.Event) bool

Wants implements integrations.Subscriber.

type Team

type Team struct {
	ID     string  `json:"id"`
	Key    string  `json:"key"`
	Name   string  `json:"name"`
	States []State `json:"-"`
}

Team is a team and its workflow states.

type WhyStep

type WhyStep struct {
	Edge, From, To string
}

WhyStep is one edge of a task's provenance chain (workflow.Engine.Why), adapted by the daemon so this package does not import the engine.

Jump to

Keyboard shortcuts

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