name: "Setup Specwright"
description: "Initialize Specwright in your repository with spec templates and configuration"
branding:
  icon: "file-text"
  color: "blue"

inputs:
  team:
    description: "Team name for SPECWRIGHT.yaml"
    required: false
    default: ""
  ticket-system:
    description: "Ticket system (github, jira, linear)"
    required: false
    default: "github"
  create-pr:
    description: "Create a PR with setup files (vs committing directly)"
    required: false
    default: "true"

runs:
  using: "composite"
  steps:
    - uses: actions/checkout@v4

    - uses: actions/setup-python@v5
      with:
        python-version: "3.12"

    - name: Install Specwright
      shell: bash
      run: pip install "gv-specwright>=1.0.0,<2.0.0"

    - name: Run specwright setup
      shell: bash
      env:
        INPUT_TEAM: ${{ inputs.team }}
        INPUT_TICKET_SYSTEM: ${{ inputs.ticket-system }}
      run: |
        ARGS=(--non-interactive --ticket-system "$INPUT_TICKET_SYSTEM")
        if [ -n "$INPUT_TEAM" ]; then
          ARGS+=(--team "$INPUT_TEAM")
        fi
        specwright setup "${ARGS[@]}"

    - name: Create PR with setup files
      if: inputs.create-pr == 'true'
      shell: bash
      env:
        GH_TOKEN: ${{ github.token }}
      run: |
        git config user.name "github-actions[bot]"
        git config user.email "github-actions[bot]@users.noreply.github.com"
        git checkout -b specwright/setup
        git add docs/specs/ SPECWRIGHT.yaml
        git commit -m "chore: initialize Specwright"
        git push -u origin specwright/setup
        gh pr create \
          --title "chore: initialize Specwright" \
          --body "$(cat <<'EOF'
        ## Summary

        Initialize Specwright in this repository with:
        - `docs/specs/_template.md` — copy to create new spec documents
        - `SPECWRIGHT.yaml` — repo-level configuration

        ## Next steps

        1. Merge this PR
        2. Copy the template to create your first spec
        3. Install the Claude Code plugin: `/plugin install specwright`

        ---
        _Created by the [Setup Specwright](https://github.com/Gerner-Ventures/gv-exp-specwright) action._
        EOF
        )"
