Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 207
Janez Kuhar Avatar asked Oct 28 '19 19:10

Janez Kuhar


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.

like image 149
Samira Avatar answered Sep 26 '22 17:09

Samira


You should not run echo ${{ github.event.comment.body }}, because it potentially causes shell injection, which allows attackers do arbitrary code execution.

Run instead:

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

Worth reading: https://securitylab.github.com/research/github-actions-untrusted-input/#remediation

like image 44
gecko655 Avatar answered Sep 23 '22 17:09

gecko655