From 629f4b3a651fc8a03b3cdb99ac0f0e17bc54e98a Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 8 Apr 2025 18:53:44 +0000 Subject: [PATCH] chore: rename directory for script --- .../go.mod | 0 .../go.sum | 0 .../main.go | 88 ++----------------- 3 files changed, 5 insertions(+), 83 deletions(-) rename .github/scripts/{readme-validation => validate-contributor-readmes}/go.mod (100%) rename .github/scripts/{readme-validation => validate-contributor-readmes}/go.sum (100%) rename .github/scripts/{readme-validation => validate-contributor-readmes}/main.go (84%) diff --git a/.github/scripts/readme-validation/go.mod b/.github/scripts/validate-contributor-readmes/go.mod similarity index 100% rename from .github/scripts/readme-validation/go.mod rename to .github/scripts/validate-contributor-readmes/go.mod diff --git a/.github/scripts/readme-validation/go.sum b/.github/scripts/validate-contributor-readmes/go.sum similarity index 100% rename from .github/scripts/readme-validation/go.sum rename to .github/scripts/validate-contributor-readmes/go.sum diff --git a/.github/scripts/readme-validation/main.go b/.github/scripts/validate-contributor-readmes/main.go similarity index 84% rename from .github/scripts/readme-validation/main.go rename to .github/scripts/validate-contributor-readmes/main.go index c942be6b..59d73259 100644 --- a/.github/scripts/readme-validation/main.go +++ b/.github/scripts/validate-contributor-readmes/main.go @@ -10,7 +10,6 @@ import ( "path" "slices" "strings" - "sync" "gopkg.in/yaml.v3" ) @@ -66,7 +65,7 @@ type contributorProfile struct { GithubUsername string DisplayName string Bio string - AvatarUrl string + AvatarUrl *string WebsiteURL *string LinkedinURL *string SupportEmail *string @@ -329,8 +328,9 @@ func remapContributorProfile( frontmatter contributorFrontmatterWithFilepath, employeeGitHubNames []string, ) contributorProfile { - // Function assumes that fields are previously validated and are safe to - // copy over verbatim when appropriate + // Function assumes that (1) fields are previously validated and are safe to + // copy over verbatim when appropriate, and (2) any missing avatar URLs will + // be backfilled during the main Registry site build step remapped := contributorProfile{ DisplayName: frontmatter.DisplayName, GithubUsername: frontmatter.GithubUsername, @@ -338,11 +338,9 @@ func remapContributorProfile( LinkedinURL: frontmatter.LinkedinURL, SupportEmail: frontmatter.SupportEmail, WebsiteURL: frontmatter.WebsiteURL, + AvatarUrl: frontmatter.AvatarUrl, } - if frontmatter.AvatarUrl != nil { - remapped.AvatarUrl = *frontmatter.AvatarUrl - } if frontmatter.ContributorStatus != nil { switch *frontmatter.ContributorStatus { case "partner": @@ -472,68 +470,6 @@ func parseContributorFiles(readmeEntries []directoryReadme) ( return structured, nil } -// backfillAvatarUrls takes a map of contributor information, each keyed by -// GitHub username, and tries to mutate each entry to fill in its missing avatar -// URL. The first integer indicates the number of avatars that needed to be -// backfilled, while the second indicates the number that could be backfilled -// without any errors. -// -// The function will collect all request errors, rather than return the first -// one found. -func backfillAvatarUrls(contributors map[string]contributorProfile) (int, int, error) { - if contributors == nil { - return 0, 0, errors.New("provided map is nil") - } - - wg := sync.WaitGroup{} - mtx := sync.Mutex{} - errors := []error{} - successfulBackfills := 0 - - // Todo: Add actual fetching logic once everything else has been verified - requestAvatarUrl := func(string) (string, error) { - return "", nil - } - - avatarsThatNeedBackfill := 0 - for ghUsername, con := range contributors { - if con.AvatarUrl != "" { - continue - } - - avatarsThatNeedBackfill++ - wg.Add(1) - go func() { - defer wg.Done() - url, err := requestAvatarUrl(ghUsername) - mtx.Lock() - defer mtx.Unlock() - - if err != nil { - errors = append(errors, err) - return - } - - successfulBackfills++ - con.AvatarUrl = url + "Not implemented yet" - contributors[ghUsername] = con - }() - } - - wg.Wait() - if len(errors) == 0 { - return avatarsThatNeedBackfill, successfulBackfills, nil - } - - slices.SortFunc(errors, func(e1 error, e2 error) int { - return strings.Compare(e1.Error(), e2.Error()) - }) - return avatarsThatNeedBackfill, successfulBackfills, workflowPhaseError{ - Phase: "Avatar Backfill", - Errors: errors, - } -} - func main() { log.Println("Starting README validation") dirEntries, err := os.ReadDir(rootRegistryPath) @@ -585,20 +521,6 @@ func main() { len(contributors), ) - backfillsNeeded, successCount, err := backfillAvatarUrls(contributors) - if err != nil { - log.Panic(err) - } - if backfillsNeeded == 0 { - log.Println("No GitHub avatar backfills needed") - } else { - log.Printf( - "Backfilled %d/%d missing GitHub avatars", - backfillsNeeded, - successCount, - ) - } - log.Printf( "Processed all READMEs in the %q directory\n", rootRegistryPath,