@@ -15,7 +15,7 @@ import (
15
15
"github.com/ghodss/yaml"
16
16
)
17
17
18
- const rootRegistryPath = "./registry"
18
+ const rootRegistryPath = "../../.. /registry"
19
19
20
20
type directoryReadme struct {
21
21
FilePath string
@@ -70,7 +70,7 @@ type workflowPhaseError struct {
70
70
}
71
71
72
72
func (wpe workflowPhaseError ) Error () string {
73
- msg := fmt .Sprintf ("Error during phase %q of README validation:" , wpe .Phase )
73
+ msg := fmt .Sprintf ("Error during %q phase of README validation:" , wpe .Phase )
74
74
for _ , e := range wpe .Errors {
75
75
msg += fmt .Sprintf ("\n - %v" , e )
76
76
}
@@ -456,59 +456,75 @@ func parseContributorFiles(input []directoryReadme) (
456
456
return structured , nil
457
457
}
458
458
459
- func backfillAvatarUrls (contributors map [string ]contributorProfile ) error {
459
+ // backfillAvatarUrls takes a map of contributor information, each keyed by
460
+ // GitHub username, and tries to mutate each entry to fill in its missing avatar
461
+ // URL. The first integer indicates the number of avatars that needed to be
462
+ // backfilled, while the second indicates the number that could be backfilled
463
+ // without any errors.
464
+ //
465
+ // The function will collect all request errors, rather than return the first
466
+ // one found.
467
+ func backfillAvatarUrls (contributors map [string ]contributorProfile ) (int , int , error ) {
460
468
if contributors == nil {
461
- return errors .New ("provided map is nil" )
469
+ return 0 , 0 , errors .New ("provided map is nil" )
462
470
}
463
471
464
472
wg := sync.WaitGroup {}
473
+ mtx := sync.Mutex {}
465
474
errors := []error {}
466
- errorsMutex := sync. Mutex {}
475
+ successfulBackfills := 0
467
476
468
477
// Todo: Add actual fetching logic once everything else has been verified
469
478
requestAvatarUrl := func (string ) (string , error ) {
470
479
return "" , nil
471
480
}
472
481
473
- for ghUsername , conCopy := range contributors {
474
- if conCopy .AvatarUrl != "" {
482
+ avatarsThatNeedBackfill := 0
483
+ for ghUsername , con := range contributors {
484
+ if con .AvatarUrl != "" {
475
485
continue
476
486
}
477
487
488
+ avatarsThatNeedBackfill ++
478
489
wg .Add (1 )
479
490
go func () {
480
491
defer wg .Done ()
481
492
url , err := requestAvatarUrl (ghUsername )
493
+ mtx .Lock ()
494
+ defer mtx .Unlock ()
495
+
482
496
if err != nil {
483
- errorsMutex .Lock ()
484
497
errors = append (errors , err )
485
- errorsMutex .Unlock ()
486
498
return
487
499
}
488
- conCopy .AvatarUrl = url
489
- contributors [ghUsername ] = conCopy
500
+
501
+ successfulBackfills ++
502
+ con .AvatarUrl = url
503
+ contributors [ghUsername ] = con
490
504
}()
491
505
}
492
506
493
507
wg .Wait ()
494
508
if len (errors ) == 0 {
495
- return nil
509
+ return avatarsThatNeedBackfill , successfulBackfills , nil
496
510
}
497
511
498
512
slices .SortFunc (errors , func (e1 error , e2 error ) int {
499
513
return strings .Compare (e1 .Error (), e2 .Error ())
500
514
})
501
- return workflowPhaseError {
515
+ return avatarsThatNeedBackfill , successfulBackfills , workflowPhaseError {
502
516
Phase : "Avatar Backfill" ,
503
517
Errors : errors ,
504
518
}
505
519
}
506
520
507
521
func main () {
522
+ log .Println ("Starting README validation" )
508
523
dirEntries , err := os .ReadDir (rootRegistryPath )
509
524
if err != nil {
510
525
log .Panic (err )
511
526
}
527
+ log .Printf ("Identified %d top-level directory entries\n " , len (dirEntries ))
512
528
513
529
allReadmeFiles := []directoryReadme {}
514
530
fsErrors := workflowPhaseError {
@@ -543,14 +559,29 @@ func main() {
543
559
log .Panic (fsErrors )
544
560
}
545
561
562
+ log .Printf ("Processing %d README files\n " , len (allReadmeFiles ))
546
563
contributors , err := parseContributorFiles (allReadmeFiles )
547
564
if err != nil {
548
565
log .Panic (err )
549
566
}
550
- err = backfillAvatarUrls (contributors )
567
+ log .Printf (
568
+ "Processed %d README files as valid contributor profiles" ,
569
+ len (contributors ),
570
+ )
571
+
572
+ backfillsNeeded , successCount , err := backfillAvatarUrls (contributors )
551
573
if err != nil {
552
574
log .Panic (err )
553
575
}
576
+ if backfillsNeeded == 0 {
577
+ log .Println ("No GitHub avatar backfills needed" )
578
+ } else {
579
+ log .Printf (
580
+ "Backfilled %d/%d missing GitHub avatars" ,
581
+ backfillsNeeded ,
582
+ successCount ,
583
+ )
584
+ }
554
585
555
586
log .Printf (
556
587
"Processed all READMEs in the %q directory\n " ,
0 commit comments