Convert issue to pull request

Pull requests are simply issues with an attached branch. An existing issue can be converted to a pull request with the following API query, assuming you own the issue:

curl --request POST --header 'Authorization: token $TOKEN' --data '{"issue": $ISSUE, "head": "[$FORK:]$BRANCH", "base": "$BASE"}' https://api.github.com/repos/$ROOT/$REPO/pulls

Alternatively, with the gh CLI:

gh api repos/:owner/:repo/pulls -X POST -F issue=$ISSUE -F head=:branch -F base=$BASE

We can turn this into an alias:

gh alias set repo-branch-default 'repo view --json defaultBranchRef --template "{{.defaultBranchRef.name}}"'
gh alias set --shell issue-convert-pr 'gh api repos/:owner/:repo/pulls -X POST -F issue="$1" -F head=:branch -F base="$(gh repo-branch-default)"'

This can be invoked as follows:

git switch my-branch
git push --set-upstream origin my-branch
gh issue-convert-pr 123