Skip to content

Commit 902b32f

Browse files
committed
wip: commit more progress on script
1 parent 20204b0 commit 902b32f

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module coder.com/static_terraform_registry
1+
module coder.com/readme-validation
22

33
go 1.23.2
44

5-
require sigs.k8s.io/yaml v1.4.0 // indirect
5+
require github.com/ghodss/yaml v1.0.0
6+
7+
require gopkg.in/yaml.v2 v2.4.0 // indirect
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1+
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
2+
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
3+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
24
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3-
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
4-
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
5+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
6+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

.github/scripts/readme-validation/main.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"sync"
1414

15-
"sigs.k8s.io/yaml"
15+
"github.com/ghodss/yaml"
1616
)
1717

1818
const rootRegistryPath = "./registry"
@@ -306,6 +306,11 @@ website:
306306
}
307307
}
308308

309+
// Avatar URL
310+
if yml.AvatarUrl != nil {
311+
312+
}
313+
309314
return errors
310315
}
311316

@@ -338,7 +343,12 @@ func remapContributorProfile(
338343
}
339344
if employeeGitHubNames != nil {
340345
remapped.EmployeeGithubUsernames = employeeGitHubNames[:]
341-
slices.Sort(remapped.EmployeeGithubUsernames)
346+
slices.SortFunc(
347+
remapped.EmployeeGithubUsernames,
348+
func(name1 string, name2 string) int {
349+
return strings.Compare(name1, name2)
350+
},
351+
)
342352
}
343353

344354
return remapped
@@ -447,18 +457,36 @@ func parseContributorFiles(input []directoryReadme) (
447457
}
448458

449459
func backfillAvatarUrls(contributors map[string]contributorProfile) error {
460+
if contributors == nil {
461+
return errors.New("provided map is nil")
462+
}
463+
450464
wg := sync.WaitGroup{}
451-
requestBuffer := make(chan struct{}, 10)
452465
errors := []error{}
466+
errorsMutex := sync.Mutex{}
467+
468+
// Todo: Add actual fetching logic once everything else has been verified
469+
requestAvatarUrl := func(string) (string, error) {
470+
return "", nil
471+
}
472+
473+
for ghUsername, conCopy := range contributors {
474+
if conCopy.AvatarUrl != "" {
475+
continue
476+
}
453477

454-
for _, c := range contributors {
455478
wg.Add(1)
456479
go func() {
457-
requestBuffer <- struct{}{}
458-
// Do request stuff
459-
460-
<-requestBuffer
461-
wg.Done()
480+
defer wg.Done()
481+
url, err := requestAvatarUrl(ghUsername)
482+
if err != nil {
483+
errorsMutex.Lock()
484+
errors = append(errors, err)
485+
errorsMutex.Unlock()
486+
return
487+
}
488+
conCopy.AvatarUrl = url
489+
contributors[ghUsername] = conCopy
462490
}()
463491
}
464492

@@ -481,12 +509,12 @@ func main() {
481509
if err != nil {
482510
log.Panic(err)
483511
}
512+
484513
allReadmeFiles := []directoryReadme{}
485514
fsErrors := workflowPhaseError{
486515
Phase: "FileSystem reading",
487516
Errors: []error{},
488517
}
489-
490518
for _, e := range dirEntries {
491519
dirPath := path.Join(rootRegistryPath, e.Name())
492520
if !e.IsDir() {

0 commit comments

Comments
 (0)