From 1d3f17e0f27498829c8200458d4592044499e899 Mon Sep 17 00:00:00 2001 From: Danny Kim Date: Thu, 9 Jul 2026 09:12:30 +0900 Subject: [PATCH] Pass Codex login request to comment --- scripts/run-codex.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/run-codex.sh b/scripts/run-codex.sh index fec56eb..95ff125 100644 --- a/scripts/run-codex.sh +++ b/scripts/run-codex.sh @@ -4,6 +4,27 @@ set -euo pipefail git config --global user.name bot git config --global user.email noreply@capsulizers.com +OUTPUT_FILE="$(mktemp)" + +post_comment() { + 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" +} + +if ! codex login status > /dev/null 2>&1; then + codex login --device-auth > "${OUTPUT_FILE}" 2>&1 & + LOGIN_PID="${!}" + sleep 3 + post_comment + wait "${LOGIN_PID}" + exit 1 +fi + export ISSUE_COMMENTS="$( curl --fail-with-body --silent --show-error \ -H "Authorization: token ${GITEA_TOKEN}" \ @@ -12,21 +33,9 @@ export ISSUE_COMMENTS="$( )" FINAL_PROMPT="$(envsubst < "${ACTION_PATH}/scripts/prompt.md")" -OUTPUT_FILE="$(mktemp)" -set +e codex exec \ --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}" +post_comment