Add onboard and migrate-pr commands (v1.1.0)
New commands for safely onboarding existing subrepos into the monorepo without losing open PRs: - josh-sync onboard <target>: interactive, resumable 5-step flow (import → wait for merge → reset to new repo) - josh-sync migrate-pr <target> [PR#...] [--all]: migrate PRs from archived repo to new repo via patch application Also refactors create_pr() to wrap create_pr_number(), eliminating duplicated curl/jq logic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
48
lib/auth.sh
48
lib/auth.sh
@@ -39,16 +39,15 @@ subrepo_ls_remote() {
|
||||
}
|
||||
|
||||
# ─── PR Creation ────────────────────────────────────────────────────
|
||||
# Shared helper for creating PRs on Gitea/GitHub API.
|
||||
# Shared helpers for creating PRs on Gitea/GitHub API.
|
||||
# Usage: create_pr <api_url> <token> <base> <head> <title> <body>
|
||||
# number=$(create_pr_number <api_url> <token> <base> <head> <title> <body>)
|
||||
#
|
||||
# create_pr — fire-and-forget (stdout suppressed, safe inside sync functions)
|
||||
# create_pr_number — returns the new PR number via stdout
|
||||
|
||||
create_pr() {
|
||||
local api_url="$1"
|
||||
local token="$2"
|
||||
local base="$3"
|
||||
local head="$4"
|
||||
local title="$5"
|
||||
local body="$6"
|
||||
create_pr_number() {
|
||||
local api_url="$1" token="$2" base="$3" head="$4" title="$5" body="$6"
|
||||
|
||||
curl -sf -X POST \
|
||||
-H "Authorization: token ${token}" \
|
||||
@@ -59,5 +58,36 @@ create_pr() {
|
||||
--arg title "$title" \
|
||||
--arg body "$body" \
|
||||
'{base:$base, head:$head, title:$title, body:$body}')" \
|
||||
"${api_url}/pulls" >/dev/null
|
||||
"${api_url}/pulls" | jq -r '.number'
|
||||
}
|
||||
|
||||
create_pr() {
|
||||
create_pr_number "$@" >/dev/null
|
||||
}
|
||||
|
||||
# ─── PR API Helpers ──────────────────────────────────────────────
|
||||
# Used by onboard and migrate-pr commands.
|
||||
|
||||
# List open PRs on a repo. Returns JSON array.
|
||||
# Usage: list_open_prs <api_url> <token>
|
||||
list_open_prs() {
|
||||
local api_url="$1" token="$2"
|
||||
curl -sf -H "Authorization: token ${token}" \
|
||||
"${api_url}/pulls?state=open&limit=50"
|
||||
}
|
||||
|
||||
# Get PR diff as plain text.
|
||||
# Usage: get_pr_diff <api_url> <token> <pr_number>
|
||||
get_pr_diff() {
|
||||
local api_url="$1" token="$2" pr_number="$3"
|
||||
curl -sf -H "Authorization: token ${token}" \
|
||||
"${api_url}/pulls/${pr_number}.diff"
|
||||
}
|
||||
|
||||
# Get single PR as JSON (for checking merge status, metadata, etc.).
|
||||
# Usage: get_pr <api_url> <token> <pr_number>
|
||||
get_pr() {
|
||||
local api_url="$1" token="$2" pr_number="$3"
|
||||
curl -sf -H "Authorization: token ${token}" \
|
||||
"${api_url}/pulls/${pr_number}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user