diff --git a/.github/scripts/readme-validation/go.mod b/.github/scripts/readme-validation/go.mod index 32d1940a..a6fe657f 100644 --- a/.github/scripts/readme-validation/go.mod +++ b/.github/scripts/readme-validation/go.mod @@ -1,5 +1,7 @@ -module coder.com/static_terraform_registry +module coder.com/readme-validation go 1.23.2 -require sigs.k8s.io/yaml v1.4.0 // indirect +require github.com/ghodss/yaml v1.0.0 + +require gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/.github/scripts/readme-validation/go.sum b/.github/scripts/readme-validation/go.sum index 8c724249..0f65cfd9 100644 --- a/.github/scripts/readme-validation/go.sum +++ b/.github/scripts/readme-validation/go.sum @@ -1,4 +1,6 @@ -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= -sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/.github/scripts/readme-validation/main.go b/.github/scripts/readme-validation/main.go index 775a32a6..8c0ae833 100644 --- a/.github/scripts/readme-validation/main.go +++ b/.github/scripts/readme-validation/main.go @@ -12,7 +12,7 @@ import ( "strings" "sync" - "sigs.k8s.io/yaml" + "github.com/ghodss/yaml" ) const rootRegistryPath = "./registry" @@ -306,6 +306,11 @@ website: } } + // Avatar URL + if yml.AvatarUrl != nil { + + } + return errors } @@ -338,7 +343,12 @@ func remapContributorProfile( } if employeeGitHubNames != nil { remapped.EmployeeGithubUsernames = employeeGitHubNames[:] - slices.Sort(remapped.EmployeeGithubUsernames) + slices.SortFunc( + remapped.EmployeeGithubUsernames, + func(name1 string, name2 string) int { + return strings.Compare(name1, name2) + }, + ) } return remapped @@ -447,18 +457,36 @@ func parseContributorFiles(input []directoryReadme) ( } func backfillAvatarUrls(contributors map[string]contributorProfile) error { - wg := sync.WaitGroup{} - requestBuffer := make(chan struct{}, 10) - errors := []error{} + if contributors == nil { + return errors.New("provided map is nil") + } + + wg := sync.WaitGroup{} + errors := []error{} + errorsMutex := sync.Mutex{} + + // Todo: Add actual fetching logic once everything else has been verified + requestAvatarUrl := func(string) (string, error) { + return "", nil + } + + for ghUsername, conCopy := range contributors { + if conCopy.AvatarUrl != "" { + continue + } - for _, c := range contributors { wg.Add(1) go func() { - requestBuffer <- struct{}{} - // Do request stuff - - <-requestBuffer - wg.Done() + defer wg.Done() + url, err := requestAvatarUrl(ghUsername) + if err != nil { + errorsMutex.Lock() + errors = append(errors, err) + errorsMutex.Unlock() + return + } + conCopy.AvatarUrl = url + contributors[ghUsername] = conCopy }() } @@ -481,12 +509,12 @@ func main() { if err != nil { log.Panic(err) } + allReadmeFiles := []directoryReadme{} fsErrors := workflowPhaseError{ Phase: "FileSystem reading", Errors: []error{}, } - for _, e := range dirEntries { dirPath := path.Join(rootRegistryPath, e.Name()) if !e.IsDir() {