@@ -49,10 +49,11 @@ type Rule struct {
4949}
5050
5151type 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"`
5657}
5758
5859func loadConfigFromURL (url string ) (* LabelsYAML , error ) {
@@ -119,6 +120,16 @@ func main() {
119120 deleteUndefinedLabels (ctx , client , owner , repo , cfg )
120121 }
121122
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+
122133 // Parse changed files if provided
123134 var files []string
124135 if * changedFiles != "" {
@@ -276,6 +287,10 @@ func getLabelDefinition(cfg *LabelsYAML, labelName string) (string, string, stri
276287 }
277288 }
278289 }
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+ }
279294 return "000000" , "Automatically applied label" , labelName // Default values
280295}
281296
@@ -285,6 +300,12 @@ func applyLabel(ctx context.Context, client *github.Client, owner, repo string,
285300 // Get label definition from config
286301 color , description , resolvedLabel := getLabelDefinition (cfg , label )
287302
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+
288309 // Ensure the label exists with the defined color and description
289310 if err := ensureLabelExists (ctx , client , owner , repo , resolvedLabel , color , description , cfg ); err != nil {
290311 log .Printf ("skipping label %s due to error: %v" , resolvedLabel , err )
0 commit comments