@@ -269,56 +269,105 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) {
269269 }
270270 return res , nil
271271 case yaml .MappingNode :
272- events , triggers , err := parseMappingNode [interface {} ](rawOn )
272+ events , triggers , err := parseMappingNode [yaml. Node ](rawOn )
273273 if err != nil {
274274 return nil , err
275275 }
276276 res := make ([]* Event , 0 , len (events ))
277277 for i , k := range events {
278278 v := triggers [i ]
279- if v == nil {
279+ switch v .Kind {
280+ case yaml .ScalarNode :
280281 res = append (res , & Event {
281282 Name : k ,
282283 })
283- continue
284- }
285- switch t := v .(type ) {
286- case string :
287- res = append (res , & Event {
288- Name : k ,
289- })
290- case []string :
291- res = append (res , & Event {
292- Name : k ,
293- })
294- case map [string ]interface {}:
295- acts := make (map [string ][]string , len (t ))
296- var inputs []WorkflowDispatchInput
297- for act , branches := range t {
298- switch b := branches .(type ) {
299- case string :
300- acts [act ] = []string {b }
301- case []string :
302- acts [act ] = b
303- case []interface {}:
304- acts [act ] = make ([]string , len (b ))
305- for i , v := range b {
284+ case yaml .SequenceNode :
285+ var t []interface {}
286+ err := v .Decode (& t )
287+ if err != nil {
288+ return nil , err
289+ }
290+ schedules := make ([]map [string ]string , len (t ))
291+ if k == "schedule" {
292+ for i , tt := range t {
293+ vv , ok := tt .(map [string ]interface {})
294+ if ! ok {
295+ return nil , fmt .Errorf ("unknown on type(schedule): %#v" , v )
296+ }
297+ schedules [i ] = make (map [string ]string , len (vv ))
298+ for k , vvv := range vv {
306299 var ok bool
307- if acts [ act ][ i ], ok = v .(string ); ! ok {
308- return nil , fmt .Errorf ("unknown on type: %#v" , branches )
300+ if schedules [ i ][ k ], ok = vvv .(string ); ! ok {
301+ return nil , fmt .Errorf ("unknown on type(schedule) : %#v" , v )
309302 }
310303 }
311- case map [string ]interface {}:
312- if k != "workflow_dispatch" && act != "inputs" {
313- return nil , fmt .Errorf ("unknown on type: %#v" , branches )
304+ }
305+ }
306+
307+ if len (schedules ) == 0 {
308+ schedules = nil
309+ }
310+ res = append (res , & Event {
311+ Name : k ,
312+ schedules : schedules ,
313+ })
314+ case yaml .MappingNode :
315+ acts := make (map [string ][]string , len (v .Content )/ 2 )
316+ var inputs []WorkflowDispatchInput
317+ expectedKey := true
318+ var act string
319+ for _ , content := range v .Content {
320+ if expectedKey {
321+ if content .Kind != yaml .ScalarNode {
322+ return nil , fmt .Errorf ("key type not string: %#v" , content )
314323 }
315- inputs , err = parseWorkflowDispatchInputs (b )
324+ act = ""
325+ err := content .Decode (& act )
316326 if err != nil {
317327 return nil , err
318328 }
319- default :
320- return nil , fmt .Errorf ("unknown on type: %#v" , branches )
329+ } else {
330+ switch content .Kind {
331+ case yaml .SequenceNode :
332+ var t []string
333+ err := content .Decode (& t )
334+ if err != nil {
335+ return nil , err
336+ }
337+ acts [act ] = t
338+ case yaml .MappingNode :
339+ if k != "workflow_dispatch" || act != "inputs" {
340+ return nil , fmt .Errorf ("map should only for workflow_dispatch but %s: %#v" , act , content )
341+ }
342+
343+ var key string
344+ for i , vv := range content .Content {
345+ if i % 2 == 0 {
346+ if vv .Kind != yaml .ScalarNode {
347+ return nil , fmt .Errorf ("key type not string: %#v" , vv )
348+ }
349+ key = ""
350+ if err := vv .Decode (& key ); err != nil {
351+ return nil , err
352+ }
353+ } else {
354+ if vv .Kind != yaml .MappingNode {
355+ return nil , fmt .Errorf ("key type not map(%s): %#v" , key , vv )
356+ }
357+
358+ input := WorkflowDispatchInput {}
359+ if err := vv .Decode (& input ); err != nil {
360+ return nil , err
361+ }
362+ input .Name = key
363+ inputs = append (inputs , input )
364+ }
365+ }
366+ default :
367+ return nil , fmt .Errorf ("unknown on type: %#v" , content )
368+ }
321369 }
370+ expectedKey = ! expectedKey
322371 }
323372 if len (inputs ) == 0 {
324373 inputs = nil
@@ -331,33 +380,8 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) {
331380 acts : acts ,
332381 inputs : inputs ,
333382 })
334- case []interface {}:
335- if k != "schedule" {
336- return nil , fmt .Errorf ("unknown on type: %#v" , v )
337- }
338- schedules := make ([]map [string ]string , len (t ))
339- for i , tt := range t {
340- vv , ok := tt .(map [string ]interface {})
341- if ! ok {
342- return nil , fmt .Errorf ("unknown on type: %#v" , v )
343- }
344- schedules [i ] = make (map [string ]string , len (vv ))
345- for k , vvv := range vv {
346- var ok bool
347- if schedules [i ][k ], ok = vvv .(string ); ! ok {
348- return nil , fmt .Errorf ("unknown on type: %#v" , v )
349- }
350- }
351- }
352- if len (schedules ) == 0 {
353- schedules = nil
354- }
355- res = append (res , & Event {
356- Name : k ,
357- schedules : schedules ,
358- })
359383 default :
360- return nil , fmt .Errorf ("unknown on type: %# v" , v )
384+ return nil , fmt .Errorf ("unknown on type: %v" , v . Kind )
361385 }
362386 }
363387 return res , nil
0 commit comments