repolist

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package repolist caches and queries the repository lists of connected git providers: one cached snapshot per connection, filtered and paged server side so a huge account never reaches the browser in one response.

Index

Constants

View Source
const (
	DefaultLimit = 100
	MaxLimit     = 500
)

DefaultLimit and MaxLimit bound one page of results.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache serves repository lists per connection key: fresh from the store, stale-while-revalidate, with concurrent fetches for one key sharing a single provider call.

func NewCache

func NewCache(st Store, cfg Config, logger *slog.Logger) *Cache

NewCache builds a Cache over st.

func (*Cache) Config

func (c *Cache) Config() Config

Config returns the cache bounds in effect.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key, provider string, refresh bool, fetch FetchFunc) (Result, error)

Get returns the repository list for key, fetching through fetch when the cache is empty, expired beyond StaleMax, or a manual refresh is asked for.

func (*Cache) Invalidate

func (c *Cache) Invalidate(ctx context.Context, prefix string) error

Invalidate drops every cached list whose key starts with prefix, and discards any fetch still in flight for them so it cannot re-save old data.

func (*Cache) Wait

func (c *Cache) Wait()

Wait blocks until background refreshes finish (tests, shutdown).

type Config

type Config struct {
	// TTL is how long a snapshot is served without any provider call.
	TTL time.Duration
	// StaleMax is how long an expired snapshot may still be served while it
	// refreshes in the background or the provider is failing.
	StaleMax time.Duration
	// RefreshMin throttles manual refreshes of one connection.
	RefreshMin time.Duration
	// MaxItems caps one connection's list; beyond it the list is marked truncated.
	MaxItems int
}

Config holds the cache bounds, all overridable through APP_GIT_REPO_*.

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv reads the cache bounds from the environment.

type FetchFunc

type FetchFunc func(ctx context.Context, prior *Snapshot) (Snapshot, error)

FetchFunc lists a connection's repositories. prior is the previous snapshot (possibly expired) for conditional requests, nil when none.

type MemoryStore

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

MemoryStore is a Store that keeps snapshots in process memory, for a control plane whose main store cannot persist them and for tests.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns an empty MemoryStore.

func (*MemoryStore) DeleteGitRepoListCachePrefix

func (s *MemoryStore) DeleteGitRepoListCachePrefix(_ context.Context, prefix string) error

DeleteGitRepoListCachePrefix implements Store.

func (*MemoryStore) GetGitRepoListCache

func (s *MemoryStore) GetGitRepoListCache(_ context.Context, key string) (store.GitRepoListCacheEntry, error)

GetGitRepoListCache implements Store.

func (*MemoryStore) PutGitRepoListCache

func (s *MemoryStore) PutGitRepoListCache(_ context.Context, e store.GitRepoListCacheEntry) error

PutGitRepoListCache implements Store.

type Mode

type Mode string

Mode selects how a boolean attribute filters the list.

const (
	Include Mode = "include"
	Exclude Mode = "exclude"
	Only    Mode = "only"
)

Filter modes for the archived and forks attributes.

func ParseMode

func ParseMode(v string) Mode

ParseMode maps a query value to a Mode, defaulting to Include.

type OwnerCount

type OwnerCount struct {
	Login string `json:"login"`
	Count int    `json:"count"`
}

OwnerCount is one owner facet: how many repos an owner/org has under the archived and forks filters.

type Page

type Page struct {
	Items  []Repo
	Total  int
	Limit  int
	Offset int
	// NextOffset is the offset of the following page, or -1 on the last page.
	NextOffset int
	Owners     []OwnerCount
}

Page is one filtered, ordered slice of a repository list.

func Apply

func Apply(repos []Repo, q Query) Page

Apply filters repos by q and returns the requested page, ordered by full name so offsets stay stable between requests.

type Query

type Query struct {
	Search   string
	Owner    string
	Archived Mode
	Forks    Mode
	Limit    int
	Offset   int
}

Query narrows and pages a repository list.

type Repo

type Repo struct {
	Key           string `json:"key"`
	FullName      string `json:"full_name"`
	Name          string `json:"name"`
	Owner         string `json:"owner"`
	Private       bool   `json:"private"`
	Archived      bool   `json:"archived"`
	Fork          bool   `json:"fork"`
	DefaultBranch string `json:"default_branch"`
	CloneURL      string `json:"clone_url"`
	WebURL        string `json:"web_url,omitempty"`
	Language      string `json:"language,omitempty"`
	PushedAt      string `json:"pushed_at,omitempty"`
	ProjectID     int64  `json:"project_id,omitempty"`
	AccountType   string `json:"account_type,omitempty"`
	// Provider, ConnectionID, ConnectionLabel and Account say which
	// connection a row came from; they are stamped when lists merge and are
	// never cached.
	Provider        string `json:"provider,omitempty"`
	ConnectionID    string `json:"connection_id,omitempty"`
	ConnectionLabel string `json:"connection_label,omitempty"`
	Account         string `json:"account,omitempty"`
}

Repo is one repository in provider-neutral form.

type Result

type Result struct {
	Snapshot
	// Stale is true when the snapshot is older than the TTL.
	Stale bool
	// Refreshing is true when a background refresh was started for it.
	Refreshing bool
	// RateLimit is set when a refresh was blocked by the provider's rate limit.
	RateLimit *gitprovider.RateLimitError
	// RefreshErr is set when a refresh failed and the stale snapshot was served instead.
	RefreshErr error
}

Result is what a Get returns: the snapshot plus how fresh it is.

type Snapshot

type Snapshot struct {
	Repos     []Repo
	Truncated bool
	FetchedAt time.Time
	// Meta is provider-specific revalidation data (GitHub page ETags).
	Meta string
}

Snapshot is one connection's full repository list as last fetched.

type Store

type Store interface {
	GetGitRepoListCache(ctx context.Context, key string) (store.GitRepoListCacheEntry, error)
	PutGitRepoListCache(ctx context.Context, e store.GitRepoListCacheEntry) error
	DeleteGitRepoListCachePrefix(ctx context.Context, prefix string) error
}

Store persists snapshots; *store.DB satisfies it.

Jump to

Keyboard shortcuts

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