Documentation
¶
Overview ¶
Package extraction provides file fetching and metadata extraction for PRs. It supports caching, multiple extractor types, and label composition from templates.
Index ¶
- Constants
- type Cache
- type CacheEntry
- type ExtractionResult
- type Extractor
- type ExtractorConfig
- type Fetcher
- func (f *Fetcher) CacheSize() int
- func (f *Fetcher) CleanExpired() int
- func (f *Fetcher) ClearCache()
- func (f *Fetcher) GetFile(ctx context.Context, pr github.PullRequest, path string) (*FileContent, error)
- func (f *Fetcher) GetFileWithRef(ctx context.Context, repo github.Repository, path string, ref string) (*FileContent, error)
- type FileContent
- type FileFetcher
- type LabelComposer
- type LabelTemplate
Constants ¶
const ( // DefaultCacheTTL is the default time-to-live for cached files DefaultCacheTTL = 5 * time.Minute // DefaultMaxCacheSize is the default maximum number of cached files DefaultMaxCacheSize = 1000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides an in-memory LRU cache for file content with TTL support. It is safe for concurrent use and automatically evicts expired entries.
func (*Cache) CleanExpired ¶
CleanExpired removes all expired entries from the cache. This should be called periodically to prevent memory buildup.
func (*Cache) Get ¶
func (c *Cache) Get(key string) *CacheEntry
Get retrieves a cache entry by key. Returns nil if the key is not found or the entry is expired.
func (*Cache) Set ¶
func (c *Cache) Set(key string, entry *CacheEntry)
Set stores a cache entry with the default TTL.
func (*Cache) SetWithTTL ¶
func (c *Cache) SetWithTTL(key string, entry *CacheEntry, ttl time.Duration)
SetWithTTL stores a cache entry with a custom TTL.
type CacheEntry ¶
type CacheEntry struct {
// Content is the cached file content
Content *FileContent
// ETag is the HTTP ETag for conditional requests
ETag string
// ExpiresAt is when the cache entry expires
ExpiresAt time.Time
}
CacheEntry represents a cached file with metadata.
func (*CacheEntry) IsExpired ¶
func (ce *CacheEntry) IsExpired() bool
IsExpired returns true if the cache entry has expired.
type ExtractionResult ¶
type ExtractionResult struct {
// Metadata contains all extracted key-value pairs
Metadata map[string]string
// Labels contains rendered labels ready for GitHub
Labels map[string]string
// Errors contains any non-fatal errors encountered
Errors []error
// ProcessingTime is how long extraction took
ProcessingTime time.Duration
}
ExtractionResult represents the result of metadata extraction.
type Extractor ¶
type Extractor interface {
// Name returns the unique name of this extractor
Name() string
// Extract extracts metadata from the given PR using the file fetcher.
// Returns a map of key-value pairs representing the extracted metadata.
Extract(ctx context.Context, pr github.PullRequest, fetcher FileFetcher) (map[string]string, error)
// Required returns true if this extractor must succeed for qualification to pass
Required() bool
}
Extractor defines the interface for metadata extractors. Each extractor reads files from a PR and extracts specific metadata.
type ExtractorConfig ¶
type ExtractorConfig struct {
// Name is the extractor name
Name string `json:"name" yaml:"name"`
// Type is the extractor type (version, environment, layout, annotation)
Type string `json:"type" yaml:"type"`
// FilePath is the file to extract from (for file-based extractors)
FilePath string `json:"filePath,omitempty" yaml:"filePath,omitempty"`
// Key is the YAML/JSON key to extract
Key string `json:"key,omitempty" yaml:"key,omitempty"`
// JSONPath is the JSONPath expression for complex extraction
JSONPath string `json:"jsonPath,omitempty" yaml:"jsonPath,omitempty"`
// Pattern is a regex pattern for pattern-based extraction
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
// DefaultValue is used if extraction fails
DefaultValue string `json:"defaultValue,omitempty" yaml:"defaultValue,omitempty"`
// Required indicates if this extraction must succeed
Required bool `json:"required" yaml:"required"`
// Transform specifies value transformation (lowercase, uppercase, trim)
Transform string `json:"transform,omitempty" yaml:"transform,omitempty"`
}
ExtractorConfig defines configuration for a metadata extractor.
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher implements FileFetcher with caching support.
func NewFetcher ¶
NewFetcher creates a new file fetcher with default cache settings.
func NewFetcherWithCache ¶
func NewFetcherWithCache(client *github.Client, logger *zap.Logger, maxSize int, ttl time.Duration) *Fetcher
NewFetcherWithCache creates a new file fetcher with custom cache settings.
func (*Fetcher) CleanExpired ¶
CleanExpired removes expired entries from the cache.
func (*Fetcher) GetFile ¶
func (f *Fetcher) GetFile(ctx context.Context, pr github.PullRequest, path string) (*FileContent, error)
GetFile fetches a file from a PR with caching support. Uses the PR's head SHA as the ref for file retrieval.
func (*Fetcher) GetFileWithRef ¶
func (f *Fetcher) GetFileWithRef(ctx context.Context, repo github.Repository, path string, ref string) (*FileContent, error)
GetFileWithRef fetches a file from a specific Git ref with caching.
type FileContent ¶
type FileContent struct {
// Path is the file path in the repository
Path string
// Content is the decoded file content
Content []byte
// SHA is the Git SHA of the file
SHA string
// Size is the file size in bytes
Size int64
// FetchedAt is when the file was fetched
FetchedAt time.Time
}
FileContent represents a cached file from a PR.
type FileFetcher ¶
type FileFetcher interface {
// GetFile fetches a file from a PR with caching support.
// Uses the PR's head SHA as the ref for file retrieval.
GetFile(ctx context.Context, pr github.PullRequest, path string) (*FileContent, error)
// GetFileWithRef fetches a file from a specific Git ref.
GetFileWithRef(ctx context.Context, repo github.Repository, path string, ref string) (*FileContent, error)
// ClearCache clears the entire cache.
ClearCache()
}
FileFetcher defines the interface for fetching files from GitHub with caching.
type LabelComposer ¶
type LabelComposer interface {
// Compose renders label templates using extracted metadata.
// Returns a map of label names to their rendered values.
Compose(metadata map[string]string) (map[string]string, error)
}
LabelComposer defines the interface for composing labels from templates.
type LabelTemplate ¶
type LabelTemplate struct {
// Name is the label name pattern (e.g., "cd/version:{version}")
Name string `json:"name" yaml:"name"`
// MetadataKey is the metadata key to use for rendering
MetadataKey string `json:"metadataKey" yaml:"metadataKey"`
// DefaultValue is used if metadata key is missing
DefaultValue string `json:"defaultValue,omitempty" yaml:"defaultValue,omitempty"`
// Prefix is the label prefix (e.g., "cd/")
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
}
LabelTemplate defines a label template for rendering.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package extractors provides specific metadata extractors for pull requests.
|
Package extractors provides specific metadata extractors for pull requests. |