Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/workflow/label_trigger_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 8 additions & 19 deletions pkg/workflow/label_trigger_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code now adds the names field to all event types including discussion, but the schema definition for the discussion event in pkg/parser/schemas/main_workflow_schema.json (lines 617-630) does not include a names property and has "additionalProperties": false. This will cause schema validation to fail when compiling workflows with discussion label triggers like "discussion labeled question".

The schema needs to be updated to add a names field definition to the discussion event properties, similar to how it's defined for issues (lines 573-590) and pull_request (lines 482-499) events.

Copilot uses AI. Check for mistakes.

// Create workflow_dispatch with item_number input
workflowDispatchConfig := map[string]any{
Expand Down
22 changes: 7 additions & 15 deletions pkg/workflow/label_trigger_parser_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
29 changes: 9 additions & 20 deletions pkg/workflow/label_trigger_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading