# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

# Clone the repo
exec gh repo clone ${ORG}/${REPO}
cd ${REPO}
exec git config user.email "test@example.com"
exec git config user.name "Test User"

# Configure push.default so that it should use the merge ref
exec git config push.default upstream

# But prepare a branch that doesn't have a tracking merge ref
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push origin feature-branch

# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
