diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 3c952f4..6cbf069 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -64,29 +64,26 @@ jobs: - name: Create Pull Request if: env.branch_exists == 'false' id: create_pr - run: | - response=$(curl -s -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{ - "title": "Auto PR from ${{ env.branch_name }}", - "body": "This is an automated PR created from ${{ env.branch_name }}", - "head": "${{ env.branch_name }}", - "base": "main" - }' \ - https://api.github.com/repos/${{ github.repository }}/pulls) - - echo "response=$response" >> $GITHUB_ENV - echo "PR creation response: $response" + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.branch_name }} + base: main + title: "Auto PR from ${{ env.branch_name }}" + body: "This is an automated PR created from ${{ env.branch_name }}" + draft: false - name: Wait for PR creation if: env.branch_exists == 'false' - run: sleep 30 # 等待 30 秒,确保 PR 被创建 + run: sleep 20 # 等待 20 秒,确保 PR 被创建 - name: Get PR number if: env.branch_exists == 'false' + id: get_pr_number + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - pr_number=$(echo "${{ env.response }}" | jq -r .number) + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV echo "PR number: $pr_number"