--- name: publish description: Ship code when user wants to commit changes, create pull requests, or save work. Auto-detects whether to create commits or PRs based on git state. Generates well-formatted messages with PRD references. Always waits for approval before executing git commands. --- # Publish Changes Create well-formatted git commits and GitHub pull requests with automatic PRD referencing. This skill is a **git assistant** - it helps you ship code, you stay in control. ## When to Activate This skill activates when user says things like: - "ship this" - "commit changes" - "save my work" - "create a commit" - "make a PR" - "create pull request" - "submit for review" - "push this code" - Any request to commit, ship, or create a pull request ## Mode Detection The skill **automatically detects** what you want to do based on git state: 1. **Commit Mode** - When uncommitted changes exist - Detects: Uncommitted changes in working directory - Creates: Conventional commit with PRD reference - Shows: Preview before execution 2. **Pull Request Mode** - When branch is clean and ahead of base - Detects: Clean working directory + commits ahead of main/master - Creates: GitHub PR with comprehensive description - Shows: Preview before execution **User says "ship" → Skill detects mode → Confirms with user → Executes** ## Workflow ### Mode 1: Commit #### Step 0: Confirm Mode Detection **Show detected mode to user:** ``` 🔍 Detected uncommitted changes Mode: Commit Files changed: 8 files (+247/-58 lines) Proceed with commit creation? [yes/show-changes/cancel] ``` **If user says "show-changes":** - Show full `git diff --stat` - Then ask again: "Proceed with commit? [yes/cancel]" **If user says "cancel":** - Exit without doing anything **If user says "yes":** - Continue to Step 1 #### Step 1: Analyze Changes Comprehensively **Load git tools and analyze changes:** ```bash # Source shared git tools source skills/shared/scripts/git-tools.sh # Analyze changes with detailed stats changes=$(analyze_git_changes "HEAD") # Parse the output files_changed=$(echo "$changes" | grep "FILES_CHANGED=" | cut -d'=' -f2) insertions=$(echo "$changes" | grep "INSERTIONS=" | cut -d'=' -f2) deletions=$(echo "$changes" | grep "DELETIONS=" | cut -d'=' -f2) # Get detailed file list with status git diff HEAD --name-status # Categorize changes by type new_files=$(git diff HEAD --name-only --diff-filter=A) modified_files=$(git diff HEAD --name-only --diff-filter=M) deleted_files=$(git diff HEAD --name-only --diff-filter=D) ``` **Analyze change patterns:** ```bash # Group files by directory/area # Detect if changes span multiple features # Identify primary area of change # Analyze actual diff content to understand nature of changes: # - Are we adding new functionality? (new classes, functions) # - Are we fixing bugs? (error handling, validation) # - Are we refactoring? (moving code, renaming) # - Are we updating tests? (test files changed) ``` **Show comprehensive change summary:** ``` 📊 Changes Analyzed: Statistics: - 8 files changed (+247/-58 lines) - New files: 2 - Modified files: 5 - Deleted files: 1 Changes by area: - Authentication (5 files, +180/-20 lines) * app/models/user.rb * app/services/auth/oauth_service.rb * app/controllers/auth_controller.rb * spec/models/user_spec.rb * spec/services/oauth_service_spec.rb - Testing (3 files, +67/-38 lines) * spec/models/user_spec.rb * spec/services/oauth_service_spec.rb * spec/integration/oauth_flow_spec.rb Nature of changes: - New functionality: OAuth provider integration - Modified: User model with OAuth fields - Tests: Comprehensive test coverage added ``` **Check for multiple unrelated areas:** If changes span multiple distinct features, suggest splitting: ``` 💡 Notice: Changes span multiple areas: - Authentication (5 files) - Booking system (3 files) These appear to be unrelated changes. Recommend splitting into: 1. Commit for authentication changes 2. Commit for booking changes Benefits: Cleaner history, easier review, better git bisect Continue with single commit? [yes/split/cancel] ``` **If user chooses "split":** - Help create multiple commits by feature area - Process each area separately through commit workflow #### Step 2: Analyze Changed Files ```bash # Get changed files changed_files=$(git diff HEAD --name-only) # Optionally detect scope from common directory patterns # Scope is optional and can be omitted if not clear scope=$(detect_scope_from_files "$changed_files") ``` **Note**: Scope detection uses simple heuristics (most common directory). Claude will analyze the changes and may choose to omit scope if it's not meaningful or use a more descriptive scope based on the actual changes. #### Step 3: Determine Commit Type Analyze changes to identify type: - **feat**: New feature or capability - **fix**: Bug fix - **refactor**: Code refactoring (no functional change) - **docs**: Documentation only - **test**: Adding or updating tests - **chore**: Maintenance (dependencies, config, etc.) - **perf**: Performance improvement - **style**: Code style/formatting (no logic change) #### Step 4: Find Related PRD Intelligently **Multi-strategy PRD detection:** ```bash # Source context manager source skills/shared/scripts/context-manager.sh # Strategy 1: Check recent commits for PRD references prd_from_commits=$(git log -5 --oneline | grep -o '.claude/prds/[^)]*\.md' | head -1) # Strategy 2: Find PRD from changed files # - Match file paths to PRD context files # - Check .claude/prds/context/*.json for files_created for context_file in .claude/prds/context/*.json; do if [[ -f "$context_file" ]]; then context_files=$(jq -r '.files_created[]' "$context_file") # Check if any changed files match context files for changed_file in $changed_files; do if echo "$context_files" | grep -q "$changed_file"; then prd_file=$(basename "$context_file" .json) related_prd=".claude/prds/${prd_file}.md" break 2 fi done fi done # Strategy 3: Check for in-progress PRDs # - Find PRDs with status "In Progress" # - Suggest most recently modified PRD in_progress_prds=$(grep -l "Status.*In Progress" .claude/prds/*.md 2>/dev/null) # Strategy 4: Ask user if multiple matches or no match found if [[ -z "$related_prd" ]] && [[ -n "$in_progress_prds" ]]; then # Present options to user fi ``` **Show PRD detection results:** ``` 🔍 PRD Detection: Strategy used: [Strategy name] Related PRD: .claude/prds/2024-10-25-oauth-core.md PRD Details: - Type: Core Feature - Status: In Progress - Phase: Phase 1 - OAuth Integration (3/4 substories complete) This commit relates to: [Substory 1.3] Token management ✅ Will include PRD reference in commit message ``` **If no PRD detected:** ``` â„šī¸ No related PRD detected Checked: - Recent commits (no PRD references found) - Context files (changed files don't match any PRD) - In-progress PRDs (none found) Options: 1. Continue without PRD reference (standalone commit) 2. Manually specify PRD: [enter path] Choice: [1/2] ``` #### Step 5: Generate Commit Message **Format:** ``` (): # or if scope is not meaningful: :