feat(codex-response): 整合 Codex issue 回覆 action
This commit is contained in:
@@ -1,51 +1,43 @@
|
||||
name: AI Response
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types:
|
||||
- created
|
||||
|
||||
jobs:
|
||||
version:
|
||||
name: 計算版本號
|
||||
runs-on: ubuntu
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
steps:
|
||||
- name: 計算版本號
|
||||
id: version
|
||||
uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }}
|
||||
with:
|
||||
IS_BETA: true
|
||||
- name: 標註版本號
|
||||
uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }}
|
||||
with:
|
||||
name: codex v${{ steps.version.outputs.version }}
|
||||
tag_name: v${{ steps.version.outputs.version }}
|
||||
target_commitish: ${{ github.head_ref }}
|
||||
response:
|
||||
name: 回覆問題留言
|
||||
runs-on: ubuntu
|
||||
if: ${{ contains(github.event.comment.body, '@opencode') }}
|
||||
needs: [version]
|
||||
if: ${{ contains(github.event.comment.body, '@codex') }}
|
||||
steps:
|
||||
- name: 安裝 OpenCode
|
||||
run: npm install -g opencode-ai
|
||||
|
||||
- name: 產生 AI 回覆
|
||||
env:
|
||||
COMMENT_BODY: ${{ github.event.comment.body }}
|
||||
ISSUE_BODY: ${{ github.event.issue.body }}
|
||||
ISSUE_TITLE: ${{ github.event.issue.title }}
|
||||
NO_COLOR: "1"
|
||||
TERM: dumb
|
||||
run: |
|
||||
clean_comment="$(printf '%s' "$COMMENT_BODY" | sed -E 's/@opencode[[:space:]]*//g')"
|
||||
|
||||
{
|
||||
printf '請根據以下 Gitea issue 資訊,以繁體中文回覆使用者。\n'
|
||||
printf '請只輸出要張貼到 issue 留言中的內容,不要包含額外前言。\n\n'
|
||||
printf '## 問題標題\n%s\n\n' "$ISSUE_TITLE"
|
||||
printf '## 問題描述\n%s\n\n' "$ISSUE_BODY"
|
||||
printf '## 使用者留言\n%s\n' "$clean_comment"
|
||||
} > prompt.md
|
||||
|
||||
opencode run --agent plan "$(cat prompt.md)" > response.md
|
||||
|
||||
- name: 留言到問題
|
||||
env:
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
||||
RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
||||
run: |
|
||||
jq -n --rawfile body response.md '{body: $body}' > comment.json
|
||||
|
||||
curl --fail-with-body \
|
||||
-X POST \
|
||||
-H "Authorization: token $RUNNER_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data @comment.json \
|
||||
"$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/issues/$ISSUE_NUMBER/comments"
|
||||
- name: 取得專案
|
||||
uses: actions/checkout@v6
|
||||
- name: 產生並留言 AI 回覆
|
||||
uses: https://gitea.jsc.idv.tw/actions/codex-response@v${{ needs.version.outputs.version }}
|
||||
with:
|
||||
gitea_server_url: ${{ gitea.server_url }}
|
||||
gitea_repository: ${{ gitea.repository }}
|
||||
gitea_token: ${{ secrets.GITEA_TOKEN }}
|
||||
oauth: ${{ secrets.CODEX_OAUTH }}
|
||||
model: gpt-5.4-mini
|
||||
issue_title: ${{ github.event.issue.title }}
|
||||
issue_body: ${{ github.event.issue.body }}
|
||||
issue_number: ${{ github.event.issue.number }}
|
||||
comment_body: ${{ github.event.comment.body }}
|
||||
|
||||
+70
-33
@@ -1,53 +1,90 @@
|
||||
name: 'Composite Action Template'
|
||||
description: 'Composite Action 範本'
|
||||
name: 'Codex Issue Response'
|
||||
description: '使用 Codex 產生 Gitea issue 留言回覆'
|
||||
author: 'Jeffery'
|
||||
inputs:
|
||||
runner_token:
|
||||
gitea_server_url:
|
||||
description: 'Gitea server URL'
|
||||
required: true
|
||||
gitea_repository:
|
||||
description: 'Gitea repository, for example owner/repo'
|
||||
required: true
|
||||
gitea_token:
|
||||
description: 'Gitea Runner Token'
|
||||
required: true
|
||||
text:
|
||||
description: '輸入的文字'
|
||||
default: "Hello, World!"
|
||||
oauth:
|
||||
description: 'Base64 encoded Codex auth.json'
|
||||
required: true
|
||||
model:
|
||||
description: 'Codex model name'
|
||||
default: 'gpt-5.4-mini'
|
||||
issue_title:
|
||||
description: 'Issue title'
|
||||
required: true
|
||||
issue_body:
|
||||
description: 'Issue body'
|
||||
required: false
|
||||
default: ''
|
||||
issue_number:
|
||||
description: 'Issue number'
|
||||
required: true
|
||||
comment_body:
|
||||
description: 'Issue comment body'
|
||||
required: true
|
||||
outputs:
|
||||
text:
|
||||
description: '輸出的文字'
|
||||
value: ${{ steps.display.outputs.text }}
|
||||
status:
|
||||
description: 'Codex execution result status'
|
||||
value: ${{ steps.codex.outputs.status }}
|
||||
response:
|
||||
description: 'Codex execution result response'
|
||||
value: ${{ steps.codex.outputs.output }}
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: 取得專案
|
||||
uses: actions/checkout@v6
|
||||
- name: 建立 Prompt
|
||||
id: prompt
|
||||
env:
|
||||
ISSUE_TITLE: ${{ inputs.issue_title }}
|
||||
ISSUE_BODY: ${{ inputs.issue_body }}
|
||||
COMMENT_BODY: ${{ inputs.comment_body }}
|
||||
run: |
|
||||
clean_comment="${COMMENT_BODY//@codex/}"
|
||||
clean_comment="$(printf '%s' "$clean_comment" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
||||
|
||||
{
|
||||
printf '請根據以下 Gitea issue 資訊,以繁體中文回覆使用者。\n'
|
||||
printf '請只輸出要張貼到 issue 留言中的內容,不要包含額外前言。\n\n'
|
||||
printf '## 問題標題\n%s\n\n' "$ISSUE_TITLE"
|
||||
printf '## 問題描述\n%s\n\n' "$ISSUE_BODY"
|
||||
printf '## 使用者留言\n%s\n' "$clean_comment"
|
||||
} > prompt.md
|
||||
|
||||
{
|
||||
echo 'prompt<<__PROMPT__'
|
||||
cat prompt.md
|
||||
echo '__PROMPT__'
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
shell: bash
|
||||
- name: 產生 AI 回覆
|
||||
id: response
|
||||
id: codex
|
||||
uses: https://gitea.jsc.idv.tw/actions/codex@v0.0.2
|
||||
with:
|
||||
OAUTH: ${{ secrets.CODEX_OAUTH }}
|
||||
MODEL: gpt-5.4-mini
|
||||
PROMPT: |
|
||||
請根據以下 Gitea issue 資訊,以繁體中文回覆使用者。
|
||||
請只輸出要張貼到 issue 留言中的內容,不要包含額外前言。
|
||||
|
||||
## 問題標題
|
||||
${{ github.event.issue.title }}
|
||||
|
||||
## 問題描述
|
||||
${{ github.event.issue.body }}
|
||||
|
||||
## 使用者留言
|
||||
${{ github.event.comment.body }}
|
||||
oauth: ${{ inputs.oauth }}
|
||||
model: ${{ inputs.model }}
|
||||
prompt: ${{ steps.prompt.outputs.prompt }}
|
||||
- name: 留言 AI 回覆
|
||||
env:
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
||||
RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
||||
GITEA_REPOSITORY: ${{ inputs.gitea_repository }}
|
||||
GITEA_SERVER_URL: ${{ inputs.gitea_server_url }}
|
||||
GITEA_TOKEN: ${{ inputs.gitea_token }}
|
||||
ISSUE_NUMBER: ${{ inputs.issue_number }}
|
||||
RESPONSE: ${{ steps.codex.outputs.output }}
|
||||
run: |
|
||||
jq -n --rawfile body response.md '{body: $body}' > comment.json
|
||||
jq -n --arg body "$RESPONSE" '{body: $body}' > comment.json
|
||||
|
||||
curl --fail-with-body \
|
||||
-X POST \
|
||||
-H "Authorization: token $RUNNER_TOKEN" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data @comment.json \
|
||||
"$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/issues/$ISSUE_NUMBER/comments"
|
||||
shell: bash
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user