@@ -49,10 +49,11 @@ type Rule struct {
49
49
}
50
50
51
51
type LabelsYAML struct {
52
- Labels []Label `yaml:"labels"`
53
- Ruleset []Rule `yaml:"ruleset"`
54
- AutoCreate bool `yaml:"autoCreateLabels"`
55
- AutoDelete bool `yaml:"autoDeleteLabels"`
52
+ Labels []Label `yaml:"labels"`
53
+ Ruleset []Rule `yaml:"ruleset"`
54
+ AutoCreate bool `yaml:"autoCreateLabels"`
55
+ AutoDelete bool `yaml:"autoDeleteLabels"`
56
+ DefinedRequired bool `yaml:"definedRequired"`
56
57
}
57
58
58
59
func loadConfigFromURL (url string ) (* LabelsYAML , error ) {
@@ -119,6 +120,16 @@ func main() {
119
120
deleteUndefinedLabels (ctx , client , owner , repo , cfg )
120
121
}
121
122
123
+ if cfg .AutoCreate {
124
+ for _ , label := range cfg .Labels {
125
+ color , description , labelName := getLabelDefinition (cfg , label .Name )
126
+ if err := ensureLabelExists (ctx , client , owner , repo , labelName , color , description , cfg ); err != nil {
127
+ log .Printf ("skipping label %s due to error: %v" , labelName , err )
128
+ continue
129
+ }
130
+ }
131
+ }
132
+
122
133
// Parse changed files if provided
123
134
var files []string
124
135
if * changedFiles != "" {
@@ -276,6 +287,10 @@ func getLabelDefinition(cfg *LabelsYAML, labelName string) (string, string, stri
276
287
}
277
288
}
278
289
}
290
+ if cfg .DefinedRequired {
291
+ log .Printf ("label %s not defined in labels.yaml" , labelName )
292
+ return "" , "" , "" // Return empty if label is required but not defined
293
+ }
279
294
return "000000" , "Automatically applied label" , labelName // Default values
280
295
}
281
296
@@ -285,6 +300,12 @@ func applyLabel(ctx context.Context, client *github.Client, owner, repo string,
285
300
// Get label definition from config
286
301
color , description , resolvedLabel := getLabelDefinition (cfg , label )
287
302
303
+ if resolvedLabel == "" {
304
+ log .Printf ("label %s is not defined in labels.yaml and auto-create is disabled" ,
305
+ label )
306
+ return
307
+ }
308
+
288
309
// Ensure the label exists with the defined color and description
289
310
if err := ensureLabelExists (ctx , client , owner , repo , resolvedLabel , color , description , cfg ); err != nil {
290
311
log .Printf ("skipping label %s due to error: %v" , resolvedLabel , err )
0 commit comments