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

Viewed 2610

This is how you setup the action triggers for GitHub issue comments in .github/workflows/main.yml:

on:
  issue_comment:
    types: [created, edited]

I assume that I can also read the issue comment inside main.yml and pass it as an input argument to my action.

How do I actually read the issue comment body?

2 Answers

For both event types:

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

For edited only; get comment body before edit:

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

You can also add one extra job to your workflow while you work on it...

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

 # ...

...so you can easily see all kind of data related to triggered event.

Related