Files
bot-agents/scripts/run-codex.sh
T

34 lines
1023 B
Bash

#!/usr/bin/env bash
set -euo pipefail
git config --global user.name bot
git config --global user.email noreply@capsulizers.com
export ISSUE_COMMENTS="$(
curl --fail-with-body --silent --show-error \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments?limit=100" \
| jq -r '.[] | "## " + .user.login + " at " + .created_at + "\n\n" + .body + "\n"'
)"
FINAL_PROMPT="$(envsubst < "${ACTION_PATH}/scripts/prompt.md")"
OUTPUT_FILE="$(mktemp)"
set +e
codex exec \
--full-auto \
--dangerously-bypass-approvals-and-sandbox \
"${FINAL_PROMPT}" > "${OUTPUT_FILE}" 2>&1
CODEX_STATUS="${?}"
set -e
COMMENT_JSON="$(jq -n --rawfile body "${OUTPUT_FILE}" '{body: $body}')"
curl --fail-with-body --silent --show-error \
-X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
--data "${COMMENT_JSON}" \
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments"
exit "${CODEX_STATUS}"