feat(infra): enhance open-pr.sh for rolling PRs and custom branches
This commit is contained in:
parent
8082bc3003
commit
101eef98aa
1 changed files with 16 additions and 5 deletions
|
|
@ -16,10 +16,11 @@ set -euo pipefail
|
||||||
: "${FORGEJO_USER:?missing FORGEJO_USER}"
|
: "${FORGEJO_USER:?missing FORGEJO_USER}"
|
||||||
: "${FORGEJO_TOKEN:?missing FORGEJO_TOKEN}"
|
: "${FORGEJO_TOKEN:?missing FORGEJO_TOKEN}"
|
||||||
|
|
||||||
slug="" title="" body_file="" base="main" label=""
|
slug="" title="" body_file="" base="main" label="" branch=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--slug) slug="$2"; shift 2 ;;
|
--slug) slug="$2"; shift 2 ;;
|
||||||
|
--branch) branch="$2"; shift 2 ;;
|
||||||
--title) title="$2"; shift 2 ;;
|
--title) title="$2"; shift 2 ;;
|
||||||
--body-file) body_file="$2"; shift 2 ;;
|
--body-file) body_file="$2"; shift 2 ;;
|
||||||
--base) base="$2"; shift 2 ;;
|
--base) base="$2"; shift 2 ;;
|
||||||
|
|
@ -28,16 +29,23 @@ while [[ $# -gt 0 ]]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
: "${slug:?--slug required}"
|
|
||||||
: "${title:?--title required}"
|
: "${title:?--title required}"
|
||||||
: "${body_file:?--body-file required}"
|
: "${body_file:?--body-file required}"
|
||||||
[[ -f "$body_file" ]] || { echo "open-pr: body file not found: $body_file" >&2; exit 1; }
|
[[ -f "$body_file" ]] || { echo "open-pr: body file not found: $body_file" >&2; exit 1; }
|
||||||
|
|
||||||
branch="feat/ai-ingest-${slug}"
|
# --branch overrides the default; otherwise derive the ingest branch from --slug.
|
||||||
|
# (run-prune passes its own chore/prune-orphans-* branch; run-ingest passes --slug.)
|
||||||
|
if [[ -z "$branch" ]]; then
|
||||||
|
: "${slug:?--slug or --branch required}"
|
||||||
|
branch="feat/ai-ingest-${slug}"
|
||||||
|
fi
|
||||||
repo="$(basename -s .git "$(git config --get remote.origin.url)")"
|
repo="$(basename -s .git "$(git config --get remote.origin.url)")"
|
||||||
|
|
||||||
# 1. Branch + commit + push (AGENTS.md rule 5: never commit to main)
|
# 1. Branch + commit + push (AGENTS.md rule 5: never commit to main)
|
||||||
git switch -c "$branch" 2>/dev/null || git switch "$branch"
|
# Rolling PR: -C force-resets the branch label to the current base (we are on it after
|
||||||
|
# clean_start) and CARRIES the freshly-written wiki/ changes, so a re-ingest of the same
|
||||||
|
# source rebuilds the branch cleanly instead of hitting a dirty-switch refusal.
|
||||||
|
git switch -C "$branch"
|
||||||
git add wiki/
|
git add wiki/
|
||||||
# Scope BOTH the emptiness check and the commit to wiki/ — never commit anything that
|
# Scope BOTH the emptiness check and the commit to wiki/ — never commit anything that
|
||||||
# happened to be staged outside wiki/ (a stray hook, an aborted prior run, etc.).
|
# happened to be staged outside wiki/ (a stray hook, an aborted prior run, etc.).
|
||||||
|
|
@ -46,7 +54,10 @@ if git diff --cached --quiet -- wiki/; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
git commit -m "$title" -- wiki/
|
git commit -m "$title" -- wiki/
|
||||||
git push -u origin "$branch"
|
# Try a normal push (new branch / fast-forward). If the branch was rebuilt from base and
|
||||||
|
# diverged, force-with-lease updates the open PR in place — the lease refuses to clobber if
|
||||||
|
# origin moved unexpectedly since our fetch, so concurrent work is never lost.
|
||||||
|
git push -u origin "$branch" 2>/dev/null || git push -u --force-with-lease origin "$branch"
|
||||||
|
|
||||||
# DRY_RUN: local git work done; skip the Forgejo API (offline tests).
|
# DRY_RUN: local git work done; skip the Forgejo API (offline tests).
|
||||||
if [[ -n "${DRY_RUN:-}" ]]; then
|
if [[ -n "${DRY_RUN:-}" ]]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue