| name | b4-pull-request |
| description | Crea un GitHub PR desde la branch actual con el template del repo. Usar cuando pidan abrir un PR; es el paso PR que invocan b7-issue-to-pr y b8-swarm. |
| context | fork |
| model | haiku |
Create Pull Request
Argumentos recibidos
$ARGUMENTS
Skill context: fork: el subagente solo ve este SKILL.md. El placeholder $ARGUMENTS es la UNICA vía por la que los argumentos tipeados (branch, flags como --draft, --body-file, --issue=N, --label) llegan al fork — el harness los sustituye. Si aparece vacío, derivar del estado de git actual.
Corre headless: nunca preguntar al usuario. Derivar cada decisión del estado git/GitHub, proceder con el default seguro y anotar cada decisión en el resumen final.
Flags soportados:
--draft — crear el PR en draft.
--body-file <path> — usar ese archivo como body.
--issue=N — el PR cierra el issue #N: el body DEBE incluir Closes #N real (nunca el placeholder #XXXX).
--label <name> — agregar ese label al PR via gh pr create --label.
Gather Context
1. Identify the current branch
git branch --show-current
2. Find the base branch (NUNCA asumir main)
BASE=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
Usar $BASE en TODOS los comandos siguientes — nunca hardcodear main. Si la branch actual ES ${BASE}, abortar y reportarlo en el resumen final (headless: no crear PR desde el default branch).
3. Analyze commits and diff relevant to this PR
git log origin/${BASE}..HEAD --oneline --no-decorate
git diff origin/${BASE}..HEAD --stat
Information Gathering
Derivar de commit messages, nombre de branch (e.g., fix/issue-123) y archivos cambiados:
- Related Issue Number: Si vino
--issue=N en los argumentos, usarlo directo. Si no, look for patterns like #123, fixes #123, or closes #123 in commit messages. Si no se puede determinar, usar el placeholder #XXXX y dejarlo anotado en el resumen final.
- Description: What problem does this solve? Why were these changes made?
- Type of Change: Bug fix, new feature, breaking change, refactor, cosmetic, documentation, or workflow
- Test Procedure: How was this tested? What could break?
Push Changes
Ensure all commits are pushed:
git push origin HEAD
Si el remoto rechaza por divergencia:
git push origin HEAD --force-with-lease
Create the Pull Request
IMPORTANT: Read and use the PR template at .github/pull_request_template.md. The PR body format must strictly match the template structure.
Si el template NO existe en el repo (o ya vino --body-file): usar estructura minima — ## Resumen, Closes #N, ## Tipo de cambio, ## Como se probo — y anotarlo en el resumen final.
When filling out the template:
- Replace
#XXXX with the actual issue number, or keep as #XXXX if no issue exists (for small fixes)
- Fill in all sections with relevant information gathered from commits and context
- Mark the appropriate "Type of Change" checkbox(es)
- Complete the "Pre-flight Checklist" items that apply
Create PR with gh CLI
Si vino --body-file, usar ese archivo directo; si no, escribir el body a un archivo temporal único (mktemp) y borrarlo después de crear el PR.
gh pr create --title "PR_TITLE" --body-file "${BODY_FILE}" --base "${BASE}" --draft --label auto-pr-bot
Incluir --draft y --label solo si vinieron en los argumentos.
Error Handling
- No commits ahead of base (
${BASE}): abortar y reportarlo en el resumen final.
- Branch not pushed: push the branch first:
git push -u origin HEAD.
- PR already exists: obtener la URL con
gh pr view, no crear otro; reportar la URL existente y anotar la decision.
- Merge conflicts: abortar y reportar el conflicto en el resumen final.
Summary Checklist
Before finalizing, ensure: