If \$GITHUB_PULL_REQUEST_TITLE or \$GITHUB_PULL_REQUEST_BODY environment variables are set, those values will be used to generate the pull request
If \$GITHUB_PULL_REQUEST_BODY is not set, but .github/pull_request_template.md is present at the top of the current checkout repo, will use that for the body. If the template body contains Jira ticket number token templates such as AA-XXXXX or AA-NNNNN and the current branch is prefixed with a matching alpha-number token, then those tokens will be replaced with the real Jira number from the branch
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 "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)