Skip to content

Instantly share code, notes, and snippets.

@hamelsmu
Last active April 2, 2021 06:03
Show Gist options
  • Save hamelsmu/4d671aae3d51f972f56e40da9c677f69 to your computer and use it in GitHub Desktop.
Save hamelsmu/4d671aae3d51f972f56e40da9c677f69 to your computer and use it in GitHub Desktop.
What is the payload field for determining the draft status of a PR for GitHub Actions?
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hamelsmu
Copy link
Author

hamelsmu commented Apr 1, 2021

The next question might be, where do I put this if statement? You can filter a workflow like this

Put your if statement here 👇 instead

name: Chatops
on: [issue_comment]

jobs:
  trigger-chatops:
    if: (github.event.issue.pull_request != null) &&  contains(github.event.comment.body, '/preview') 
...

@hamelsmu
Copy link
Author

hamelsmu commented Apr 1, 2021

@hamelsmu
Copy link
Author

hamelsmu commented Apr 1, 2021

You might be wonedering what this means

if: (github.event.issue.pull_request != null) && contains(github.event.comment.body, '/preview')

In the backend, GitHub PRs are a special kind of issue. So you might want to trigger something to happen when you comment on PRs, not Issues.

To make sure an issue_comment is actually a PR comment, you have to use this filter

github.event.issue.pull_request != null

Finally, if you want to inspect a comment for the presence of a string, you can use the built-in function contains

contains(github.event.comment.body, '/preview')

You can learn more about the built in functions here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment