expandLabelTriggerShorthand takes an entity type and label names and returns a map that represents the expanded label trigger + workflow_dispatch configuration with item_number input. Note: GitHub Actions doesn't support native label filtering for any event type, so all labels are filtered via job c
(entityType string, labelNames []string)
| 84 | // Note: GitHub Actions doesn't support native label filtering for any event type, |
| 85 | // so all labels are filtered via job conditions using the internal `names` field. |
| 86 | func expandLabelTriggerShorthand(entityType string, labelNames []string) map[string]any { |
| 87 | labelTriggerParserLog.Printf("Expanding label trigger shorthand: entity=%s, labels=%v", entityType, labelNames) |
| 88 | |
| 89 | // Create the trigger configuration based on entity type |
| 90 | var triggerKey string |
| 91 | switch entityType { |
| 92 | case "issues": |
| 93 | triggerKey = "issues" |
| 94 | case "pull_request": |
| 95 | triggerKey = "pull_request" |
| 96 | case "discussion": |
| 97 | triggerKey = "discussion" |
| 98 | default: |
| 99 | labelTriggerParserLog.Printf("Unknown entity type %q, defaulting to issues trigger key", entityType) |
| 100 | triggerKey = "issues" // Default to issues (though this shouldn't happen with our parser) |
| 101 | } |
| 102 | |
| 103 | // Build the trigger configuration |
| 104 | // GitHub Actions doesn't support native label filtering for any event type, |
| 105 | // so we use the `names` field (internal representation) for job condition filtering |
| 106 | triggerConfig := map[string]any{ |
| 107 | "types": []any{"labeled"}, |
| 108 | } |
| 109 | |
| 110 | // Add label names for filtering |
| 111 | // All event types use `names` field for job condition filtering |
| 112 | // The `names` field is an internal representation for job condition generation |
| 113 | // and won't be rendered in the final GitHub Actions YAML for these event types |
| 114 | // Convert []string to []any so applyLabelFilter can type-assert correctly |
| 115 | namesAny := make([]any, len(labelNames)) |
| 116 | for i, name := range labelNames { |
| 117 | namesAny[i] = name |
| 118 | } |
| 119 | triggerConfig["names"] = namesAny |
| 120 | |
| 121 | // Create workflow_dispatch with item_number input (not required so the workflow can be |
| 122 | // triggered manually without providing a value; the activation job will fall back to |
| 123 | // the event payload when item_number is not supplied). |
| 124 | workflowDispatchConfig := map[string]any{ |
| 125 | "inputs": map[string]any{ |
| 126 | "item_number": map[string]any{ |
| 127 | "description": "The number of the " + getItemTypeName(entityType), |
| 128 | "required": false, |
| 129 | "default": "", |
| 130 | "type": "string", |
| 131 | }, |
| 132 | }, |
| 133 | } |
| 134 | |
| 135 | labelTriggerParserLog.Printf("Expanded to trigger key=%s with %d label(s) and workflow_dispatch", triggerKey, len(labelNames)) |
| 136 | return map[string]any{ |
| 137 | triggerKey: triggerConfig, |
| 138 | "workflow_dispatch": workflowDispatchConfig, |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // getItemTypeName returns the human-readable item type name for the entity type |
| 143 | func getItemTypeName(entityType string) string { |