@@ -84,6 +84,7 @@ type Label struct {
84
84
// There is also a Default list of labels applied to every Repo
85
85
type Configuration struct {
86
86
Repos map [string ]RepoConfig `json:"repos,omitempty"`
87
+ Orgs map [string ]RepoConfig `json:"orgs,omitempty"`
87
88
Default RepoConfig `json:"default"`
88
89
}
89
90
@@ -239,6 +240,9 @@ func stringInSortedSlice(a string, list []string) bool {
239
240
func (c Configuration ) Labels () []Label {
240
241
var labelarrays [][]Label
241
242
labelarrays = append (labelarrays , c .Default .Labels )
243
+ for _ , org := range c .Orgs {
244
+ labelarrays = append (labelarrays , org .Labels )
245
+ }
242
246
for _ , repo := range c .Repos {
243
247
labelarrays = append (labelarrays , repo .Labels )
244
248
}
@@ -265,29 +269,42 @@ func (c Configuration) Labels() []Label {
265
269
// Ensures the config does not duplicate label names between default and repo
266
270
func (c Configuration ) validate (orgs string ) error {
267
271
// Check default labels
268
- seen , err := validate (c .Default .Labels , "default" , make (map [string ]string ))
272
+ defaultSeen , err := validate (c .Default .Labels , "default" , make (map [string ]string ))
269
273
if err != nil {
270
274
return fmt .Errorf ("invalid config: %v" , err )
271
275
}
272
276
273
277
// Generate list of orgs
274
278
sortedOrgs := strings .Split (orgs , "," )
275
279
sort .Strings (sortedOrgs )
276
- // Check other repos labels
280
+
281
+ // Check org-level labels for duplicities with default labels
282
+ orgSeen := map [string ]map [string ]string {}
283
+ for org , orgConfig := range c .Orgs {
284
+ if orgSeen [org ], err = validate (orgConfig .Labels , org , defaultSeen ); err != nil {
285
+ return fmt .Errorf ("invalid config: %v" , err )
286
+ }
287
+ }
288
+
277
289
for repo , repoconfig := range c .Repos {
278
- // Will complain if a label is both in default and repo
279
- if _ , err := validate (repoconfig .Labels , repo , seen ); err != nil {
290
+ data := strings .Split (repo , "/" )
291
+ if len (data ) != 2 {
292
+ return fmt .Errorf ("invalid repo name '%s', expected org/repo form" , repo )
293
+ }
294
+ org := data [0 ]
295
+ if _ , ok := orgSeen [org ]; ! ok {
296
+ orgSeen [org ] = defaultSeen
297
+ }
298
+
299
+ // Check repo labels for duplicities with default and org-level labels
300
+ if _ , err := validate (repoconfig .Labels , repo , orgSeen [org ]); err != nil {
280
301
return fmt .Errorf ("invalid config: %v" , err )
281
302
}
282
303
// If orgs have been specified, warn if repo isn't under orgs
283
- if len (orgs ) != 0 {
284
- data := strings .Split (repo , "/" )
285
- if len (data ) == 2 {
286
- if ! stringInSortedSlice (data [0 ], sortedOrgs ) {
287
- logrus .WithField ("orgs" , orgs ).WithField ("org" , data [0 ]).WithField ("repo" , repo ).Warn ("Repo isn't inside orgs" )
288
- }
289
- }
304
+ if len (orgs ) > 0 && ! stringInSortedSlice (org , sortedOrgs ) {
305
+ logrus .WithField ("orgs" , orgs ).WithField ("org" , org ).WithField ("repo" , repo ).Warn ("Repo isn't inside orgs" )
290
306
}
307
+
291
308
}
292
309
return nil
293
310
}
@@ -472,6 +489,9 @@ func copyLabelMap(originalMap map[string]Label) map[string]Label {
472
489
func syncLabels (config Configuration , org string , repos RepoLabels ) (RepoUpdates , error ) {
473
490
// Find required, dead and archaic labels
474
491
defaultRequired , defaultArchaic , defaultDead := classifyLabels (config .Default .Labels , make (map [string ]Label ), make (map [string ]Label ), make (map [string ]Label ), time .Now (), nil )
492
+ if orgLabels , ok := config .Orgs [org ]; ok {
493
+ defaultRequired , defaultArchaic , defaultDead = classifyLabels (orgLabels .Labels , defaultRequired , defaultArchaic , defaultDead , time .Now (), nil )
494
+ }
475
495
476
496
var validationErrors []error
477
497
var actions []Update
@@ -811,8 +831,31 @@ func writeDocs(template string, output string, config Configuration) error {
811
831
data = append (data , labelData {desc , linkify (desc ), LabelsForTarget (config .Default .Labels , issueTarget )})
812
832
desc = "all repos, only for PRs"
813
833
data = append (data , labelData {desc , linkify (desc ), LabelsForTarget (config .Default .Labels , prTarget )})
834
+ // Let's sort orgs
835
+ var orgs []string
836
+ for org := range config .Orgs {
837
+ orgs = append (orgs , org )
838
+ }
839
+ sort .Strings (orgs )
840
+ // And append their labels
841
+ for _ , org := range orgs {
842
+ lead := fmt .Sprintf ("all repos in %s" , org )
843
+ if l := LabelsForTarget (config .Orgs [org ].Labels , bothTarget ); len (l ) > 0 {
844
+ desc = lead + ", for both issues and PRs"
845
+ data = append (data , labelData {desc , linkify (desc ), l })
846
+ }
847
+ if l := LabelsForTarget (config .Orgs [org ].Labels , issueTarget ); len (l ) > 0 {
848
+ desc = lead + ", only for issues"
849
+ data = append (data , labelData {desc , linkify (desc ), l })
850
+ }
851
+ if l := LabelsForTarget (config .Orgs [org ].Labels , prTarget ); len (l ) > 0 {
852
+ desc = lead + ", only for PRs"
853
+ data = append (data , labelData {desc , linkify (desc ), l })
854
+ }
855
+ }
856
+
814
857
// Let's sort repos
815
- repos := make ( []string , 0 )
858
+ var repos []string
816
859
for repo := range config .Repos {
817
860
repos = append (repos , repo )
818
861
}
0 commit comments