@@ -35,7 +35,7 @@ type contributorProfileReadme struct {
3535
3636func validateContributorDisplayName (displayName string ) error {
3737 if displayName == "" {
38- return fmt . Errorf ("missing display_name" )
38+ return errors . New ("missing display_name" )
3939 }
4040
4141 return nil
@@ -53,17 +53,16 @@ func validateContributorLinkedinURL(linkedinURL *string) error {
5353 return nil
5454}
5555
56+ // validateContributorSupportEmail does best effort validation of a contributors email address. We can't 100% validate
57+ // that this is correct without actually sending an email, especially because some contributors are individual developers
58+ // and we don't want to do that on every single run of the CI pipeline. The best we can do is verify the general structure.
5659func validateContributorSupportEmail (email * string ) []error {
5760 if email == nil {
5861 return nil
5962 }
6063
6164 errs := []error {}
6265
63- // Can't 100% validate that this is correct without actually sending
64- // an email, and especially with some contributors being individual
65- // developers, we don't want to do that on every single run of the CI
66- // pipeline. Best we can do is verify the general structure
6766 username , server , ok := strings .Cut (* email , "@" )
6867 if ! ok {
6968 errs = append (errs , fmt .Errorf ("email address %q is missing @ symbol" , * email ))
@@ -113,21 +112,18 @@ func validateContributorStatus(status string) error {
113112 return nil
114113}
115114
116- // Can't validate the image actually leads to a valid resource in a pure
117- // function, but can at least catch obvious problems
115+ // Can't validate the image actually leads to a valid resource in a pure function, but can at least catch obvious problems.
118116func validateContributorAvatarURL (avatarURL * string ) []error {
119117 if avatarURL == nil {
120118 return nil
121119 }
122120
123- errs := []error {}
124121 if * avatarURL == "" {
125- errs = append (errs , errors .New ("avatar URL must be omitted or non-empty string" ))
126- return errs
122+ return []error {errors .New ("avatar URL must be omitted or non-empty string" )}
127123 }
128124
129- // Have to use .Parse instead of .ParseRequestURI because this is the
130- // one field that's allowed to be a relative URL
125+ errs := [] error {}
126+ // Have to use .Parse instead of .ParseRequestURI because this is the one field that's allowed to be a relative URL.
131127 if _ , err := url .Parse (* avatarURL ); err != nil {
132128 errs = append (errs , fmt .Errorf ("URL %q is not a valid relative or absolute URL" , * avatarURL ))
133129 }
@@ -220,8 +216,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
220216
221217 yamlValidationErrors := []error {}
222218 for _ , p := range profilesByNamespace {
223- errors := validateContributorReadme (p )
224- if len (errors ) > 0 {
219+ if errors := validateContributorReadme (p ); len (errors ) > 0 {
225220 yamlValidationErrors = append (yamlValidationErrors , errors ... )
226221 continue
227222 }
@@ -245,11 +240,12 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
245240 allReadmeFiles := []readme {}
246241 errs := []error {}
247242 for _ , e := range dirEntries {
248- dirPath := path .Join (rootRegistryPath , e .Name ())
249243 if ! e .IsDir () {
250244 continue
251245 }
252246
247+ dirPath := path .Join (rootRegistryPath , e .Name ())
248+
253249 readmePath := path .Join (dirPath , "README.md" )
254250 rmBytes , err := os .ReadFile (readmePath )
255251 if err != nil {
@@ -273,20 +269,17 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
273269}
274270
275271func validateContributorRelativeUrls (contributors map [string ]contributorProfileReadme ) error {
276- // This function only validates relative avatar URLs for now, but it can be
277- // beefed up to validate more in the future
272+ // This function only validates relative avatar URLs for now, but it can be beefed up to validate more in the future.
278273 errs := []error {}
279274
280275 for _ , con := range contributors {
281- // If the avatar URL is missing, we'll just assume that the Registry
282- // site build step will take care of filling in the data properly
276+ // If the avatar URL is missing, we'll just assume that the Registry site build step will take care of filling
277+ // in the data properly.
283278 if con .frontmatter .AvatarURL == nil {
284279 continue
285280 }
286281
287- isRelativeURL := strings .HasPrefix (* con .frontmatter .AvatarURL , "." ) ||
288- strings .HasPrefix (* con .frontmatter .AvatarURL , "/" )
289- if ! isRelativeURL {
282+ if ! strings .HasPrefix (* con .frontmatter .AvatarURL , "." ) || ! strings .HasPrefix (* con .frontmatter .AvatarURL , "/" ) {
290283 continue
291284 }
292285
@@ -297,8 +290,7 @@ func validateContributorRelativeUrls(contributors map[string]contributorProfileR
297290
298291 absolutePath := strings .TrimSuffix (con .filePath , "README.md" ) +
299292 * con .frontmatter .AvatarURL
300- _ , err := os .ReadFile (absolutePath )
301- if err != nil {
293+ if _ , err := os .ReadFile (absolutePath ); err != nil {
302294 errs = append (errs , fmt .Errorf ("%q: relative avatar path %q does not point to image in file system" , con .filePath , * con .frontmatter .AvatarURL ))
303295 }
304296 }
@@ -325,8 +317,7 @@ func validateAllContributorFiles() error {
325317 }
326318 logger .Info (context .Background (), "Processed README files as valid contributor profiles" , "num_contributors" , len (contributors ))
327319
328- err = validateContributorRelativeUrls (contributors )
329- if err != nil {
320+ if err = validateContributorRelativeUrls (contributors ); err != nil {
330321 return err
331322 }
332323 logger .Info (context .Background (), "All relative URLs for READMEs are valid" )
0 commit comments