他人向我的仓库提交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
相关产品推荐
相关产品推荐

