#!/usr/bin/env bash set -euo pipefail git config --global user.name bot git config --global user.email noreply@capsulizers.com COMMENT_FILE="$(mktemp)" post_comment() { COMMENT_JSON="$(jq -n --rawfile body "${COMMENT_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" } if ! codex login status > /dev/null 2>&1; then codex login --device-auth 2>&1 | ansifilter > "${COMMENT_FILE}" & LOGIN_PID="${!}" sleep 3 post_comment wait "${LOGIN_PID}" codex login status 2>&1 | ansifilter > "${COMMENT_FILE}" post_comment fi 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")" codex exec \ --dangerously-bypass-approvals-and-sandbox \ --output-last-message "${COMMENT_FILE}" \ "${FINAL_PROMPT}" post_comment