feat(codex-response): 整合 Codex issue 回覆 action #2
@@ -1,51 +1,43 @@
|
|||||||
name: AI Response
|
name: AI Response
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types:
|
types:
|
||||||
- created
|
- created
|
||||||
|
|
||||||
jobs:
|
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:
|
response:
|
||||||
name: 回覆問題留言
|
name: 回覆問題留言
|
||||||
runs-on: ubuntu
|
runs-on: ubuntu
|
||||||
if: ${{ contains(github.event.comment.body, '@opencode') }}
|
needs: [version]
|
||||||
|
if: ${{ contains(github.event.comment.body, '@codex') }}
|
||||||
steps:
|
steps:
|
||||||
- name: 安裝 OpenCode
|
- name: 取得專案
|
||||||
run: npm install -g opencode-ai
|
uses: actions/checkout@v6
|
||||||
|
- name: 產生並留言 AI 回覆
|
||||||
- name: 產生 AI 回覆
|
uses: https://gitea.jsc.idv.tw/actions/codex-response@v${{ needs.version.outputs.version }}
|
||||||
env:
|
with:
|
||||||
COMMENT_BODY: ${{ github.event.comment.body }}
|
gitea_server_url: ${{ gitea.server_url }}
|
||||||
ISSUE_BODY: ${{ github.event.issue.body }}
|
gitea_repository: ${{ gitea.repository }}
|
||||||
ISSUE_TITLE: ${{ github.event.issue.title }}
|
gitea_token: ${{ secrets.GITEA_TOKEN }}
|
||||||
NO_COLOR: "1"
|
oauth: ${{ secrets.CODEX_OAUTH }}
|
||||||
TERM: dumb
|
model: gpt-5.4-mini
|
||||||
run: |
|
issue_title: ${{ github.event.issue.title }}
|
||||||
clean_comment="$(printf '%s' "$COMMENT_BODY" | sed -E 's/@opencode[[:space:]]*//g')"
|
issue_body: ${{ github.event.issue.body }}
|
||||||
|
issue_number: ${{ github.event.issue.number }}
|
||||||
{
|
comment_body: ${{ github.event.comment.body }}
|
||||||
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"
|
|
||||||
|
|||||||
+70
-33
@@ -1,53 +1,90 @@
|
|||||||
name: 'Composite Action Template'
|
name: 'Codex Issue Response'
|
||||||
description: 'Composite Action 範本'
|
description: '使用 Codex 產生 Gitea issue 留言回覆'
|
||||||
author: 'Jeffery'
|
author: 'Jeffery'
|
||||||
inputs:
|
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'
|
description: 'Gitea Runner Token'
|
||||||
required: true
|
required: true
|
||||||
text:
|
oauth:
|
||||||
description: '輸入的文字'
|
description: 'Base64 encoded Codex auth.json'
|
||||||
default: "Hello, World!"
|
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:
|
outputs:
|
||||||
text:
|
status:
|
||||||
description: '輸出的文字'
|
description: 'Codex execution result status'
|
||||||
value: ${{ steps.display.outputs.text }}
|
value: ${{ steps.codex.outputs.status }}
|
||||||
|
response:
|
||||||
|
description: 'Codex execution result response'
|
||||||
|
value: ${{ steps.codex.outputs.output }}
|
||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
- name: 取得專案
|
- name: 建立 Prompt
|
||||||
uses: actions/checkout@v6
|
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 回覆
|
- name: 產生 AI 回覆
|
||||||
id: response
|
id: codex
|
||||||
uses: https://gitea.jsc.idv.tw/actions/codex@v0.0.2
|
uses: https://gitea.jsc.idv.tw/actions/codex@v0.0.2
|
||||||
with:
|
with:
|
||||||
OAUTH: ${{ secrets.CODEX_OAUTH }}
|
oauth: ${{ inputs.oauth }}
|
||||||
MODEL: gpt-5.4-mini
|
model: ${{ inputs.model }}
|
||||||
PROMPT: |
|
prompt: ${{ steps.prompt.outputs.prompt }}
|
||||||
請根據以下 Gitea issue 資訊,以繁體中文回覆使用者。
|
|
||||||
請只輸出要張貼到 issue 留言中的內容,不要包含額外前言。
|
|
||||||
|
|
||||||
## 問題標題
|
|
||||||
${{ github.event.issue.title }}
|
|
||||||
|
|
||||||
## 問題描述
|
|
||||||
${{ github.event.issue.body }}
|
|
||||||
|
|
||||||
## 使用者留言
|
|
||||||
${{ github.event.comment.body }}
|
|
||||||
- name: 留言 AI 回覆
|
- name: 留言 AI 回覆
|
||||||
env:
|
env:
|
||||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
GITEA_REPOSITORY: ${{ inputs.gitea_repository }}
|
||||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
GITEA_SERVER_URL: ${{ inputs.gitea_server_url }}
|
||||||
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
GITEA_TOKEN: ${{ inputs.gitea_token }}
|
||||||
RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
ISSUE_NUMBER: ${{ inputs.issue_number }}
|
||||||
|
RESPONSE: ${{ steps.codex.outputs.output }}
|
||||||
run: |
|
run: |
|
||||||
jq -n --rawfile body response.md '{body: $body}' > comment.json
|
jq -n --arg body "$RESPONSE" '{body: $body}' > comment.json
|
||||||
|
|
||||||
curl --fail-with-body \
|
curl --fail-with-body \
|
||||||
-X POST \
|
-X POST \
|
||||||
-H "Authorization: token $RUNNER_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data @comment.json \
|
--data @comment.json \
|
||||||
"$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/issues/$ISSUE_NUMBER/comments"
|
"$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/issues/$ISSUE_NUMBER/comments"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
Reference in New Issue
Block a user
嚴重等級:🔵 建議
審查員:Bard
問題:在
cat <<EOF的 heredoc 內容中,直接寫入縮排會導致產生的 Prompt 內容包含不必要的左側空白,影響 AI 接收到的格式。建議:建議改用
cat <<-EOF並搭配適當的縮排處理,確保輸出給 AI 的 Prompt 內容乾淨、無不必要的縮排。