Files
2026-07-13 12:35:20 +08:00

76 lines
2.0 KiB
YAML

name: Create PR
on:
workflow_dispatch:
inputs:
issue_number:
description: "Issue 编号(从 Claude 回复中解析 PR 信息)"
required: false
type: string
jobs:
create-branch-and-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: 启用 Corepack
run: corepack enable
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
version: 10.30.3
- name: 设置 Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: 安装依赖
uses: nick-invision/retry@v3
with:
timeout_minutes: 5
max_attempts: 2
retry_on: error
command: pnpm install
- name: 创建PR
id: parse
if: ${{ github.event.inputs.issue_number != '' }}
env:
ISSUE_NUMBER: ${{ github.event.inputs.issue_number }}
GH_TOKEN: ${{ github.token }}
run: |
output=$(npx tsx scripts/parse-claude-reply.ts --issue "$ISSUE_NUMBER" 2>&1)
echo "$output"
result=$(echo "$output" | sed -n '/^{/,/^}/p')
echo "$result"
# 提取各个字段
branch_name=$(echo "$result" | jq -r .branchName)
pr_title=$(echo "$result" | jq -r .title)
pr_body=$(echo "$result" | jq -r .body)
# 输出到 GITHUB_OUTPUT(使用 heredoc 处理多行)
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
echo "pr_title=$pr_title" >> $GITHUB_OUTPUT
# 使用 heredoc 处理多行 body
echo "pr_body<<EOF" >> $GITHUB_OUTPUT
echo "$pr_body" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
gh pr create \
--base main \
--head "$branch_name" \
--title "$pr_title" \
--body "$pr_body" \