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

Function parseDeploymentTrigger

pkg/workflow/trigger_parser.go:638–710  ·  view source on GitHub ↗

parseDeploymentTrigger parses deployment status triggers with optional state filtering. Supported patterns: - "deployment failed" → deployment_status filtered to failure - "deployment error" → deployment_status filtered to error - "deployment failed or error" → deployment_status f

(input string)

Source from the content-addressed store, hash-verified

636// - "deployment failed or error" → deployment_status filtered to failure or error
637// - "deployment_status" → deployment_status (all states, no filter)
638func parseDeploymentTrigger(input string) (*TriggerIR, error) {
639 tokens := strings.Fields(input)
640 if len(tokens) == 0 {
641 return nil, nil
642 }
643
644 // Only handle "deployment" or "deployment_status" prefix
645 if tokens[0] != "deployment" && tokens[0] != "deployment_status" {
646 return nil, nil
647 }
648
649 // Bare "deployment_status" with no further args - let it fall through as a simple string
650 if len(tokens) == 1 {
651 return nil, nil
652 }
653
654 // Map common words to GitHub deployment_status state values
655 stateAliases := map[string]string{
656 "failed": "failure",
657 "failure": "failure",
658 "error": "error",
659 "errored": "error",
660 "success": "success",
661 "succeeded": "success",
662 "pending": "pending",
663 "inactive": "inactive",
664 }
665
666 // Parse remaining tokens to collect states, skipping conjunctions
667 var states []string
668 seenStates := make(map[string]struct {
669 })
670 conjunctions := map[string]struct {
671 }{"or": {}, "and": {}}
672 for _, tok := range tokens[1:] {
673 tok = strings.ToLower(strings.TrimRight(tok, ","))
674 if setutil.Contains(conjunctions, tok) {
675 continue
676 }
677 if state, ok := stateAliases[tok]; ok {
678 if !setutil.Contains(seenStates, state) {
679 states = append(states, state)
680 seenStates[state] = struct {
681 }{}
682 }
683 } else {
684 // Unknown token - not a deployment shorthand we can handle
685 return nil, nil
686 }
687 }
688
689 if len(states) == 0 {
690 return nil, nil
691 }
692
693 // Build the if condition expression
694 parts := make([]string, 0, len(states))
695 for _, s := range states {

Callers 1

ParseTriggerShorthandFunction · 0.85

Calls 3

ContainsFunction · 0.92
ToLowerMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected