Documentation
¶
Index ¶
- type ArchivedRepo
- type CodeHostClient
- type CodeHostConfig
- type CodeHostRepository
- type Connection
- type RepoConfigEntry
- type RepoListOptions
- type RepoListResult
- type RepoStats
- type Repository
- type Service
- func (s *Service) ClaimPendingIndexJob(ctx context.Context, workerID string) (*Repository, error)
- func (s *Service) CleanupStaleIndexing(ctx context.Context, olderThan time.Duration) (int64, error)
- func (s *Service) CreateConnection(ctx context.Context, name, connType, url, token string, excludeArchived bool, ...) (*Connection, error)
- func (s *Service) CreateRepository(ctx context.Context, connectionID int64, name, cloneURL, defaultBranch string, ...) (*Repository, error)
- func (s *Service) DeleteConnection(ctx context.Context, id int64) error
- func (s *Service) DeleteRepository(ctx context.Context, id int64) error
- func (s *Service) ExcludeRepository(ctx context.Context, id int64) error
- func (s *Service) FindRepositoryByZoektName(ctx context.Context, zoektName string) (*Repository, error)
- func (s *Service) GetConnection(ctx context.Context, id int64) (*Connection, error)
- func (s *Service) GetConnectionByName(ctx context.Context, name string) (*Connection, error)
- func (s *Service) GetConnectionStats(ctx context.Context, connectionID int64) (*RepoStats, error)
- func (s *Service) GetPendingIndexJobs(ctx context.Context, limit int) ([]Repository, error)
- func (s *Service) GetRepoStats(ctx context.Context, staleThreshold time.Time) (*RepoStats, error)
- func (s *Service) GetRepositoriesByStatus(ctx context.Context, status string, limit int) ([]Repository, error)
- func (s *Service) GetRepository(ctx context.Context, id int64) (*Repository, error)
- func (s *Service) GetRepositoryByName(ctx context.Context, name string) (*Repository, error)
- func (s *Service) GetStats(ctx context.Context) (*RepoStats, error)
- func (s *Service) IncludeRepository(ctx context.Context, id int64) error
- func (s *Service) ListConnections(ctx context.Context) ([]Connection, error)
- func (s *Service) ListRepositories(ctx context.Context, connectionID *int64) ([]Repository, error)
- func (s *Service) ListRepositoriesWithOptions(ctx context.Context, opts RepoListOptions) (*RepoListResult, error)
- func (s *Service) ReindexAll(ctx context.Context) (int64, error)
- func (s *Service) ReindexConnection(ctx context.Context, connectionID int64) (int64, error)
- func (s *Service) RestoreRepository(ctx context.Context, id int64) error
- func (s *Service) ScheduleIndex(ctx context.Context, repoID int64) error
- func (s *Service) SetRepoPollInterval(ctx context.Context, repoID int64, intervalSeconds int) error
- func (s *Service) SyncCodeHostsFromConfig(ctx context.Context, codeHosts map[string]CodeHostConfig) ([]int64, error)
- func (s *Service) SyncRepositories(ctx context.Context, connectionID int64, client CodeHostClient, ...) ([]ArchivedRepo, error)
- func (s *Service) TouchRepository(ctx context.Context, id int64) error
- func (s *Service) TriggerSyncAllRepos(ctx context.Context) (int, error)
- func (s *Service) TriggerSyncStaleRepos(ctx context.Context, staleThreshold time.Time) (int, error)
- func (s *Service) UpdateBranches(ctx context.Context, repoID int64, branches []string) error
- func (s *Service) UpdateConnection(ctx context.Context, id int64, name, connType, url, token string, ...) (*Connection, error)
- func (s *Service) UpdateIndexStatus(ctx context.Context, id int64, status string, indexed bool) error
- func (s *Service) UpdateIndexStatusIfMatch(ctx context.Context, id int64, expectedStatus, newStatus string, indexed bool) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArchivedRepo ¶
ArchivedRepo represents a repository that was newly archived and excluded during sync.
type CodeHostClient ¶
type CodeHostClient interface {
ListRepositories(ctx context.Context) ([]CodeHostRepository, error)
// GetRepository fetches a single repository by name (e.g., "owner/repo").
// Returns nil if the repository doesn't exist.
GetRepository(ctx context.Context, name string) (*CodeHostRepository, error)
}
CodeHostClient interface for syncing repositories.
type CodeHostConfig ¶
type CodeHostConfig struct {
Type string
URL string
Token string // Can be literal or env var reference like "$CS_GITHUB_TOKEN"
ExcludeArchived bool // When true, archived repos are excluded from sync
CleanupArchived bool // When true, auto-cleanup index for archived repos
Repos []string // Specific repos to index (if empty, syncs all accessible repos)
RepoConfigs []RepoConfigEntry // Per-repo configuration (branches, exclude, etc.)
}
CodeHostConfig represents a code host configuration from config file.
func (*CodeHostConfig) GetRepoConfig ¶
func (ch *CodeHostConfig) GetRepoConfig(repoName string) *RepoConfigEntry
GetRepoConfig returns the config for a specific repo name, or nil if not found.
func (*CodeHostConfig) ResolveToken ¶
func (ch *CodeHostConfig) ResolveToken() string
ResolveToken resolves the token, expanding environment variable references.
type CodeHostRepository ¶
type CodeHostRepository struct {
Name string
FullName string
CloneURL string
DefaultBranch string
Private bool
Archived bool
}
CodeHostRepository represents a repository from a code host.
type Connection ¶
type Connection struct {
ID int64
Name string
Type string // github, gitlab, gitea, bitbucket
URL string
Token string
ExcludeArchived bool // When true, archived repos are excluded from sync
CleanupArchived bool // When true, auto-cleanup index for archived repos
Repos []string // Specific repos to sync (if empty, syncs all accessible repos)
CreatedAt time.Time
UpdatedAt time.Time
}
Connection represents a code host connection.
type RepoConfigEntry ¶
type RepoConfigEntry struct {
Name string // Repository name (e.g., "owner/repo")
Branches []string // Specific branches to index (empty = default branch only)
Exclude bool // If true, exclude this repo from indexing (can be re-included)
Delete bool // If true, permanently delete this repo (won't be re-added on sync)
}
RepoConfigEntry represents per-repo configuration from config file.
type RepoListOptions ¶
type RepoListOptions struct {
ConnectionID *int64
Search string // Search by name (case-insensitive)
Status string // Filter by index status
Limit int // Max results (default 50)
Offset int // Pagination offset
}
RepoListOptions contains options for listing repositories with pagination.
type RepoListResult ¶
type RepoListResult struct {
Repos []Repository `json:"repos"`
TotalCount int `json:"total_count"`
Limit int `json:"limit"`
Offset int `json:"offset"`
HasMore bool `json:"has_more"`
}
RepoListResult represents the result of listing repositories.
type RepoStats ¶
type RepoStats struct {
Total int `json:"total"`
Indexed int `json:"indexed"`
Pending int `json:"pending"`
Indexing int `json:"indexing"`
Failed int `json:"failed"`
Excluded int `json:"excluded"`
Deleted int `json:"deleted"`
Stale int `json:"stale,omitempty"`
}
RepoStats contains repository statistics.
type Repository ¶
type Repository struct {
ID int64
ConnectionID int64
Name string
CloneURL string
DefaultBranch string
Branches db.StringArray
LastIndexed *time.Time
IndexStatus string
Excluded bool // When true, repo is excluded from sync and indexing
Deleted bool // When true, repo is permanently excluded and won't be re-added on sync
Archived bool // Reflects archived status from code host
CreatedAt time.Time
UpdatedAt time.Time
}
Repository represents a code repository.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles repository operations.
func NewService ¶
func NewService(pool db.Pool, encryptor *crypto.TokenEncryptor) *Service
NewService creates a new repository service.
func (*Service) ClaimPendingIndexJob ¶
ClaimPendingIndexJob atomically claims a single pending job for this worker Uses SELECT FOR UPDATE SKIP LOCKED to prevent race conditions.
func (*Service) CleanupStaleIndexing ¶
func (s *Service) CleanupStaleIndexing( ctx context.Context, olderThan time.Duration, ) (int64, error)
CleanupStaleIndexing resets repositories stuck in 'indexing' or 'cloning' state for too long.
func (*Service) CreateConnection ¶
func (s *Service) CreateConnection( ctx context.Context, name, connType, url, token string, excludeArchived bool, cleanupArchived bool, ) (*Connection, error)
CreateConnection creates a new code host connection.
func (*Service) CreateRepository ¶
func (s *Service) CreateRepository( ctx context.Context, connectionID int64, name, cloneURL, defaultBranch string, branches []string, ) (*Repository, error)
CreateRepository adds a new repository.
func (*Service) DeleteConnection ¶
DeleteConnection removes a connection and all its repositories.
func (*Service) DeleteRepository ¶
DeleteRepository marks a repository as deleted (soft delete). Deleted repos are permanently excluded and won't be re-added on sync.
func (*Service) ExcludeRepository ¶
ExcludeRepository marks a repository as excluded (soft delete) Excluded repos are skipped during sync and should be removed from the index.
func (*Service) FindRepositoryByZoektName ¶
func (s *Service) FindRepositoryByZoektName( ctx context.Context, zoektName string, ) (*Repository, error)
FindRepositoryByZoektName finds a repository by the name returned from Zoekt search. Zoekt may return names like "gitlab.example.com/group/repo" while the database stores just "group/repo". This method tries multiple matching strategies: 1. Exact match on name 2. Match where clone_url contains the zoekt name 3. Match where zoekt name ends with the database name.
func (*Service) GetConnection ¶
GetConnection retrieves a connection by ID.
func (*Service) GetConnectionByName ¶
GetConnectionByName retrieves a connection by name.
func (*Service) GetConnectionStats ¶
GetConnectionStats returns statistics for a specific connection.
func (*Service) GetPendingIndexJobs ¶
GetPendingIndexJobs returns repositories that need indexing Uses FOR UPDATE SKIP LOCKED to prevent multiple workers from picking the same jobs.
func (*Service) GetRepoStats ¶
GetRepoStats returns repository statistics grouped by index status.
func (*Service) GetRepositoriesByStatus ¶
func (s *Service) GetRepositoriesByStatus( ctx context.Context, status string, limit int, ) ([]Repository, error)
GetRepositoriesByStatus returns repositories with a specific status.
func (*Service) GetRepository ¶
GetRepository retrieves a repository by ID.
func (*Service) GetRepositoryByName ¶
GetRepositoryByName retrieves a repository by name.
func (*Service) IncludeRepository ¶
IncludeRepository marks a repository as included (un-exclude).
func (*Service) ListConnections ¶
func (s *Service) ListConnections(ctx context.Context) ([]Connection, error)
ListConnections returns all configured connections.
func (*Service) ListRepositories ¶
ListRepositories returns all repositories, optionally filtered by connection.
func (*Service) ListRepositoriesWithOptions ¶
func (s *Service) ListRepositoriesWithOptions( ctx context.Context, opts RepoListOptions, ) (*RepoListResult, error)
ListRepositoriesWithOptions returns repositories with filtering and pagination.
func (*Service) ReindexAll ¶
ReindexAll marks all indexed repositories for re-indexing.
func (*Service) ReindexConnection ¶
ReindexConnection marks all repositories in a connection for re-indexing.
func (*Service) RestoreRepository ¶
RestoreRepository un-deletes a repository (clears both deleted and excluded flags). This allows a previously deleted repo to be re-added and indexed.
func (*Service) ScheduleIndex ¶
ScheduleIndex marks a repository for indexing.
func (*Service) SetRepoPollInterval ¶
func (s *Service) SetRepoPollInterval( ctx context.Context, repoID int64, intervalSeconds int, ) error
SetRepoPollInterval sets a custom poll interval for a repository. Pass 0 to reset to default (NULL).
func (*Service) SyncCodeHostsFromConfig ¶
func (s *Service) SyncCodeHostsFromConfig( ctx context.Context, codeHosts map[string]CodeHostConfig, ) ([]int64, error)
SyncCodeHostsFromConfig syncs code hosts from config to database Config-defined code hosts take precedence and will overwrite existing connections with the same name Returns a list of connection IDs that were synced (for triggering repo discovery).
func (*Service) SyncRepositories ¶
func (s *Service) SyncRepositories( ctx context.Context, connectionID int64, client CodeHostClient, excludeArchived bool, cleanupArchived bool, allowedRepos []string, repoConfigs []RepoConfigEntry, ) ([]ArchivedRepo, error)
SyncRepositories fetches and syncs repositories from a connection Excluded repos are skipped - they won't be re-added or updated If excludeArchived is true, archived repos will be soft-deleted (excluded) If a repo becomes unarchived, it will be re-included on next sync. If allowedRepos is non-empty, only repos matching those patterns will be synced. If repoConfigs is non-empty, per-repo settings (branches, exclude) are applied. If cleanupArchived is true, returns repos that were newly excluded due to archival so the caller can queue cleanup jobs.
func (*Service) TouchRepository ¶
TouchRepository updates the updated_at timestamp for a repository. This is used as a heartbeat during long-running indexing operations to prevent the stale cleanup from resetting the repository status.
func (*Service) TriggerSyncAllRepos ¶
TriggerSyncAllRepos marks all indexed or failed repos as pending for re-indexing. Returns the count of repos marked for sync.
func (*Service) TriggerSyncStaleRepos ¶
func (s *Service) TriggerSyncStaleRepos( ctx context.Context, staleThreshold time.Time, ) (int, error)
TriggerSyncStaleRepos marks stale repos as pending for re-indexing. Returns the count of repos marked for sync.
func (*Service) UpdateBranches ¶
UpdateBranches updates the branches for a repository.
func (*Service) UpdateConnection ¶
func (s *Service) UpdateConnection( ctx context.Context, id int64, name, connType, url, token string, excludeArchived bool, cleanupArchived bool, ) (*Connection, error)
UpdateConnection updates an existing code host connection.
func (*Service) UpdateIndexStatus ¶
func (s *Service) UpdateIndexStatus( ctx context.Context, id int64, status string, indexed bool, ) error
UpdateIndexStatus updates the indexing status of a repository Uses optimistic locking to prevent race conditions.
func (*Service) UpdateIndexStatusIfMatch ¶
func (s *Service) UpdateIndexStatusIfMatch( ctx context.Context, id int64, expectedStatus, newStatus string, indexed bool, ) (bool, error)
UpdateIndexStatusIfMatch updates status only if current status matches expected This prevents race conditions when multiple workers process the same repo.