MCPcopy Create free account
hub / github.com/github/gh-aw / buildDispatchLabelCommandCondition

Function buildDispatchLabelCommandCondition

pkg/workflow/label_command.go:101–129  ·  view source on GitHub ↗

buildDispatchLabelCommandCondition builds label-command conditions for dispatch-routed workflows that trigger through workflow_dispatch. For workflow_dispatch events, label routing checks use aw_context fields rather than github.event_name/github.event.label.

(labelNames []string, labelCommandEvents []string)

Source from the content-addressed store, hash-verified

99// For workflow_dispatch events, label routing checks use aw_context fields rather than
100// github.event_name/github.event.label.
101func buildDispatchLabelCommandCondition(labelNames []string, labelCommandEvents []string) (ConditionNode, error) {
102 if len(labelNames) == 0 {
103 return nil, errors.New("no label names provided for label-command trigger")
104 }
105 filteredEvents := FilterLabelCommandEvents(labelCommandEvents)
106 if len(filteredEvents) == 0 {
107 return nil, errors.New("no valid events specified for label-command trigger")
108 }
109
110 labelExpr := BuildPropertyAccess("fromJSON(github.event.inputs.aw_context || '{}').trigger_label")
111 eventExpr := BuildPropertyAccess("fromJSON(github.event.inputs.aw_context || '{}').event_type")
112
113 var labelChecks []ConditionNode
114 for _, labelName := range labelNames {
115 labelChecks = append(labelChecks, BuildEquals(labelExpr, BuildStringLiteral(labelName)))
116 }
117 labelNameMatch := BuildDisjunction(false, labelChecks...)
118
119 var eventChecks []ConditionNode
120 for _, event := range filteredEvents {
121 eventChecks = append(eventChecks, BuildEquals(eventExpr, BuildStringLiteral(event)))
122 }
123 isLabelSourceEvent := BuildDisjunction(false, eventChecks...)
124 dispatchLabelCondition := &OrNode{
125 Left: &AndNode{Left: isLabelSourceEvent, Right: labelNameMatch},
126 Right: &NotNode{Child: isLabelSourceEvent},
127 }
128 return dispatchLabelCondition, nil
129}

Callers 2

applyDefaultsMethod · 0.85

Calls 5

FilterLabelCommandEventsFunction · 0.85
BuildPropertyAccessFunction · 0.85
BuildEqualsFunction · 0.85
BuildStringLiteralFunction · 0.85
BuildDisjunctionFunction · 0.85

Tested by 1