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

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

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

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

# Clone the repo
exec gh repo clone ${ORG}/${REPO}

# Prepare a branch to PR
cd ${REPO}
exec git config user.email "test@example.com"
exec git config user.name "Test User"
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push -u origin feature-branch

# Leave the repo so there's no local repo
cd ${WORK}

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