#!/usr/bin/env bash
set -euo pipefail
# Caller supplies AZURE_DEVOPS_EXT_PAT, AZURE_DEVOPS_TEST_ORG,
# AZURE_DEVOPS_TEST_PROJECT, and a fresh SEED_DIR.
cd "$SEED_DIR"
git init -b main
git config user.name 'Proof fixture'
git config user.email 'proof@example.com'
printf 'Batch close proof\n' > README.md
git add README.md
git commit -m 'Initial fixture'
url="$AZURE_DEVOPS_TEST_ORG/$AZURE_DEVOPS_TEST_PROJECT/_git/proof-47464-e1"
git remote add origin "$url"
git -c credential.helper='!f() { echo username=pat; echo "password=$AZURE_DEVOPS_EXT_PAT"; }; f' push origin main
for n in 1 2 3 4 5 6 7 8; do
 git checkout -b "proof-$n" main
 printf 'Change %s\n' "$n" > "change-$n.txt"
 git add .
 git commit -m "Fixture $n"
 git -c credential.helper='!f() { echo username=pat; echo "password=$AZURE_DEVOPS_EXT_PAT"; }; f' push origin "proof-$n"
 az repos pr create --organization "$AZURE_DEVOPS_TEST_ORG" --project "$AZURE_DEVOPS_TEST_PROJECT" --repository proof-47464-e1 --source-branch "proof-$n" --target-branch main --title "Batch close proof $n" --query pullRequestId -o tsv
 done
git checkout main
