diff --git a/pkg/workflow/label_trigger_integration_test.go b/pkg/workflow/label_trigger_integration_test.go index 328c02e20e..d49f131731 100644 --- a/pkg/workflow/label_trigger_integration_test.go +++ b/pkg/workflow/label_trigger_integration_test.go @@ -48,10 +48,11 @@ func TestLabelTriggerIntegrationSimple(t *testing.T) { t.Errorf("issues.names = %v, want [bug enhancement]", names) } - // Check that the native filter marker is present - nativeFilter, ok := issues["__gh_aw_native_label_filter__"].(bool) - if !ok || !nativeFilter { - t.Errorf("__gh_aw_native_label_filter__ = %v, want true", nativeFilter) + // Check that the native filter marker is NOT present + // (GitHub Actions doesn't support native label filtering for issues) + _, hasMarker := issues["__gh_aw_native_label_filter__"] + if hasMarker { + t.Errorf("__gh_aw_native_label_filter__ should not be present (no native label filtering support)") } // Check workflow_dispatch exists diff --git a/pkg/workflow/label_trigger_parser.go b/pkg/workflow/label_trigger_parser.go index a3128549fd..bb9edc7fb8 100644 --- a/pkg/workflow/label_trigger_parser.go +++ b/pkg/workflow/label_trigger_parser.go @@ -79,8 +79,8 @@ func parseLabelTriggerShorthand(input string) (entityType string, labelNames []s // 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: For discussion events, GitHub Actions doesn't support the `labels` field, -// so we use the native label filter marker but the labels will be filtered via job conditions. +// Note: GitHub Actions doesn't support native label filtering for any event type, +// so all labels are filtered via job conditions using the internal `names` field. func expandLabelTriggerShorthand(entityType string, labelNames []string) map[string]any { // Create the trigger configuration based on entity type var triggerKey string @@ -96,28 +96,17 @@ func expandLabelTriggerShorthand(entityType string, labelNames []string) map[str } // Build the trigger configuration - // Add a marker to indicate this uses native GitHub Actions label filtering - // (not job condition filtering), so names should not be commented out - // Note: For discussion events, GitHub Actions doesn't support names field, - // so we don't include it but still use the marker to indicate shorthand expansion + // GitHub Actions doesn't support native label filtering for any event type, + // so we use the `names` field (internal representation) for job condition filtering triggerConfig := map[string]any{ "types": []any{"labeled"}, } // Add label names for filtering - // For issues: GitHub Actions supports native `labels` field - use it with marker - // For pull_request & discussion: Use `names` field for job condition filtering (no marker) - // Note: The `names` field is an internal representation for job condition generation - // and won't be rendered in the final GitHub Actions YAML for these event types - switch entityType { - case "issues": - triggerConfig["labels"] = labelNames - triggerConfig["__gh_aw_native_label_filter__"] = true // Marker to use native filtering - case "pull_request", "discussion": - // For pull_request and discussion: add names field for job condition filtering - triggerConfig["names"] = labelNames - // No marker - this will be filtered via job conditions - } + // All event types use `names` field for job condition filtering + // The `names` field is an internal representation for job condition generation + // and won't be rendered in the final GitHub Actions YAML for these event types + triggerConfig["names"] = labelNames // Create workflow_dispatch with item_number input workflowDispatchConfig := map[string]any{ diff --git a/pkg/workflow/label_trigger_parser_fuzz_test.go b/pkg/workflow/label_trigger_parser_fuzz_test.go index 8103fa4919..6684a8980e 100644 --- a/pkg/workflow/label_trigger_parser_fuzz_test.go +++ b/pkg/workflow/label_trigger_parser_fuzz_test.go @@ -138,21 +138,13 @@ func FuzzExpandLabelTriggerShorthand(f *testing.F) { t.Errorf("types array is empty for entityType=%q", entityType) } - // Check for names field (only for issues and pull_request, not discussion) - switch entityType { - case "issues", "pull_request": - if names, hasNames := triggerMap["names"]; !hasNames { - t.Errorf("trigger missing names field for entityType=%q", entityType) - } else if namesArray, ok := names.([]string); !ok { - t.Errorf("names is not a string array for entityType=%q", entityType) - } else if len(namesArray) != len(labelNames) { - t.Errorf("names array length mismatch: got %d, want %d for entityType=%q", len(namesArray), len(labelNames), entityType) - } - case "discussion": - // Discussion should not have names field (GitHub Actions doesn't support it) - if _, hasNames := triggerMap["names"]; hasNames { - t.Errorf("discussion trigger should not have names field, but it does") - } + // Check for names field (all event types use names for job condition filtering) + if names, hasNames := triggerMap["names"]; !hasNames { + t.Errorf("trigger missing names field for entityType=%q", entityType) + } else if namesArray, ok := names.([]string); !ok { + t.Errorf("names is not a string array for entityType=%q", entityType) + } else if len(namesArray) != len(labelNames) { + t.Errorf("names array length mismatch: got %d, want %d for entityType=%q", len(namesArray), len(labelNames), entityType) } } } diff --git a/pkg/workflow/label_trigger_parser_test.go b/pkg/workflow/label_trigger_parser_test.go index baab95b845..7351281705 100644 --- a/pkg/workflow/label_trigger_parser_test.go +++ b/pkg/workflow/label_trigger_parser_test.go @@ -329,26 +329,15 @@ func TestExpandLabelTriggerShorthand(t *testing.T) { t.Errorf("expandLabelTriggerShorthand() types = %v, want [labeled]", types) } - // Check labels/names field: - // - For issues: uses native 'labels' field - // - For pull_request & discussion: uses 'names' field for job condition filtering - switch tt.entityType { - case "issues": - labels, ok := triggerConfig["labels"].([]string) - if !ok { - t.Fatalf("expandLabelTriggerShorthand() labels is not a string array for issues") - } - if !slicesEqual(labels, tt.labelNames) { - t.Errorf("expandLabelTriggerShorthand() labels = %v, want %v", labels, tt.labelNames) - } - case "pull_request", "discussion": - names, ok := triggerConfig["names"].([]string) - if !ok { - t.Fatalf("expandLabelTriggerShorthand() names is not a string array for %s", tt.entityType) - } - if !slicesEqual(names, tt.labelNames) { - t.Errorf("expandLabelTriggerShorthand() names = %v, want %v", names, tt.labelNames) - } + // Check names field: + // All entity types use 'names' field for job condition filtering + // (GitHub Actions doesn't support native label filtering) + names, ok := triggerConfig["names"].([]string) + if !ok { + t.Fatalf("expandLabelTriggerShorthand() names is not a string array for %s", tt.entityType) + } + if !slicesEqual(names, tt.labelNames) { + t.Errorf("expandLabelTriggerShorthand() names = %v, want %v", names, tt.labelNames) } // Check workflow_dispatch