tracker

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectCandidateKinds

func DetectCandidateKinds(key string) []string

DetectCandidateKinds returns all tracker kinds whose key format matches the given key. The order is deterministic: azuredevops is checked before github/gitlab repo format since "Word/N" is a subset of "owner/repo".

func DetectKind

func DetectKind(key string) string

DetectKind returns the tracker kind that can be unambiguously inferred from the key format. Currently only "github" is detectable (owner/repo#N or owner/repo). Returns "" when the kind cannot be determined.

func ExtractProject

func ExtractProject(key string) string

ExtractProject extracts the project identifier from a key.

"KAN-42"              → "KAN"
"octocat/repo#42"     → "octocat/repo"
"octocat/repo"        → "octocat/repo"
"Project/42"          → "Project"
"123"                 → ""

func FormatMissingCreds added in v0.13.0

func FormatMissingCreds(result CredResult, parsed *ParsedURL) string

FormatMissingCreds returns a user-friendly message about which env vars to set.

func IsURL added in v0.13.0

func IsURL(input string) bool

IsURL returns true if the input looks like a URL rather than an issue key.

Types

type Assigner

type Assigner interface {
	AssignIssue(ctx context.Context, key string, userID string) error
}

Assigner assigns an issue to a user.

type AuditEntry

type AuditEntry struct {
	Timestamp  string `json:"timestamp"`
	Operation  string `json:"operation"`
	Tracker    string `json:"tracker"`
	Kind       string `json:"kind"`
	Key        string `json:"key"`
	DurationMs int64  `json:"duration_ms"`
	Error      string `json:"error,omitempty"`
}

AuditEntry represents a single audit log record written as a JSON line.

type AuditProvider

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

AuditProvider wraps a Provider and logs every method call to a JSON Lines file.

func NewAuditProvider

func NewAuditProvider(inner Provider, name, kind, logPath string) (*AuditProvider, error)

NewAuditProvider creates an AuditProvider that delegates to inner and appends audit entries to the file at logPath. The file is created if it does not exist.

func (*AuditProvider) AddComment

func (a *AuditProvider) AddComment(ctx context.Context, issueKey string, body string) (*Comment, error)

func (*AuditProvider) AssignIssue

func (a *AuditProvider) AssignIssue(ctx context.Context, key string, userID string) error

func (*AuditProvider) Close

func (a *AuditProvider) Close() error

Close closes the underlying log file.

func (*AuditProvider) CreateIssue

func (a *AuditProvider) CreateIssue(ctx context.Context, issue *Issue) (*Issue, error)

func (*AuditProvider) DeleteIssue

func (a *AuditProvider) DeleteIssue(ctx context.Context, key string) error

func (*AuditProvider) EditIssue

func (a *AuditProvider) EditIssue(ctx context.Context, key string, opts EditOptions) (*Issue, error)

func (*AuditProvider) GetCurrentUser

func (a *AuditProvider) GetCurrentUser(ctx context.Context) (string, error)

func (*AuditProvider) GetIssue

func (a *AuditProvider) GetIssue(ctx context.Context, key string) (*Issue, error)

func (*AuditProvider) ListComments

func (a *AuditProvider) ListComments(ctx context.Context, issueKey string) ([]Comment, error)

func (*AuditProvider) ListIssues

func (a *AuditProvider) ListIssues(ctx context.Context, opts ListOptions) ([]Issue, error)

func (*AuditProvider) ListStatuses

func (a *AuditProvider) ListStatuses(ctx context.Context, key string) ([]Status, error)

func (*AuditProvider) TransitionIssue

func (a *AuditProvider) TransitionIssue(ctx context.Context, key string, targetStatus string) error

type Comment

type Comment struct {
	ID      string
	Author  string
	Body    string // markdown
	Created time.Time
}

Comment is a provider-agnostic comment representation.

type Commenter

type Commenter interface {
	ListComments(ctx context.Context, issueKey string) ([]Comment, error)
	AddComment(ctx context.Context, issueKey string, body string) (*Comment, error)
}

Commenter manages issue comments.

type Creator

type Creator interface {
	CreateIssue(ctx context.Context, issue *Issue) (*Issue, error)
}

Creator creates new issues.

type CredResult added in v0.13.0

type CredResult struct {
	Spec      CredSpec
	Available map[string]string // suffix → value, for env vars that are set
	Missing   []string          // suffixes that are not set
	Complete  bool              // true if all required vars are set
}

CredResult tells the caller what credentials are available.

func CheckCreds added in v0.13.0

func CheckCreds(spec CredSpec) CredResult

CheckCreds checks which credentials are available in the environment. It checks global env vars (e.g. JIRA_KEY) for each required suffix.

func CheckCredsEnv added in v0.13.0

func CheckCredsEnv(spec CredSpec, getenv func(string) string) CredResult

CheckCredsEnv is like CheckCreds but accepts a custom env lookup function.

type CredSpec added in v0.13.0

type CredSpec struct {
	Kind      string   // "jira", "github", etc.
	EnvPrefix string   // "JIRA", "GITHUB", etc.
	Required  []string // env var suffixes: ["KEY", "USER"] for Jira, ["TOKEN"] for GitHub
	Label     string   // Human-readable name
	HelpURL   string   // Where to generate tokens
}

CredSpec describes the credentials required for a tracker kind.

func CredSpecForKind added in v0.13.0

func CredSpecForKind(kind string) (CredSpec, bool)

CredSpecForKind returns the credential specification for a tracker kind.

type CurrentUserGetter

type CurrentUserGetter interface {
	GetCurrentUser(ctx context.Context) (string, error)
}

CurrentUserGetter retrieves the authenticated user's identifier.

type Deleter

type Deleter interface {
	DeleteIssue(ctx context.Context, key string) error
}

Deleter deletes (or closes) an issue by key.

type EditOptions

type EditOptions struct {
	Title       *string
	Description *string
}

EditOptions specifies which fields to update on an issue. Nil pointer fields are left unchanged; non-nil fields are set (even if empty).

type Editor

type Editor interface {
	EditIssue(ctx context.Context, key string, opts EditOptions) (*Issue, error)
}

Editor updates an existing issue's title and/or description.

type FindResult

type FindResult struct {
	Provider string `json:"provider"`
	Project  string `json:"project"`
	Key      string `json:"key"`
}

FindResult holds the outcome of FindTracker.

func FindTracker

func FindTracker(ctx context.Context, key string, instances []Instance) (*FindResult, error)

FindTracker determines which configured tracker owns the given key.

Resolution strategy:

  1. Match key format against regexes → candidate kinds
  2. Filter candidates against configured instances
  3. If one kind remains → return it (no API call)
  4. If ambiguous → probe each instance with GetIssue until one succeeds

type Getter

type Getter interface {
	GetIssue(ctx context.Context, key string) (*Issue, error)
}

Getter retrieves a single issue by key.

type Instance

type Instance struct {
	Name        string   // config entry name ("work", "personal"), empty for CLI-flag instances
	Kind        string   // "jira", "github", "linear"
	URL         string   // display URL
	User        string   // display user (Jira only)
	Description string   // optional human-readable description of what this tracker is for
	Safe        bool     // when true, destructive operations (deletes) are blocked
	Projects    []string // projects to index (e.g. ["KAN", "INFRA"])
	Provider    Provider
}

Instance represents a configured tracker backend ready for use.

func Resolve

func Resolve(name string, instances []Instance, keyHint string) (*Instance, error)

Resolve determines which tracker instance to use.

When name is provided it finds the single instance whose Name matches. When name is empty it auto-detects: if keyHint allows inferring the tracker kind it filters to that kind; otherwise if all instances share one Kind it returns the first; if multiple kinds exist it returns an error.

func ResolveByKind

func ResolveByKind(kind string, instances []Instance, name string) (*Instance, error)

ResolveByKind returns the first instance matching the given tracker kind. When name is non-empty, it further filters to that named instance.

type Issue

type Issue struct {
	Key         string    `json:"key"`
	Project     string    `json:"project"` // project key, e.g. "KAN"
	Type        string    `json:"type"`    // issue type, e.g. "Task", "Bug"
	Title       string    `json:"title"`
	Status      string    `json:"status"`
	Priority    string    `json:"priority"`
	Assignee    string    `json:"assignee"`
	Reporter    string    `json:"reporter"`
	Description string    `json:"description"` // markdown
	UpdatedAt   time.Time `json:"updated_at"`  // last modification timestamp
}

Issue is a provider-agnostic issue representation.

type ListOptions

type ListOptions struct {
	Project      string
	MaxResults   int
	IncludeAll   bool      // when false, only open/active issues are returned
	UpdatedSince time.Time // when non-zero, only return issues updated after this time
}

ListOptions controls issue listing behaviour.

type Lister

type Lister interface {
	ListIssues(ctx context.Context, opts ListOptions) ([]Issue, error)
}

Lister lists issues for a project.

type ParsedURL added in v0.13.0

type ParsedURL struct {
	Kind    string // "jira", "github", "gitlab", "linear", "azuredevops", "shortcut"
	BaseURL string // API-compatible base URL (e.g., "https://amazingcto.atlassian.net")
	Key     string // issue key in CLI format (e.g., "HUM-4", "owner/repo#42")
	Org     string // Azure DevOps org or Shortcut org slug
}

ParsedURL holds the results of parsing a tracker URL.

func ParseURL added in v0.13.0

func ParseURL(rawURL string) (*ParsedURL, bool)

ParseURL extracts tracker kind, base URL, and issue key from a tracker URL. Returns (nil, false) if the URL doesn't match any known tracker pattern.

type Provider

Provider combines all tracker operations into a single interface.

type SafeProvider added in v0.7.0

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

SafeProvider wraps a Provider and blocks destructive operations. Only DeleteIssue is blocked; all other methods delegate to the inner provider.

func NewSafeProvider added in v0.7.0

func NewSafeProvider(inner Provider, instanceName string) *SafeProvider

NewSafeProvider creates a SafeProvider that delegates to inner and blocks DeleteIssue with a descriptive error.

func (*SafeProvider) AddComment added in v0.7.0

func (s *SafeProvider) AddComment(ctx context.Context, issueKey string, body string) (*Comment, error)

func (*SafeProvider) AssignIssue added in v0.7.0

func (s *SafeProvider) AssignIssue(ctx context.Context, key string, userID string) error

func (*SafeProvider) CreateIssue added in v0.7.0

func (s *SafeProvider) CreateIssue(ctx context.Context, issue *Issue) (*Issue, error)

func (*SafeProvider) DeleteIssue added in v0.7.0

func (s *SafeProvider) DeleteIssue(_ context.Context, _ string) error

func (*SafeProvider) EditIssue added in v0.7.0

func (s *SafeProvider) EditIssue(ctx context.Context, key string, opts EditOptions) (*Issue, error)

func (*SafeProvider) GetCurrentUser added in v0.7.0

func (s *SafeProvider) GetCurrentUser(ctx context.Context) (string, error)

func (*SafeProvider) GetIssue added in v0.7.0

func (s *SafeProvider) GetIssue(ctx context.Context, key string) (*Issue, error)

func (*SafeProvider) ListComments added in v0.7.0

func (s *SafeProvider) ListComments(ctx context.Context, issueKey string) ([]Comment, error)

func (*SafeProvider) ListIssues added in v0.7.0

func (s *SafeProvider) ListIssues(ctx context.Context, opts ListOptions) ([]Issue, error)

func (*SafeProvider) ListStatuses added in v0.7.0

func (s *SafeProvider) ListStatuses(ctx context.Context, key string) ([]Status, error)

func (*SafeProvider) TransitionIssue added in v0.7.0

func (s *SafeProvider) TransitionIssue(ctx context.Context, key string, targetStatus string) error

type Status

type Status struct {
	Name string `json:"name"`
	Type string `json:"type,omitempty"` // "unstarted", "started", "done", "closed", or ""
}

Status represents a workflow state that an issue can be in.

type StatusLister

type StatusLister interface {
	ListStatuses(ctx context.Context, key string) ([]Status, error)
}

StatusLister lists available statuses for an issue. For Jira, only valid transitions from the current state are returned. For other trackers, all statuses for the project/workflow are returned.

type Transitioner

type Transitioner interface {
	TransitionIssue(ctx context.Context, key string, targetStatus string) error
}

Transitioner moves an issue to a new status.

Jump to

Keyboard shortcuts

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