Skip to content

Add title-prefix and labels validation to push-to-pull-request-branch safe output - #1068

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-08753f9a-6c8e-4472-ad60-e1b1c585a840
Sep 27, 2025
Merged

pelikhan merged 6 commits into
mainfrom
copilot/fix-08753f9a-6c8e-4472-ad60-e1b1c585a840

Conversation

Copilot AI commented Sep 27, 2025 •

Copy link
Copy Markdown
Contributor

Push-to-Pull-Request-Branch Title Prefix and Labels Support ✅

Successfully implemented support for title-prefix and labels fields in the push-to-pull-request-branch safe output configuration.

✅ Implementation Complete

  • Updated PushToPullRequestBranchConfig struct to include TitlePrefix and Labels fields
  • Modified parsePushToPullRequestBranchConfig to parse the new fields from YAML
  • Updated buildCreateOutputPushToPullRequestBranchJob to pass fields as environment variables
  • Enhanced JavaScript code to validate pull request against title prefix and labels
  • Updated TypeScript type definitions for safe-outputs-config
  • Updated JSON schema to allow new fields in validation
  • Added comprehensive Go tests for new configuration parsing and environment variable generation
  • Added comprehensive JavaScript tests for validation logic
  • Manual testing confirms end-to-end functionality works correctly
  • Fixed jq expression to safely handle null labels array
  • Updated documentation for safe-outputs reference with minimal changes

✅ Features Added

  • Title Prefix Validation: Optional title-prefix field validates PR titles must start with specified prefix
  • Labels Validation: Optional labels field validates PR has all required labels
  • Environment Variables: Passes GITHUB_AW_PR_TITLE_PREFIX and GITHUB_AW_PR_LABELS to JavaScript
  • GitHub CLI Integration: Uses gh pr view --json headRefName,title,labels to fetch PR details with safe null handling
  • Comprehensive Error Messages: Clear validation failures with current vs expected values
  • Schema Validation: JSON schema updated to allow new fields

✅ Documentation Updated (Minimal Changes)

  • Added title-prefix and labels fields to the configuration reference
  • Explained pull request validation behavior with fail-fast approach
  • Updated safety features section to highlight new validation capabilities
  • Preserved all original examples and structure as requested

✅ Testing

  • All existing tests continue to pass (no regressions)
  • New Go tests validate configuration parsing and environment variable generation
  • New JavaScript tests validate PR title prefix and labels validation logic
  • Manual end-to-end testing confirms workflow compilation and generation works correctly
  • Code review feedback addressed (safer jq expression)

Usage Example

safe-outputs:
  push-to-pull-request-branch:
    target: "triggering"
    title-prefix: "[bot] "
    labels: ["automated", "enhancement"]

Both fields are optional and work independently or together. When specified, the workflow will validate the target PR meets the requirements before pushing changes.

Technical Implementation

  • Uses safe jq expression (.labels // [] | map(.name)) to handle null labels gracefully
  • Follows same patterns as existing create-pull-request safe output
  • Maintains backward compatibility - all existing configurations continue to work unchanged
  • Documentation updated with minimal changes, preserving original examples
Original prompt

Update the push-to-pull-request-branch safe output such that it supports

  • title-prefix field that specify a required title prefix for the pull request. Only pull requests with this prefix will be accepted. This field is optional
  • labels field: a list of label name. Only pull requests with these label names will be accepted. This field is optional.

Both fields should be passed as environment variable to the push-to-pull-request-branch job and the javascript should use them to validate the pull request if present.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title Update the push-to-pull-request-branch safe output such that it supports - title-prefix field that specify a required title prefix for the pull request. Only pull requests with this prefix will be accepted. This field is optional - labels field: a... Add title-prefix and labels validation to push-to-pull-request-branch safe output Sep 27, 2025
Copilot AI requested a review from pelikhan September 27, 2025 11:17
@pelikhan
pelikhan marked this pull request as ready for review September 27, 2025 11:26
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot update documentation

…le-prefix and labels validation

Co-authored-by: pelikhan <[email protected]>

Copilot AI commented Sep 27, 2025

Copy link
Copy Markdown
Contributor Author

@copilot update documentation

Updated the documentation in /docs/src/content/docs/reference/safe-outputs.md to include the new title-prefix and labels validation fields for push-to-pull-request-branch. The documentation now covers:

  • Configuration syntax for both new fields
  • Pull request validation behavior explanation
  • Examples showing different validation scenarios
  • Updated safety features section
  • Clear usage examples

Commit: 0912ce8

**Examples with different configurations:**

```yaml
# Always succeed, warn when no changes (default behavior)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot revert changes beyond here, do not modify existing example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted the additional examples while keeping the essential configuration documentation for title-prefix and labels fields. The original examples structure is now preserved exactly as it was.

Changes made:

  • Kept configuration fields documentation (title-prefix and labels)
  • Kept the validation explanation section
  • Kept updated safety features
  • Removed the additional examples I had added
  • Preserved all original examples and structure

Commit: e5f1885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants