Skip to content

Commit da7e920

Browse files
committed
code cleanup
1 parent 062e803 commit da7e920

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

main.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -559,30 +559,25 @@ func enrichPRsParallel(ctx context.Context, prs []PR, cfg *enrichConfig) {
559559
wg.Wait()
560560
}
561561

562-
func fetchPRDetails(ctx context.Context, pr *PR, token string, httpClient *http.Client, logger *log.Logger, debug bool) error {
563-
// Extract repository info from PR URL
564-
// URL format: https://github.com/owner/repo/pull/123
562+
func fetchPRDetails(ctx context.Context, pr *PR, cfg *enrichConfig) error {
565563
parts := strings.Split(pr.HTMLURL, "/")
566564
if len(parts) < minPRURLParts {
567565
return fmt.Errorf("invalid PR URL format: %s", pr.HTMLURL)
568566
}
569567
owner := parts[3]
570568
repo := parts[repoPartIndex]
571569

572-
// Build API URL
573570
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/%s/pulls/%d", owner, repo, pr.Number)
574571

575-
// Create request
576572
req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, http.NoBody)
577573
if err != nil {
578574
return err
579575
}
580576

581-
req.Header.Set("Authorization", "token "+token)
577+
req.Header.Set("Authorization", "token "+cfg.token)
582578
req.Header.Set("Accept", "application/vnd.github.v3+json")
583579

584-
// Make request
585-
resp, err := httpClient.Do(req)
580+
resp, err := cfg.httpClient.Do(req)
586581
if err != nil {
587582
return err
588583
}
@@ -592,19 +587,17 @@ func fetchPRDetails(ctx context.Context, pr *PR, token string, httpClient *http.
592587
return fmt.Errorf("GitHub API returned status %d", resp.StatusCode)
593588
}
594589

595-
// Parse response
596590
var prDetails PR
597591
if err := json.NewDecoder(resp.Body).Decode(&prDetails); err != nil {
598592
return err
599593
}
600594

601-
// Update PR with size information
602595
pr.Additions = prDetails.Additions
603596
pr.Deletions = prDetails.Deletions
604597
pr.ChangedFiles = prDetails.ChangedFiles
605598

606-
if debug {
607-
logger.Printf("Fetched PR #%d size: +%d/-%d files:%d", pr.Number, pr.Additions, pr.Deletions, pr.ChangedFiles)
599+
if cfg.debug {
600+
cfg.logger.Printf("Fetched PR #%d size: +%d/-%d files:%d", pr.Number, pr.Additions, pr.Deletions, pr.ChangedFiles)
608601
}
609602

610603
return nil
@@ -619,7 +612,7 @@ func enrichPRData(ctx context.Context, pr *PR, cfg *enrichConfig) error {
619612
}()
620613

621614
// Fetch individual PR data to get size information
622-
if err := fetchPRDetails(ctx, pr, cfg.token, cfg.httpClient, cfg.logger, cfg.debug); err != nil {
615+
if err := fetchPRDetails(ctx, pr, cfg); err != nil {
623616
cfg.logger.Printf("WARNING: Failed to fetch PR details for #%d: %v", pr.Number, err)
624617
// Continue without size info
625618
}
@@ -631,9 +624,6 @@ func enrichPRData(ctx context.Context, pr *PR, cfg *enrichConfig) error {
631624
}
632625
return nil
633626
}
634-
if cfg.debug {
635-
cfg.logger.Printf("Calling enrichWithTurnData for PR #%d", pr.Number)
636-
}
637627
return enrichWithTurnData(ctx, pr, cfg)
638628
}
639629

@@ -663,11 +653,11 @@ func enrichWithTurnData(ctx context.Context, pr *PR, cfg *enrichConfig) error {
663653
cfg.logger.Printf("INFO: Cache miss for PR #%d", pr.Number)
664654
}
665655
} else if cfg.debug {
656+
msg := "Cache unavailable"
666657
if cfg.noCache {
667-
cfg.logger.Printf("INFO: Cache disabled (--no-cache) for PR #%d", pr.Number)
668-
} else {
669-
cfg.logger.Printf("INFO: Cache unavailable for PR #%d", pr.Number)
658+
msg = "Cache disabled (--no-cache)"
670659
}
660+
cfg.logger.Printf("INFO: %s for PR #%d", msg, pr.Number)
671661
}
672662

673663
return fetchAndCacheTurnData(ctx, pr, cacheKey, cfg)

0 commit comments

Comments
 (0)