Documentation
¶
Index ¶
- Constants
- type CachedForge
- func (c *CachedForge) FetchRef(number int) string
- func (c *CachedForge) GetPR(ctx context.Context, number int) (*PR, error)
- func (c *CachedForge) ListPRs(ctx context.Context) ([]PR, error)
- func (c *CachedForge) ListPRsAsync(ctx context.Context) <-chan PRResult
- func (c *CachedForge) Name() string
- func (c *CachedForge) PRURL(number int) string
- type Forge
- type Option
- type PR
- type PRResult
- type PRState
- type ReviewStatus
- type TokenFunc
Constants ¶
const ( // CacheTTL is how long cached PR data is considered fresh. CacheTTL = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedForge ¶
type CachedForge struct {
// contains filtered or unexported fields
}
CachedForge wraps a Forge and caches ListPRs results to disk. Stale-while-revalidate: returns stale data immediately and refreshes in the background when the cache is expired.
func NewCachedForge ¶
func NewCachedForge(inner Forge, gitCommonDir string) *CachedForge
NewCachedForge wraps a Forge with file-based PR caching. gitCommonDir should be the output of `git rev-parse --git-common-dir`.
func (*CachedForge) FetchRef ¶
func (c *CachedForge) FetchRef(number int) string
FetchRef returns the git fetch refspec for the given PR number.
func (*CachedForge) ListPRs ¶
func (c *CachedForge) ListPRs(ctx context.Context) ([]PR, error)
ListPRs returns cached PR data if fresh, or stale data while refreshing in the background. On cache miss, fetches synchronously.
func (*CachedForge) ListPRsAsync ¶
func (c *CachedForge) ListPRsAsync(ctx context.Context) <-chan PRResult
ListPRsAsync returns cached data immediately (if available) and always fetches fresh data in the background. The returned channel receives up to two results:
- Cached data (FromCache=true) — sent immediately if a cache file exists
- Fresh data (FromCache=false) — sent when the API call completes
The channel is closed after all results are sent.
func (*CachedForge) Name ¶
func (c *CachedForge) Name() string
Name returns the name of the underlying forge.
func (*CachedForge) PRURL ¶
func (c *CachedForge) PRURL(number int) string
PRURL returns the URL for the given PR number.
type Forge ¶
type Forge interface {
// ListPRs returns all open pull requests.
ListPRs(ctx context.Context) ([]PR, error)
// GetPR returns a specific PR by number.
GetPR(ctx context.Context, number int) (*PR, error)
// PRURL returns the web URL for a given PR number.
PRURL(number int) string
// FetchRef returns the git refspec to fetch a PR head.
// For GitHub: "pull/{n}/head:pr-{n}"
// For GitLab: "merge-requests/{n}/head:mr-{n}"
FetchRef(number int) string
// Name returns the forge name (e.g. "github", "gitlab").
Name() string
}
Forge abstracts GitHub/GitLab API interactions.
type Option ¶
type Option func(*options)
Option configures Detect behavior.
func WithTokenFunc ¶
WithTokenFunc overrides the default token retrieval for testing.
type PR ¶
type PR struct {
Number int `json:"number"`
Title string `json:"title"`
Branch string `json:"branch"`
Author string `json:"author"`
CreatedAt time.Time `json:"created_at"`
ReviewStatus ReviewStatus `json:"review_status"`
URL string `json:"url"`
IsDraft bool `json:"is_draft"`
State PRState `json:"state"`
}
PR represents a pull request or merge request.
type ReviewStatus ¶
type ReviewStatus string
ReviewStatus represents the review state of a PR.
const ( ReviewNone ReviewStatus = "" ReviewApproved ReviewStatus = "approved" ReviewChanges ReviewStatus = "changes_requested" ReviewPending ReviewStatus = "pending" )
Review status values for pull requests.