# Load PR Context and Load Review Checklist

## Load Config and PR Context

```bash
# Load GitFlow config (sets GF_* variables)
read_gitflow_config || { echo "❌ Run /gitflow init first."; exit 1; }

CURRENT=$(git rev-parse --abbrev-ref HEAD)
GIT_PROVIDER="$GF_PROVIDER"

# Try loading persisted PR state first
CONFIG_DIR=$(dirname "$GF_CONFIG_FILE")
PR_STATE_FILE="$CONFIG_DIR/cache/pr-state.json"
if [ -f "$PR_STATE_FILE" ]; then
  PR_NUMBER=$(grep -oP '"pr_number":\s*"\K[^"]+' "$PR_STATE_FILE" | head -1)
  TARGET_BRANCH=$(grep -oP '"target_branch":\s*"\K[^"]+' "$PR_STATE_FILE" | head -1)
  echo "✓ Loaded PR state from cache: PR #$PR_NUMBER → $TARGET_BRANCH"
fi

# Fallback: query provider if no cached state
if [ -z "$PR_NUMBER" ]; then
  if [ "$GIT_PROVIDER" = "github" ]; then
    PR_NUMBER=$(gh pr list --head "$CURRENT" --json number --jq '.[0].number')
    PR_STATUS=$(gh pr view $PR_NUMBER --json state,mergeable,reviews --jq '.')
  elif [ "$GIT_PROVIDER" = "azuredevops" ]; then
    PR_NUMBER=$(az repos pr list --source-branch "$CURRENT" --query "[0].pullRequestId" -o tsv)
    PR_STATUS=$(az repos pr show --id $PR_NUMBER --query "{status:status,mergeStatus:mergeStatus}")
  fi
fi

[ -z "$PR_NUMBER" ] && {
  echo "❌ No PR found for branch $CURRENT"
  echo "→ Run /gitflow pr first"
  STOP
}
```

## Display Review Checklist

```
╔══════════════════════════════════════════════════════════════════╗
║                    PR REVIEW CHECKLIST                            ║
╠══════════════════════════════════════════════════════════════════╣
║  PR #${PR_NUMBER}: ${PR_TITLE}                                    ║
╠══════════════════════════════════════════════════════════════════╣

## Code Quality
- [ ] Code follows project conventions
- [ ] No unnecessary complexity
- [ ] No code duplication
- [ ] Variable/function names are clear

## Security
- [ ] No hardcoded secrets
- [ ] Input validation present
- [ ] Authentication/authorization correct
- [ ] No SQL injection risks

## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests pass
- [ ] Manual testing completed

## EF Core (if applicable)
- [ ] Migration files complete (3 files)
- [ ] No destructive operations (or confirmed)
- [ ] Snapshot synced with base

## Documentation
- [ ] Code comments where needed
- [ ] API docs updated (if applicable)
- [ ] README updated (if applicable)

╚══════════════════════════════════════════════════════════════════╝
```
