@@ -35,7 +35,7 @@ type contributorProfileReadme struct {
35
35
36
36
func validateContributorDisplayName (displayName string ) error {
37
37
if displayName == "" {
38
- return fmt . Errorf ("missing display_name" )
38
+ return errors . New ("missing display_name" )
39
39
}
40
40
41
41
return nil
@@ -53,17 +53,16 @@ func validateContributorLinkedinURL(linkedinURL *string) error {
53
53
return nil
54
54
}
55
55
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.
56
59
func validateContributorSupportEmail (email * string ) []error {
57
60
if email == nil {
58
61
return nil
59
62
}
60
63
61
64
errs := []error {}
62
65
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
67
66
username , server , ok := strings .Cut (* email , "@" )
68
67
if ! ok {
69
68
errs = append (errs , fmt .Errorf ("email address %q is missing @ symbol" , * email ))
@@ -113,21 +112,18 @@ func validateContributorStatus(status string) error {
113
112
return nil
114
113
}
115
114
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.
118
116
func validateContributorAvatarURL (avatarURL * string ) []error {
119
117
if avatarURL == nil {
120
118
return nil
121
119
}
122
120
123
- errs := []error {}
124
121
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" )}
127
123
}
128
124
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.
131
127
if _ , err := url .Parse (* avatarURL ); err != nil {
132
128
errs = append (errs , fmt .Errorf ("URL %q is not a valid relative or absolute URL" , * avatarURL ))
133
129
}
@@ -220,8 +216,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
220
216
221
217
yamlValidationErrors := []error {}
222
218
for _ , p := range profilesByNamespace {
223
- errors := validateContributorReadme (p )
224
- if len (errors ) > 0 {
219
+ if errors := validateContributorReadme (p ); len (errors ) > 0 {
225
220
yamlValidationErrors = append (yamlValidationErrors , errors ... )
226
221
continue
227
222
}
@@ -245,11 +240,12 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
245
240
allReadmeFiles := []readme {}
246
241
errs := []error {}
247
242
for _ , e := range dirEntries {
248
- dirPath := path .Join (rootRegistryPath , e .Name ())
249
243
if ! e .IsDir () {
250
244
continue
251
245
}
252
246
247
+ dirPath := path .Join (rootRegistryPath , e .Name ())
248
+
253
249
readmePath := path .Join (dirPath , "README.md" )
254
250
rmBytes , err := os .ReadFile (readmePath )
255
251
if err != nil {
@@ -273,20 +269,17 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
273
269
}
274
270
275
271
func 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.
278
273
errs := []error {}
279
274
280
275
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.
283
278
if con .frontmatter .AvatarURL == nil {
284
279
continue
285
280
}
286
281
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 , "/" ) {
290
283
continue
291
284
}
292
285
@@ -297,8 +290,7 @@ func validateContributorRelativeUrls(contributors map[string]contributorProfileR
297
290
298
291
absolutePath := strings .TrimSuffix (con .filePath , "README.md" ) +
299
292
* con .frontmatter .AvatarURL
300
- _ , err := os .ReadFile (absolutePath )
301
- if err != nil {
293
+ if _ , err := os .ReadFile (absolutePath ); err != nil {
302
294
errs = append (errs , fmt .Errorf ("%q: relative avatar path %q does not point to image in file system" , con .filePath , * con .frontmatter .AvatarURL ))
303
295
}
304
296
}
@@ -325,8 +317,7 @@ func validateAllContributorFiles() error {
325
317
}
326
318
logger .Info (context .Background (), "Processed README files as valid contributor profiles" , "num_contributors" , len (contributors ))
327
319
328
- err = validateContributorRelativeUrls (contributors )
329
- if err != nil {
320
+ if err = validateContributorRelativeUrls (contributors ); err != nil {
330
321
return err
331
322
}
332
323
logger .Info (context .Background (), "All relative URLs for READMEs are valid" )
0 commit comments