Github Actions问候Bot无法在PR提交时添加评论求助
问题排查与解决方案
核心原因
actions/first-interaction@v1 这个Action的设计逻辑是仅向仓库的首次贡献者(第一次提交PR或创建Issue的用户)发送问候消息。如果提交PR的用户之前已经在该仓库有过PR、Issue提交记录,或者是仓库维护者,这个Action就不会生成评论——哪怕工作流显示执行成功。
验证方法
- 检查提交PR的用户的仓库贡献记录:确认该用户是否有过历史PR、Issue,或是仓库成员。
- 用新账号测试:找一个从未在该仓库有过任何操作的GitHub账号提交PR,验证是否能正常生成问候评论。
替代方案(给所有PR发送问候)
如果需要给**所有提交PR的用户(无论是否首次贡献)**发送问候评论,可以替换为actions/github-script实现,示例配置如下:
name: Greetings on: pull_request_target: types: [opened] jobs: greeting: runs-on: ubuntu-latest steps: - name: Greet PR Submitter uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `Hello @${context.actor}, thank you for submitting a PR! To allow your work to be integrated as seamlessly as possible, we advise you to: - Verify your PR is **up-to-date with origin/master.** - Verify all Continuous Integration (CI) **checks are passing**. - Reduce changes to the absolute **minimum** required for your bug fix or feature addition. _"It is not daily increase but daily decrease, hack away the unessential." - Bruce Lee._` })
额外注意事项
- 明确指定
pull_request_target的触发类型为opened,可以避免PR状态变更时重复执行工作流。 - 默认的
GITHUB_TOKEN已经拥有评论PR的权限,无需额外配置权限。
内容的提问来源于stack exchange,提问作者user27521614
相关产品推荐
相关产品推荐

