📚 Update serena creating-prs workflow documentation

This commit is contained in:
Andrey Antukh 2026-07-09 13:12:41 +02:00
parent 28fd798c52
commit 64b0bff7bd
2 changed files with 109 additions and 0 deletions

View File

@ -2,6 +2,20 @@
PR only on explicit request. Branch: issue/feature-specific; fallback `<type>/<short-description>` (`fix/...`, `feat/...`, `refactor/...`, `docs/...`, `chore/...`, `perf/...`).
## Target Branch
Auto-detect the base branch with `tools/detect-target-branch`:
```bash
TARGET=$(tools/detect-target-branch)
```
This outputs `staging` or `develop` by walking the local commit graph (pure local, no remote/network). Do not ask the user for the target branch unless the tool fails.
## Metadata
Always add the PR to the Main project (`--project "Main"`) unless the user explicitly requests a different project.
## Title Format
PR titles follow commit title conventions:
@ -60,3 +74,24 @@ The "Note:" line is required at the top. Adjust if this is a manual (non-AI) PR.
- Follow `mem:workflow/creating-commits` for commits
- Run the focused tests/lints appropriate to touched modules.
- Do not force-push during review unless the maintainer workflow explicitly asks for it.
- When the user says the code is already pushed, trust that — do not verify remote branch existence via `git ls-remote` or `git fetch`.
## Creating the PR
```bash
cat > /tmp/pr-body.md << 'PR_BODY'
<body content here>
PR_BODY
TARGET=$(tools/detect-target-branch)
gh pr create \
--repo penpot/penpot \
--base "$TARGET" \
--head <branch> \
--title "<title>" \
--project "Main" \
--body-file /tmp/pr-body.md
rm -f /tmp/pr-body.md
```

74
tools/detect-target-branch Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -euo pipefail
# detect-target-branch
#
# Determines the target branch for a PR of the current branch.
#
# Uses git name-rev to find the nearest ref (branch/tag) that is an ancestor of
# HEAD, falling back to a graph walk if name-rev returns the current branch.
#
# Pure local — no remote, no SSH, no network. Works even when the current
# branch shares its tip commit with the target (not yet diverged).
#
# Usage:
# tools/detect-target-branch # print branch name
# tools/detect-target-branch --verbose # print "branch~N"
#
# Exit status:
# 0 — target found
# 1 — no target found (orphan commit, no other branches)
verbose=false
for arg do
case "$arg" in
--verbose|-v) verbose=true ;;
--name-only) ;;
--help|-h)
sed -n '/^#/,/^$/p' "$0" | sed 's/^# //; s/^#$//'
exit 0
;;
*)
echo "Unknown option: $arg" >&2
echo "Usage: $(basename "$0") [--verbose|-v] [--name-only] [--help|-h]" >&2
exit 1
;;
esac
done
current=$(git rev-parse --abbrev-ref HEAD)
# Use name-rev to find the nearest ref — it has smart tie-breaking
raw=$(git name-rev --name-only HEAD 2>/dev/null)
target=${raw%%~[0-9]*} # strip ~N distance suffix
# If name-rev returned the current branch itself, walk backwards
if [ "$target" = "$current" ] || [ -z "$target" ]; then
target=$(git rev-list HEAD | while read commit; do
branch=$(git branch --points-at="$commit" --format='%(refname:short)' 2>/dev/null \
| grep -v "^$current$" \
| head -1 || true)
if [ -n "$branch" ]; then
echo "$branch"
break
fi
done || true)
if [ -z "$target" ]; then
echo "error: unable to determine target branch" >&2
exit 1
fi
fi
if [ "$verbose" = true ]; then
target_commit=$(git rev-parse "$target" 2>/dev/null || true)
if [ -n "$target_commit" ]; then
distance=$(git rev-list --count HEAD ^"$target_commit" 2>/dev/null || echo "0")
echo "${target}~${distance}"
else
echo "${target}~?"
fi
else
echo "$target"
fi