skip 'it creates a fork owned by the user running the test' # Setup environment variables used for testscript env REPO=${SCRIPT_NAME}-${RANDOM_STRING} env FORK=${REPO}-fork # 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} # Create a user fork of repository. This will be owned by USER. exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK} sleep 5 # Defer repo cleanup of fork defer gh repo delete --yes ${USER}/${FORK} # Retrieve fork repository information exec gh repo view ${USER}/${FORK} --json id --jq '.id' stdout2env FORK_ID # Clone the repo exec gh repo clone ${USER}/${FORK} cd ${FORK} # Prepare a branch where changes are pulled from the upstream default branch but pushed to fork exec git checkout -b feature-branch exec git branch --set-upstream-to upstream/main exec git config remote.pushDefault origin exec git config unset remote.upstream.gh-resolved exec git commit --allow-empty -m 'Empty Commit' exec git push # Create the PR spanning upstream and fork repositories exec gh pr create --title 'Feature Title' --body 'Feature Body' stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1 # Assert that the PR was created with the correct head repository and refs exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}