timestamp "Base branch not specified, inferring to be default branch from repo"
base="$(jq -r '.default_branch'<<<"$repo_data")"
timestamp "Using default branch '$base' as base branch"
fi
if is_blank "$head";then
if ! is_in_git_repo;then
die "Head branch not specified and not in a git repository checkout to infer it"
fi
checkout_owner_repo="$(gh api '/repos/{owner}/{repo}'| jq -r '.full_name')"
if["$owner/$repo" !="$checkout_owner_repo"];then
die "ERROR: Head branch not specified and current git repository checkout we are within ($checkout_owner_repo) does not match the target repo ($owner/$repo), so cannot use local branch name to infer it"
fi
timestamp "Head branch not specified, inferring to be current branch from repo checkout"
head="$(git rev-parse --abbrev-ref HEAD)"
timestamp "Head branch was inferred from local git checkout branch to be '$head'"
if["$head"="$base"];then
die "Cannot create pull request from head branch '$head' to base branch '$base' because they are the same branch! "
body="${GITHUB_PULL_REQUEST_BODY:-${body_template:-Created automatically by script \`${0##*/}\` in the [DevOps Bash tools](https://github.com/HariSekhon/DevOps-Bash-tools) repo}}"
timestamp "Branch '$base' already has an existing pull request from '$head', skipping PR: $existing_pr_url"
echo >&2
exit0
fi
timestamp "Creating Pull Request from head '$head' into base branch '$base'"
# --no-maintainer-edit is important, otherwise member ci account gets error (and yes there is a double 'Fork collab' error in GitHub CLI's error message):
# pull request create failed: GraphQL: Fork collab Fork collab can't be granted by someone without permission (createPullRequest)