patch_upstream_branch_name=$1 patch_stack_upstream_branch_name_relative_to_remote=$2 patch_stack_upstream_remote_name=$3 patch_stack_upstream_remote_url=$4
gh pr -R "$patch_stack_upstream_remote_url" view $patch_upstream_branch_name
if [ $? -eq 0 ]; then
echo "gh pr -R \"$patch_stack_upstream_remote_url\" view $patch_upstream_branch_name succeded"
closed=$(gh pr -R "$patch_stack_upstream_remote_url" view $patch_upstream_branch_name --json closed --jq '.closed')
if [ $? -eq 0 ]; then
echo "gh pr -R \"$patch_stack_upstream_remote_url\" view $patch_upstream_branch_name --json closed --jq '.closed' succeded"
echo "closed=$closed"
if [ $closed != "true" ]; then
echo "An open PR was found for the branch, so exiting to prevent duplicate PR creation."
exit 0
fi
fi
fi
gh pr create --fill --base "$patch_stack_upstream_branch_name_relative_to_remote" --head "$patch_upstream_branch_name" -R "$patch_stack_upstream_remote_url"