You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

他人向我的仓库提交Pull Request时Workflow报错求助

问题分析

你的GitHub Workflow处理Issue正常,但处理Pull Request时报错,核心原因是gh pr comment命令不支持直接传入PR的HTML URL作为目标参数,而你当前代码里用了${{ github.event.pull_request.html_url }},这会导致命令执行失败。

修复方案

将Pull Request分支的命令参数从HTML URL替换为PR编号,gh pr comment可以直接识别PR编号。修改后的完整Workflow代码如下:

name: Greetings
on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened

jobs:
  Greetings:
    runs-on: ubuntu-latest
    steps:
      - env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if [[ "${{ github.event_name }}" == "issues" ]]; then
            gh issue comment ${{ github.event.issue.html_url }} --body "@${{ github.event.issue.user.login }}
            
            Thank you for raising this issue! 🎉🙌
            
            We truly appreciate your contribution to this project and will review the details shortly. 🛠️✨
            We will get back to you soon!
            
            Thank you for your patience! 🙏"
          elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # 改用PR编号作为gh pr comment的参数
            gh pr comment ${{ github.event.pull_request.number }} --body "@${{ github.event.pull_request.user.login }}
            
            Thank you for your Pull Request!
            
            We truly appreciate your contribution! 🙌
            We will review the changes and provide feedback or merge the PR soon. 🔍
            Please stay tuned for updates! 🔔
            
            🌟 Thank you for your efforts in improving the project! 🙏"
          fi
额外说明
  • gh issue comment支持传入Issue的HTML URL是因为命令内部做了兼容解析,但gh pr comment并未提供该兼容,必须使用PR编号、PR的完整仓库路径+编号(如octocat/hello-world#123)或者PR的SSH/HTTPS克隆地址。
  • 你已配置的读写权限足够支持该命令执行,无需额外调整权限设置。

内容的提问来源于stack exchange,提问作者Om Maniya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 14:00:58