Skip to content

Add short trigger syntax for labeled events with explicit item types#7153

Merged
pelikhan merged 6 commits intomainfrom
copilot/add-short-trigger-syntax
Dec 21, 2025
Merged

Add short trigger syntax for labeled events with explicit item types#7153
pelikhan merged 6 commits intomainfrom
copilot/add-short-trigger-syntax

Conversation

Copy link
Contributor

Copilot AI commented Dec 21, 2025

Implements shorthand syntax for label triggers that expands to full GitHub Actions configuration with workflow_dispatch and native label filtering.

Syntax

# Short form (explicit item type required)
on: issue labeled bug enhancement

# Expands to
on:
  issues:
    names:
    - bug
    - enhancement
    types:
    - labeled
  workflow_dispatch:
    inputs:
      item_number:
        description: The number of the issue
        required: true
        type: string

Supported variants:

  • on: issue labeled label1 label2 ... - Issues (explicit)
  • on: pull_request labeled label1 label2 ... - Pull requests (explicit)
  • on: pull-request labeled label1 label2 ... - Pull requests with hyphen (explicit)
  • on: discussion labeled label1 label2 ... - Discussions (explicit)

Note: Implicit syntax (on: labeled label1 label2) is NOT supported - item type must be explicitly specified.

Note: Discussion labeled triggers are supported, but GitHub Actions does not support the names field for discussion events, so label filtering must be handled via job conditions if needed.

Key Features

  • Native Label Filtering: Label names are applied directly in the names field for GitHub Actions native filtering for issues and pull requests (not commented out)
  • Explicit Item Types: Requires explicit specification of issue, pull_request, pull-request, or discussion to avoid ambiguity
  • Automatic Workflow Dispatch: Adds workflow_dispatch trigger with item_number input parameter
  • Hyphen Support: Both pull_request and pull-request syntax variants are supported
  • Discussion Support: Supports discussion labeled triggers (without names field due to GitHub Actions limitation)

Implementation

Parser (pkg/workflow/label_trigger_parser.go)

  • parseLabelTriggerShorthand() - Tokenizes and validates syntax (requires explicit item type, supports pull-request hyphen variant)
  • expandLabelTriggerShorthand() - Generates trigger config with native label filtering marker (omits names field for discussions)

Integration (pkg/workflow/schedule_preprocessing.go)

  • Added label trigger detection after slash command check, before schedule parsing
  • Follows existing shorthand expansion pattern

Native Filtering (pkg/workflow/frontmatter_extraction.go, pkg/workflow/filters.go)

  • Uses __gh_aw_native_label_filter__ marker to enable native GitHub Actions label filtering
  • Skips job condition filtering for shorthand-expanded triggers
  • Label names appear in YAML output for native filtering (issues and pull requests only)
  • Handles discussion sections without names field

Tests

  • 20 parser test cases covering valid/invalid syntax, entity types, hyphen variants, discussions, edge cases
  • 5 integration tests verifying full compilation pipeline with native filtering
  • Comprehensive fuzz tests (label_trigger_parser_fuzz_test.go) for parser robustness with 18+ seed cases
  • Example workflows demonstrating usage for issues, pull requests, and discussions

Example Workflows

See examples/label-trigger-simple.md, examples/label-trigger-pull-request.md, and examples/label-trigger-discussion.md for working examples that compile to valid GitHub Actions workflows with native label filtering.

Original prompt

Add a short trigger syntax to generated triggers on label created events.

on: labeled labelname1 labelname2
on: issue labeled labename1 labelname2 ...
on: discussion labeled name1 ...
on: pull_request labeled name1 ...

The short syntax expands to label triggers and workflow_dispatch with a input parameter for the item index

Update existings parsers, add extensive tests


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 21, 2025
Copilot AI and others added 3 commits December 21, 2025 17:43
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add short trigger syntax for label created events Add short trigger syntax for labeled events Dec 21, 2025
Copilot AI requested a review from pelikhan December 21, 2025 18:06
@pelikhan
Copy link
Contributor

@copilot the label names should be applied as "names" field in the issue generated code

Remove "on: labeled name" syntax, always make the target item type explicit

…licit item type

- Remove implicit "labeled" syntax - now requires "issue labeled" or "pull_request labeled"
- Label names are now applied as "names" field in generated YAML (not commented out)
- Add __gh_aw_native_label_filter__ marker to enable native GitHub Actions label filtering
- Skip label filtering via job conditions when using native filtering
- Update all tests to reflect changes
- Update example workflows to use explicit syntax

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 21, 2025

@copilot the label names should be applied as "names" field in the issue generated code

Remove "on: labeled name" syntax, always make the target item type explicit

Done in commit 1bb8304.

Changes made:

  1. Removed implicit "labeled" syntax - Now requires explicit item type:

    • on: issue labeled bug
    • on: pull_request labeled bug
    • on: labeled bug (removed)
  2. Label names now applied in generated YAML:

    "on":
      issues:
        names:        # ← Not commented out
        - bug
        - enhancement
        types:
        - labeled

The implementation uses an internal marker to distinguish shorthand-expanded triggers from regular triggers, ensuring label filtering is done natively by GitHub Actions instead of via job conditions.

Copilot AI changed the title Add short trigger syntax for labeled events Add short trigger syntax for labeled events with explicit item types Dec 21, 2025
@pelikhan
Copy link
Contributor

@copilot support "pull-request" or "pull_request"
Also support discussions
Add fuzz tests for parser

- Support both "pull_request" and "pull-request" (with hyphen) syntax
- Add support for "discussion labeled" triggers
- Add comprehensive fuzz tests for parser robustness
- Note: Discussions don't support names field (GitHub Actions limitation)
- Update all tests to cover new features
- Add example workflow for discussion labeled triggers

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 21, 2025

@copilot support "pull-request" or "pull_request"
Also support discussions
Add fuzz tests for parser

Done in commit aaeef68.

Changes made:

  1. Support for both "pull-request" and "pull_request" - Both syntaxes now work:

    • on: pull_request labeled needs-review
    • on: pull-request labeled needs-review
  2. Discussion support added:

    • on: discussion labeled question announcement
    • Note: GitHub Actions doesn't support names field for discussions, so it's omitted in the generated YAML
  3. Fuzz tests added (label_trigger_parser_fuzz_test.go):

    • FuzzParseLabelTriggerShorthand - Tests parser handles arbitrary input without panicking
    • FuzzExpandLabelTriggerShorthand - Tests expansion with various entity types and labels
    • Comprehensive seed corpus with 18+ test cases

Example outputs:

  • Pull-request (hyphen): Compiles to pull_request trigger with names field
  • Discussion: Compiles to discussion trigger without names field (per GitHub Actions spec)

@pelikhan
Copy link
Contributor

@copilot make sure generated lock file are syntactically correct

@pelikhan pelikhan marked this pull request as ready for review December 21, 2025 18:58
@pelikhan pelikhan merged commit c651689 into main Dec 21, 2025
4 of 5 checks passed
@pelikhan pelikhan deleted the copilot/add-short-trigger-syntax branch December 21, 2025 18:58
github-actions bot added a commit that referenced this pull request Dec 21, 2025
Add documentation for the new shorthand label trigger syntax that supports:
- Basic format: on: issue labeled bug
- Space-separated labels: on: issue labeled bug enhancement
- Comma-separated labels: on: issue labeled bug, enhancement

Covers features from PRs #7153, #7160, and #7169.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants