tracker

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 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 ValidateURL

func ValidateURL(rawURL string) error

ValidateURL checks that rawURL is a valid HTTP(S) URL. This guards against SSRF by rejecting non-HTTP schemes.

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 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 HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer abstracts HTTP request execution for testability and to decouple from the concrete *http.Client type.

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
	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
}

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
}

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 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