set -eu
: "${RK_REPO:?rk sets this; run this script through rk setup}"
: "${RK_BOT_INSTALLATION:?rk sets this; run this script through rk setup}"
repo_id="$(gh api "repos/$RK_REPO" -q .id)"
if ! gh api -X PUT "user/installations/$RK_BOT_INSTALLATION/repositories/$repo_id" >/dev/null; then
echo 'FAIL the forge refused the grant' >&2
echo 'remediation: put a classic personal access token with repo scope in GH_TOKEN, or add the repository by hand under github.com/settings/installations' >&2
exit 1
fi
echo "granted $RK_REPO to installation $RK_BOT_INSTALLATION"