feat: add AI issue response workflow
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
name: AI Response
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types:
|
||||
- created
|
||||
|
||||
jobs:
|
||||
response:
|
||||
name: 回覆問題留言
|
||||
runs-on: ubuntu
|
||||
if: ${{ contains(github.event.comment.body, '@opencode') }}
|
||||
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"
|
||||
Reference in New Issue
Block a user