projectintegrations

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCredentialUnavailable = errors.New("integration credential unavailable")
View Source
var ErrInvalidInput = errors.New("invalid integration input")
View Source
var ErrNotFound = errors.New("integration resource not found")
View Source
var ErrProviderRequestFailed = errors.New("integration provider request failed")

Functions

func RetryAfter

func RetryAfter(header string) time.Duration

Types

type ActiveSyncRunStore

type ActiveSyncRunStore interface {
	GetActiveSyncRun(context.Context, string, Provider) (SyncRun, error)
}

type AsyncPollRunner

type AsyncPollRunner interface {
	SubmitProviderPoll(context.Context, string, Provider, SyncKind) (SyncRun, error)
}

type ConfluencePlanInput

type ConfluencePlanInput struct {
	ProjectID string
	Config    config.ConfluenceIntegration
	State     SyncState
	Kind      SyncKind
}

type ConfluencePoller

type ConfluencePoller interface {
	PollConfluence(context.Context, Credentials, ConfluenceQueryPlan) (PollResult, error)
}

type ConfluenceProgressPoller

type ConfluenceProgressPoller interface {
	PollConfluenceWithProgress(context.Context, Credentials, ConfluenceQueryPlan, PollProgressFunc) (PollResult, error)
}

type ConfluenceQueryPlan

type ConfluenceQueryPlan struct {
	ProjectID           string
	Provider            Provider
	Kind                SyncKind
	SpaceKeys           []string
	CQL                 string
	PageSize            int
	MaxResults          int
	IncrementalInterval time.Duration
	OverlapWindow       time.Duration
	Since               time.Time
	BodyRepresentation  string
	IncludeBody         bool
	IncludeComments     bool
	IncludeLabels       bool
	IncludeProperties   bool
}

func PlanConfluenceQuery

func PlanConfluenceQuery(input ConfluencePlanInput) (ConfluenceQueryPlan, error)

type CredentialResolver

type CredentialResolver struct {
	LookupEnv func(string) (string, bool)
	ReadFile  func(string) ([]byte, error)
}

func NewCredentialResolver

func NewCredentialResolver() CredentialResolver

func (CredentialResolver) ResolveAtlassian

func (resolver CredentialResolver) ResolveAtlassian(refs config.AtlassianCredentialRefs) (Credentials, error)

type Credentials

type Credentials struct {
	Email    string
	APIToken string
}

type ErrorCategory

type ErrorCategory string
const (
	ErrorCategoryAuthFailed            ErrorCategory = "auth_failed"
	ErrorCategoryPermissionDenied      ErrorCategory = "permission_denied"
	ErrorCategoryNotFound              ErrorCategory = "not_found"
	ErrorCategoryRateLimited           ErrorCategory = "rate_limited"
	ErrorCategoryUnexpectedStatus      ErrorCategory = "unexpected_status"
	ErrorCategoryRequestFailed         ErrorCategory = "request_failed"
	ErrorCategoryDecodeFailed          ErrorCategory = "decode_failed"
	ErrorCategoryCredentialUnavailable ErrorCategory = "credential_unavailable"
	ErrorCategoryStorageFailed         ErrorCategory = "storage_failed"
	ErrorCategoryInterrupted           ErrorCategory = "interrupted"
)

type ItemCountStore

type ItemCountStore interface {
	CountItems(context.Context, string, Provider) (int, error)
}

type ItemMetadata

type ItemMetadata struct {
	ProjectID       string
	Provider        Provider
	ItemID          string
	ItemKey         string
	ItemIDHash      string
	ItemKeyHash     string
	ItemType        string
	ItemStatus      string
	ItemUpdatedAt   time.Time
	ContentSHA256   string
	ProviderVersion string
	ProviderETag    string
	FirstSeenAt     time.Time
	LastSeenAt      time.Time
	LastRunID       string
	Changed         bool
}

type ItemMetadataInput

type ItemMetadataInput struct {
	ProjectID       string
	Provider        Provider
	ItemID          string
	ItemKey         string
	ItemType        string
	ItemStatus      string
	ItemUpdatedAt   time.Time
	ProviderVersion string
	ProviderETag    string
	FirstSeenAt     time.Time
	LastSeenAt      time.Time
	LastRunID       string
}

type JiraPlanInput

type JiraPlanInput struct {
	ProjectID string
	Config    config.JiraIntegration
	State     SyncState
	Kind      SyncKind
}

type JiraPoller

type JiraPoller interface {
	PollJira(context.Context, Credentials, JiraQueryPlan) (PollResult, error)
}

type JiraProgressPoller

type JiraProgressPoller interface {
	PollJiraWithProgress(context.Context, Credentials, JiraQueryPlan, PollProgressFunc) (PollResult, error)
}

type JiraQueryPlan

type JiraQueryPlan struct {
	ProjectID           string
	Provider            Provider
	Kind                SyncKind
	ProjectKeys         []string
	JQL                 string
	Fields              []string
	PageSize            int
	MaxResults          int
	IncrementalInterval time.Duration
	OverlapWindow       time.Duration
	Since               time.Time
	IncludeRichFields   bool
	IncludeComments     bool
}

func PlanJiraQuery

func PlanJiraQuery(input JiraPlanInput) (JiraQueryPlan, error)

type LocalReadInput

type LocalReadInput struct {
	ProjectID     string
	Provider      Provider
	ItemIDOrKey   string
	MaxChunkBytes int
	MaxChunks     int
}

type LocalSearchInput

type LocalSearchInput struct {
	ProjectID       string
	Provider        Provider
	Query           string
	MaxResults      int
	MaxSnippetBytes int
	CaseSensitive   bool
}

type Planner

type Planner struct {
	Jira       func(JiraPlanInput) (JiraQueryPlan, error)
	Confluence func(ConfluencePlanInput) (ConfluenceQueryPlan, error)
}

type PollItem

type PollItem struct {
	ID              string
	Key             string
	Type            string
	Status          string
	UpdatedAt       time.Time
	ProviderVersion string
	ProviderETag    string
}

type PollProgress

type PollProgress struct {
	ItemsSeen int
}

type PollProgressFunc

type PollProgressFunc func(context.Context, PollProgress) error

type PollResult

type PollResult struct {
	Items       []PollItem
	RichContent []RichContentPayload
	Cursor      string
}

type PollRunResult

type PollRunResult struct {
	Run   SyncRun
	State SyncState
}

type PollRunner

type PollRunner interface {
	RunProviderPoll(context.Context, string, Provider, SyncKind) (PollRunResult, error)
}

type ProjectIntegrationCounts

type ProjectIntegrationCounts struct {
	ProjectID string
	Counts    []ProviderItemCount
}

type Provider

type Provider string
const (
	ProviderJira       Provider = "jira"
	ProviderConfluence Provider = "confluence"
)

type ProviderError

type ProviderError struct {
	Provider   string
	Operation  string
	Category   ErrorCategory
	StatusCode int
	RetryAfter time.Duration
}

func DecodeError

func DecodeError(provider, operation string) *ProviderError

func ProviderErrorFromStatus

func ProviderErrorFromStatus(provider, operation string, statusCode int, retryAfter time.Duration) *ProviderError

func RequestError

func RequestError(provider, operation string) *ProviderError

func (*ProviderError) Error

func (err *ProviderError) Error() string

func (*ProviderError) Unwrap

func (err *ProviderError) Unwrap() error

type ProviderItemCount

type ProviderItemCount struct {
	ProjectID string
	Provider  Provider
	Count     int
}

type ProviderPollAccepted

type ProviderPollAccepted struct {
	ProjectID string
	Provider  Provider
	Accepted  bool
	Run       SyncRunStatusView
}

type ProviderPollStatus

type ProviderPollStatus struct {
	ProjectID string
	Provider  Provider
	Run       SyncRunStatusView
	SyncState SyncStateStatus
}

type ProviderSchedule

type ProviderSchedule struct {
	ProjectID           string
	Provider            Provider
	InitialFullSync     string
	IncrementalInterval time.Duration
	EmptyPollSleep      time.Duration
	MaxIdleSleep        time.Duration
}

type ProviderStatus

type ProviderStatus struct {
	ProjectID            string
	Provider             Provider
	Configured           bool
	Enabled              bool
	AuthMode             string
	CredentialSource     string
	AllowlistKind        string
	AllowlistCount       int
	IngestionEnabled     bool
	InitialFullSync      string
	IncrementalInterval  time.Duration
	EmptyPollSleep       time.Duration
	MaxIdleSleep         time.Duration
	OverlapWindow        time.Duration
	InitialPageSize      int
	IncrementalPageSize  int
	MaxResults           int
	SourcePersisted      bool
	SourceAllowlistCount int
	SyncState            *SyncStateStatus
	LastRun              *SyncRunStatusView
}

type ProviderSummary

type ProviderSummary struct {
	ProjectID         string
	Provider          Provider
	Configured        bool
	Enabled           bool
	AuthMode          string
	CredentialSource  string
	AllowlistKind     string
	AllowlistCount    int
	IngestionEnabled  bool
	IncrementalPeriod time.Duration
}

type RichContentArtifact

type RichContentArtifact struct {
	ID            string
	ProjectID     string
	Provider      Provider
	ItemID        string
	ItemKey       string
	ItemType      string
	FieldCount    int
	ChunkCount    int
	ContentSHA256 string
	UpdatedAt     time.Time
}

type RichContentChunk

type RichContentChunk struct {
	ID        string
	ProjectID string
	Provider  Provider
	ItemID    string
	ItemKey   string
	ItemType  string
	FieldName string
	Label     string
	Index     int
	ByteStart int
	ByteEnd   int
	Text      string
	UpdatedAt time.Time
}

func ChunkRichContentItem

func ChunkRichContentItem(item RichContentItem, options RichContentOptions) ([]RichContentChunk, error)

type RichContentChunkView

type RichContentChunkView struct {
	ID            string
	ArtifactID    string
	ProjectID     string
	Provider      Provider
	ItemID        string
	ItemKey       string
	ItemType      string
	FieldName     string
	Label         string
	Index         int
	ByteStart     int
	ByteEnd       int
	Text          string
	TextTruncated bool
	UpdatedAt     time.Time
}

type RichContentField

type RichContentField struct {
	Name  string
	Label string
	Text  string
}

type RichContentGraphResult

type RichContentGraphResult struct {
	ArtifactID    string
	ChunksWritten int
	ContentSHA256 string
	Changed       bool
}

type RichContentGraphStore

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

func NewRichContentGraphStore

func NewRichContentGraphStore(graph integrationGraphBackend) *RichContentGraphStore

func (*RichContentGraphStore) GetRichContentItem

func (store *RichContentGraphStore) GetRichContentItem(ctx context.Context, projectID string, provider Provider, itemID string, options RichContentReadOptions) (RichContentReadResult, error)

func (*RichContentGraphStore) PutRichContentItem

func (store *RichContentGraphStore) PutRichContentItem(ctx context.Context, item RichContentItem, chunks []RichContentChunk) (RichContentGraphResult, error)

func (*RichContentGraphStore) SearchRichContent

func (store *RichContentGraphStore) SearchRichContent(ctx context.Context, projectID string, options RichContentSearchOptions) ([]RichContentSearchResult, error)

type RichContentItem

type RichContentItem struct {
	ProjectID string
	Provider  Provider
	ItemID    string
	ItemKey   string
	ItemType  string
	UpdatedAt time.Time
	Fields    []RichContentField
}

type RichContentOptions

type RichContentOptions struct {
	MaxItemTextBytes int
	MaxChunkBytes    int
}

type RichContentPayload

type RichContentPayload struct {
	Item   RichContentItem
	Chunks []RichContentChunk
}

type RichContentReadOptions

type RichContentReadOptions struct {
	MaxChunkBytes int
	MaxChunks     int
}

type RichContentReadResult

type RichContentReadResult struct {
	Artifact        RichContentArtifact
	Chunks          []RichContentChunkView
	ChunksTruncated bool
}

type RichContentSearchOptions

type RichContentSearchOptions struct {
	Provider        Provider
	Query           string
	MaxResults      int
	MaxSnippetBytes int
	CaseSensitive   bool
}

type RichContentSearchResult

type RichContentSearchResult struct {
	Artifact         RichContentArtifact
	Chunk            RichContentChunkView
	Snippet          string
	SnippetTruncated bool
	ByteStart        int
	ByteEnd          int
}

type RichContentStore

type RichContentStore interface {
	PutRichContentItem(context.Context, RichContentItem, []RichContentChunk) (RichContentGraphResult, error)
}

type Runner

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

func NewRunner

func NewRunner(options RunnerOptions) (*Runner, error)

func (*Runner) ExecutePreparedProviderPoll

func (runner *Runner) ExecutePreparedProviderPoll(ctx context.Context, run SyncRun) (PollRunResult, error)

func (*Runner) FailPreparedProviderPoll

func (runner *Runner) FailPreparedProviderPoll(ctx context.Context, run SyncRun, errorCategory string) (SyncRun, error)

func (*Runner) PrepareProviderPoll

func (runner *Runner) PrepareProviderPoll(ctx context.Context, projectID string, provider Provider, kind SyncKind) (SyncRun, error)

func (*Runner) RunProviderPoll

func (runner *Runner) RunProviderPoll(ctx context.Context, projectID string, provider Provider, kind SyncKind) (PollRunResult, error)

type RunnerBatchItemStore

type RunnerBatchItemStore interface {
	UpsertItems(context.Context, []ItemMetadataInput) ([]ItemMetadata, error)
}

type RunnerOptions

type RunnerOptions struct {
	Projects           []config.Project
	Store              RunnerStore
	RichContentStore   RichContentStore
	CredentialResolver CredentialResolver
	JiraClient         JiraPoller
	ConfluenceClient   ConfluencePoller
	Planner            Planner
	Now                func() time.Time
	NewRunID           func() string
}

type RunnerStore

type RunnerStore interface {
	UpsertSource(context.Context, SourceMetadataInput) (SourceMetadata, error)
	CreateSyncRun(context.Context, SyncRun) error
	UpdateSyncRun(context.Context, SyncRun) error
	GetSyncState(context.Context, string, Provider) (SyncState, error)
	UpdateSyncState(context.Context, SyncStateInput) (SyncState, error)
	UpsertItem(context.Context, ItemMetadataInput) (ItemMetadata, error)
}

type SQLiteStore

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

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) *SQLiteStore

func (*SQLiteStore) CountItems

func (store *SQLiteStore) CountItems(ctx context.Context, projectID string, provider Provider) (int, error)

func (*SQLiteStore) CreateSyncRun

func (store *SQLiteStore) CreateSyncRun(ctx context.Context, run SyncRun) error

func (*SQLiteStore) FailActiveSyncRuns

func (store *SQLiteStore) FailActiveSyncRuns(ctx context.Context, finishedAt time.Time, errorCategory string) (int, error)

func (*SQLiteStore) GetActiveSyncRun

func (store *SQLiteStore) GetActiveSyncRun(ctx context.Context, projectID string, provider Provider) (SyncRun, error)

func (*SQLiteStore) GetSyncRun

func (store *SQLiteStore) GetSyncRun(ctx context.Context, projectID string, provider Provider, runID string) (SyncRun, error)

func (*SQLiteStore) GetSyncState

func (store *SQLiteStore) GetSyncState(ctx context.Context, projectID string, provider Provider) (SyncState, error)

func (*SQLiteStore) ListItems

func (store *SQLiteStore) ListItems(ctx context.Context, projectID string, provider Provider) ([]ItemMetadata, error)

func (*SQLiteStore) ListSources

func (store *SQLiteStore) ListSources(ctx context.Context, projectID string) ([]SourceMetadata, error)

func (*SQLiteStore) UpdateSyncRun

func (store *SQLiteStore) UpdateSyncRun(ctx context.Context, run SyncRun) error

func (*SQLiteStore) UpdateSyncState

func (store *SQLiteStore) UpdateSyncState(ctx context.Context, input SyncStateInput) (SyncState, error)

func (*SQLiteStore) UpsertItem

func (store *SQLiteStore) UpsertItem(ctx context.Context, input ItemMetadataInput) (ItemMetadata, error)

func (*SQLiteStore) UpsertItems

func (store *SQLiteStore) UpsertItems(ctx context.Context, inputs []ItemMetadataInput) ([]ItemMetadata, error)

func (*SQLiteStore) UpsertSource

func (store *SQLiteStore) UpsertSource(ctx context.Context, input SourceMetadataInput) (SourceMetadata, error)

type Scheduler

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

func NewScheduler

func NewScheduler(projects []config.Project, runner PollRunner, options SchedulerOptions) (*Scheduler, error)

func (*Scheduler) Diagnostics

func (scheduler *Scheduler) Diagnostics() SchedulerDiagnostics

func (*Scheduler) RunProviderPoll

func (scheduler *Scheduler) RunProviderPoll(ctx context.Context, projectID string, provider Provider, kind SyncKind) (PollRunResult, error)

func (*Scheduler) ScheduledProviders

func (scheduler *Scheduler) ScheduledProviders() []ProviderSchedule

func (*Scheduler) Start

func (scheduler *Scheduler) Start(ctx context.Context) error

func (*Scheduler) Stop

func (scheduler *Scheduler) Stop(ctx context.Context) error

func (*Scheduler) SubmitProviderPoll

func (scheduler *Scheduler) SubmitProviderPoll(ctx context.Context, projectID string, provider Provider, kind SyncKind) (SyncRun, error)

type SchedulerDiagnostics

type SchedulerDiagnostics struct {
	Started                bool
	ScheduledProviderCount int
	ActivePollCount        int
	ActivePolls            map[string]int
}

type SchedulerOptions

type SchedulerOptions struct {
	Sleep  func(context.Context, time.Duration) error
	Logger *slog.Logger
}

type Service

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

func NewService

func NewService(projects []config.Project, store Store) (*Service, error)

func NewServiceWithOptions

func NewServiceWithOptions(projects []config.Project, store Store, options ServiceOptions) (*Service, error)

func (*Service) Counts

func (service *Service) Counts(ctx context.Context, projectID string) (ProjectIntegrationCounts, error)

func (*Service) ListProviders

func (service *Service) ListProviders(projectID string) ([]ProviderSummary, error)

func (*Service) PollProvider

func (service *Service) PollProvider(ctx context.Context, projectID string, provider Provider, kind SyncKind) (ProviderPollStatus, error)

func (*Service) PollRunStatus

func (service *Service) PollRunStatus(ctx context.Context, projectID string, provider Provider, runID string) (ProviderPollStatus, error)

func (*Service) ReadLocalContent

func (service *Service) ReadLocalContent(ctx context.Context, input LocalReadInput) (RichContentReadResult, error)

func (*Service) SearchLocalContent

func (service *Service) SearchLocalContent(ctx context.Context, input LocalSearchInput) ([]RichContentSearchResult, error)

func (*Service) Status

func (service *Service) Status(ctx context.Context, projectID string, provider Provider) (ProviderStatus, error)

func (*Service) SubmitProviderPoll

func (service *Service) SubmitProviderPoll(ctx context.Context, projectID string, provider Provider, kind SyncKind) (ProviderPollAccepted, error)

func (*Service) UpsertConfiguredSources

func (service *Service) UpsertConfiguredSources(ctx context.Context, projectID string) ([]SourceMetadata, error)

type ServiceOptions

type ServiceOptions struct {
	Runner      PollRunner
	RichContent RichContentReader
}

type SourceMetadata

type SourceMetadata struct {
	ProjectID           string
	Provider            Provider
	SiteURLHash         string
	CloudIDHash         string
	AllowlistHash       string
	AllowlistCount      int
	AuthMode            string
	IngestionEnabled    bool
	InitialFullSync     string
	IncrementalInterval time.Duration
	EmptyPollSleep      time.Duration
	MaxIdleSleep        time.Duration
	OverlapWindow       time.Duration
	InitialPageSize     int
	IncrementalPageSize int
	MaxResults          int
	UpdatedAt           time.Time
}

type SourceMetadataInput

type SourceMetadataInput struct {
	ProjectID           string
	Provider            Provider
	SiteURL             string
	CloudID             string
	Allowlist           []string
	AuthMode            string
	IngestionEnabled    bool
	InitialFullSync     string
	IncrementalInterval time.Duration
	EmptyPollSleep      time.Duration
	MaxIdleSleep        time.Duration
	OverlapWindow       time.Duration
	InitialPageSize     int
	IncrementalPageSize int
	MaxResults          int
	UpdatedAt           time.Time
}

type Store

type Store interface {
	UpsertSource(context.Context, SourceMetadataInput) (SourceMetadata, error)
	ListSources(context.Context, string) ([]SourceMetadata, error)
	GetSyncState(context.Context, string, Provider) (SyncState, error)
	GetSyncRun(context.Context, string, Provider, string) (SyncRun, error)
}

type SyncKind

type SyncKind string
const (
	SyncKindInitialFull SyncKind = "initial_full"
	SyncKindIncremental SyncKind = "incremental"
)

type SyncRun

type SyncRun struct {
	ID                   string
	ProjectID            string
	Provider             Provider
	Kind                 SyncKind
	Status               SyncRunStatus
	ItemsSeen            int
	ItemsUpserted        int
	ItemsChanged         int
	ItemsUnchanged       int
	RichContentChanged   int
	RichContentUnchanged int
	EmptyPoll            bool
	IdleSleep            time.Duration
	ErrorCategory        string
	StartedAt            time.Time
	FinishedAt           time.Time
}

type SyncRunStatus

type SyncRunStatus string
const (
	SyncRunStatusPending   SyncRunStatus = "pending"
	SyncRunStatusRunning   SyncRunStatus = "running"
	SyncRunStatusCompleted SyncRunStatus = "completed"
	SyncRunStatusFailed    SyncRunStatus = "failed"
	SyncRunStatusNoOp      SyncRunStatus = "no_op"
)

type SyncRunStatusView

type SyncRunStatusView struct {
	ID                   string
	Kind                 SyncKind
	Status               SyncRunStatus
	ItemsSeen            int
	ItemsUpserted        int
	ItemsChanged         int
	ItemsUnchanged       int
	RichContentChanged   int
	RichContentUnchanged int
	EmptyPoll            bool
	IdleSleep            time.Duration
	ErrorCategory        string
	StartedAt            time.Time
	FinishedAt           time.Time
}

type SyncState

type SyncState struct {
	ProjectID             string
	Provider              Provider
	LastRunID             string
	LastSuccessfulRunID   string
	LastSuccessAt         time.Time
	LastFullSyncAt        time.Time
	LastIncrementalSyncAt time.Time
	LastEmptyPollAt       time.Time
	EmptyPollCount        int
	CurrentIdleSleep      time.Duration
	Cursor                string
	CursorHash            string
	UpdatedAt             time.Time
}

type SyncStateInput

type SyncStateInput struct {
	ProjectID             string
	Provider              Provider
	LastRunID             string
	LastSuccessfulRunID   string
	LastSuccessAt         time.Time
	LastFullSyncAt        time.Time
	LastIncrementalSyncAt time.Time
	LastEmptyPollAt       time.Time
	EmptyPollCount        int
	CurrentIdleSleep      time.Duration
	Cursor                string
	UpdatedAt             time.Time
}

type SyncStateStatus

type SyncStateStatus struct {
	LastRunID             string
	LastSuccessfulRunID   string
	LastSuccessAt         time.Time
	LastFullSyncAt        time.Time
	LastIncrementalSyncAt time.Time
	LastEmptyPollAt       time.Time
	EmptyPollCount        int
	CurrentIdleSleep      time.Duration
	CursorHashPresent     bool
	UpdatedAt             time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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