如何使用 GitHub 操作访问 GitHub 问题评论正文?

How to access a GitHub issue comment body using GitHub Actions?

这就是您在 .github/workflows/main.yml 中为 GitHub 问题评论设置操作触发器的方式:

on:
  issue_comment:
    types: [created, edited]

假设我也可以阅读main.yml中的问题评论并将其作为输入参数传递给我的操作。

我如何真正阅读问题评论 body

对于两种事件类型:

- run: echo ${{ github.event.comment.body }}

仅限edited;编辑前获取评论正文:

- run: echo ${{ github.event.changes.body.from }}

您还可以在处理工作流程时将 one extra job 添加到您的工作流程中...

jobs:
 dump:
  runs-on: ubuntu-latest
  steps:
  - name: $github
    run:   echo "$GITHUB_CONTEXT"
    env:
     GITHUB_CONTEXT: ${{ toJson(github) }}

 # ...

...因此您可以轻松查看与触发事件相关的各种数据。

你不应该 运行 echo ${{ github.event.comment.body }},因为它可能会导致 shell 注入,从而允许攻击者执行任意代码。

运行 改为:

- name: print body
  env:
    BODY: ${{ github.event.comment.body }}
  run: echo "$BODY"

值得一读:https://securitylab.github.com/research/github-actions-untrusted-input/#remediation