Resolve the current repository identity and fetch PR state. Both queries must
succeed before merging. Refuse before changing draft state unless the PR is
open and targets staging. If it is a draft, mark it ready, refetch the same
fields, and verify that the PR is still open, still targets staging, has
the same head, and is no longer a draft:
CURRENT_REPO=$(gh repo view --json nameWithOwner --jq '.nameWithOwner') || 1
! PR_JSON=$(gh view <> --json number,title,state,isDraft,baseRefName,headRefName,headRefOid,mergeable,mergeStateStatus,url,body,author,reviewDecision,statusCheckRollup,labels);
>&2
1
! jq -e <<< >/dev/null;
>&2
1
READY_TRANSITION=
jq -e <<< >/dev/null;
PRE_READY_HEAD=$(jq -r <<<)
! gh ready <>;
>&2
1
! PR_JSON=$(gh view <> --json number,title,state,isDraft,baseRefName,headRefName,headRefOid,mergeable,mergeStateStatus,url,body,author,reviewDecision,statusCheckRollup,labels);
>&2
1
! jq -e --arg <<< >/dev/null;
>&2
1
READY_TRANSITION=
checks_status=0
REQUIRED_CHECKS=$(gh checks <> --required --json bucket,name,state) || checks_status=$?
[[ -ne 0 && -ne 8 ]];
>&2
1
! jq -e <<< >/dev/null;
>&2
1
ON_STAGING_LABEL=$(gh label list --search -- 100 \
--json name --jq )
[[ != ]];
>&2
1