From 5039c728cb9fd46c415c67bcc17debc0361b9da2 Mon Sep 17 00:00:00 2001 From: Danny Kim Date: Sat, 18 Jul 2026 02:25:09 +0900 Subject: [PATCH] Add Claude --- action.yml | 20 ++++++++++++++------ scripts/prompt.md | 4 ++-- scripts/run-claude.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 scripts/run-claude.sh diff --git a/action.yml b/action.yml index 920e284..982d639 100644 --- a/action.yml +++ b/action.yml @@ -1,9 +1,16 @@ -name: Codex Bot -description: Run Codex CLI for approved Gitea issue/PR automation +name: Bot agents +description: Run a coding agent for approved Gitea issue/PR automation inputs: - gitea-token: + bot-type: + description: Which bot to run, either `codex` or `claude` required: true + gitea-token: + description: Gitea access token for API calls and pushes + required: true + bot-token: + description: API key or token for the selected bot + required: false runs: using: composite @@ -14,15 +21,16 @@ runs: run: | apt-get update apt-get install -y --no-install-recommends gettext-base jq ansifilter - npm install -g @openai/codex - - name: Run Codex + npm install -g @openai/codex @anthropic-ai/claude-code + - name: Run bot shell: bash - run: bash "${ACTION_PATH}/scripts/run-codex.sh" + run: bash "${ACTION_PATH}/scripts/run-${{ inputs.bot-type }}.sh" env: ACTION_PATH: ${{ gitea.action_path }} GITEA_API_URL: ${{ gitea.api_url }} GITEA_REPOSITORY: ${{ gitea.repository }} GITEA_TOKEN: ${{ inputs.gitea-token }} + BOT_TOKEN: ${{ inputs.bot-token }} EVENT_NAME: ${{ gitea.event_name }} ISSUE_INDEX: ${{ gitea.event.issue.number || gitea.event.pull_request.number }} COMMENT: ${{ toJSON(gitea.event.comment || gitea.event.review) }} diff --git a/scripts/prompt.md b/scripts/prompt.md index a7b9fe2..9557976 100644 --- a/scripts/prompt.md +++ b/scripts/prompt.md @@ -1,4 +1,4 @@ -You are Codex running inside Gitea Actions. +You are a coding agent running inside Gitea Actions. Do not post a final issue comment yourself; your final response is posted automatically. Post additional comments only when needed for PR updates, @@ -29,7 +29,7 @@ latest branch state before pushing. Skip this check when no code changes are needed. Prefer minimal, correct changes. Run relevant checks or tests if practical. -Treat code changes as a request to create a pull request. If a prior Codex pull +Treat code changes as a request to create a pull request. If a prior bot pull request already exists for this issue, update that same pull request instead of creating a new one. When you create a pull request, include `@bot` in its body and ask it to review the pull request. This is required for every pull request diff --git a/scripts/run-claude.sh b/scripts/run-claude.sh new file mode 100644 index 0000000..80374c8 --- /dev/null +++ b/scripts/run-claude.sh @@ -0,0 +1,41 @@ +#!/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 [ -z "${BOT_TOKEN:-}" ]; then + echo 'Run `claude setup-token` locally and set the `bot-token` action input.' > "${COMMENT_FILE}" + post_comment + exit 1 +fi +export CLAUDE_CODE_OAUTH_TOKEN="${BOT_TOKEN}" + +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")" + +# Claude refuses --dangerously-skip-permissions as root outside a sandbox. +export IS_SANDBOX=1 + +claude --print --dangerously-skip-permissions "${FINAL_PROMPT}" \ + | ansifilter > "${COMMENT_FILE}" + +post_comment