mirror of
https://github.com/lukaszraczylo/git-velocity.git
synced 2026-06-05 22:43:56 +00:00
Update + signing of the binaries
This commit is contained in:
@@ -204,121 +204,3 @@ func (f *DateFilteredFetcher[T, R]) ShouldSkip(item T) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// WithRetry wraps a fetch function with retry logic
|
||||
func (c *Client) WithRetry(ctx context.Context, operation string, fn func() error) error {
|
||||
return c.retryWithBackoff(ctx, operation, fn)
|
||||
}
|
||||
|
||||
// EnrichingFetcher extends DateFilteredFetcher with per-item enrichment
|
||||
// This is useful when you need to fetch additional details for each item (e.g., commit details)
|
||||
type EnrichingFetcher[T any, R any] struct {
|
||||
FetchFn func(ctx context.Context, page int) ([]T, *github.Response, error)
|
||||
EnrichFn func(ctx context.Context, item T) (R, error) // Enriches and converts in one step
|
||||
GetDateFn func(item T) time.Time
|
||||
SkipFn func(item T) bool
|
||||
Since *time.Time
|
||||
Until *time.Time
|
||||
}
|
||||
|
||||
func (f *EnrichingFetcher[T, R]) Fetch(ctx context.Context, page int) ([]T, *github.Response, error) {
|
||||
return f.FetchFn(ctx, page)
|
||||
}
|
||||
|
||||
func (f *EnrichingFetcher[T, R]) Convert(item T) R {
|
||||
// This won't be used - FetchAllPagesWithEnrichment handles enrichment
|
||||
var zero R
|
||||
return zero
|
||||
}
|
||||
|
||||
func (f *EnrichingFetcher[T, R]) Filter(item T) DateFilterResult {
|
||||
return FilterByDate(f.GetDateFn(item), f.Since, f.Until)
|
||||
}
|
||||
|
||||
func (f *EnrichingFetcher[T, R]) ShouldSkip(item T) bool {
|
||||
if f.SkipFn != nil {
|
||||
return f.SkipFn(item)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FetchAllPagesWithEnrichment is like FetchAllPages but calls EnrichFn for each item
|
||||
// This is useful when you need to make additional API calls per item (e.g., fetching commit details)
|
||||
func FetchAllPagesWithEnrichment[T any, R any](
|
||||
ctx context.Context,
|
||||
c *Client,
|
||||
cacheKey string,
|
||||
config FetchConfig,
|
||||
fetcher *EnrichingFetcher[T, R],
|
||||
progressEvery int, // Report progress every N items (0 = disabled)
|
||||
) ([]R, error) {
|
||||
// Check cache first
|
||||
if cacheKey != "" {
|
||||
if cached, ok := c.cache.Get(cacheKey); ok {
|
||||
if results, ok := cached.([]R); ok {
|
||||
c.progress(fmt.Sprintf(" Using cached %s data", config.ResourceName))
|
||||
return results, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var allResults []R
|
||||
page := 1
|
||||
|
||||
for {
|
||||
items, resp, err := fetcher.Fetch(ctx, page)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch %s: %w", config.ResourceName, err)
|
||||
}
|
||||
|
||||
// Safety check for nil response
|
||||
if resp == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if !config.Quiet {
|
||||
c.progress(fmt.Sprintf(" Fetching %s page %d (%d %s so far)...",
|
||||
config.ResourceName, page, len(allResults), config.ResourceName))
|
||||
}
|
||||
|
||||
itemsInPage := 0
|
||||
for i, item := range items {
|
||||
// Skip items that should be filtered out entirely
|
||||
if fetcher.ShouldSkip(item) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Apply date filtering
|
||||
if fetcher.Filter(item) != DateInclude {
|
||||
continue
|
||||
}
|
||||
|
||||
// Enrich the item (this may make additional API calls)
|
||||
enriched, err := fetcher.EnrichFn(ctx, item)
|
||||
if err != nil {
|
||||
c.progress(fmt.Sprintf(" Warning: failed to enrich item: %v", err))
|
||||
continue
|
||||
}
|
||||
|
||||
allResults = append(allResults, enriched)
|
||||
itemsInPage++
|
||||
|
||||
// Progress reporting
|
||||
if progressEvery > 0 && (i+1)%progressEvery == 0 {
|
||||
c.progress(fmt.Sprintf(" Processing item %d/%d on page %d...", i+1, len(items), page))
|
||||
}
|
||||
}
|
||||
|
||||
if resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
// Cache results
|
||||
if cacheKey != "" {
|
||||
c.cache.Set(cacheKey, allResults)
|
||||
}
|
||||
|
||||
return allResults, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user