3

I'm wondering if there is a way to get the commits in a push event from @actions/github?

I tried GitHub.context.payload.comment, but that's returning undefined.

Is there a way to do it in javascript/typescript?

Thanks.

Simo
  • 77
  • 2
  • 9
  • 1
    You can get this in the `github context` for the action, as described here: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context The event key will give you the webhook content, as defined here: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#push So you can use something like `${{ github.event.head_commit.message }}` – GuiFalourd Apr 08 '21 at 13:38
  • It is also possible to get the commit messages with the `git log` command if you use bash: `git log -1 --pretty=format:"%s"` – GuiFalourd Apr 08 '21 at 13:39
  • I'm writing my own action so I'm looking to get the commit messages programmatically in javascript. What you said can be passed to my action as an input from the workflow file, but I am wondering if this information can get extracted directly in the js code. – Simo Apr 08 '21 at 15:50
  • 1
    Also, wouldn't `github.event.head_commit.message` only give the last commit and not all the commits in the push? – Simo Apr 08 '21 at 15:51
  • Yes, the head will give you the last one. Now, regarding how to get comments from you script, it might be possible through the github api. Otherwise you can do it in your script doing something like the answer from this question: https://stackoverflow.com/questions/9179828/github-api-retrieve-all-commits-for-all-branches-for-a-repo – GuiFalourd Apr 09 '21 at 00:36

0 Answers0