Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 8

GitHub Actions: get the PR ID that started it?

Solved! Go to Solution.

Hi all!

 

I'm starting with GitHub Actions, and I wanted to send a Slack notification when a PR review was submitted. This is the workflow I'm using:

 

 

workflow "Notify PR reviews" {
  on = "pull_request_review"
  resolves = ["GitHub Action for Slack"]
}

 action "On review submission" {
  uses = "actions/bin/filter@c6471707d308175c57dfe91963406ef205837dbd"
  args = "action submitted"
}

 action "GitHub Action for Slack" {
  uses = "Ilshidur/action-slack@5b3a58f5e0ff655ca9c17a22516efdf9d0de36bf"
  needs = ["On review submission"]
  secrets = ["SLACK_WEBHOOK"]
  args = "A new PR review was submitted!"
}

 

I checked the available environment variables, but I can't seem to find any that returns this info. Am I missing something?

 

Thanks!

7 Replies
Solution
GitHub Staff
Message 2 of 8

Re: GitHub Actions: get the PR ID that started it?

Hi @mrcasals!

 

You should be able to get this information by looking at the file located at the environment variable GITHUB_EVENT_PATH, you can find more information on that here: https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#envi...

 

This should contain information about the Pull Request that has triggered your action.

 

If I'm misreading anything, let me know!

Copilot Lvl 3
Message 3 of 8

Re: GitHub Actions: get the PR ID that started it?

Hi @nickvanw! Thanks for your reply!

 

I didn't realize the `GITHUB_EVENT_PATH` pointed to a file in the filesystem, guess I read that section diagonally. Thanks! I don't understand what the "payload of the event" is, though. How can I debug what this file contains? I might be missing something :(

 

I see that "any action can create [...] environment variables", as per the link you posted. Could we create an action that sets env variables based on the contents of the file, and then use those variables as args for the action that sends the message? 

GitHub Staff
Message 4 of 8

Re: GitHub Actions: get the PR ID that started it?

Hey @mrcasals!

 

It looks like you're already working with @abinoda, but if you look inside of that file you'll find that it matches the same format that's documented for our webhooks (https://developer.github.com/v3/activity/events/types/) - so if you're looking at PRs, for example, it should follow the same format here: https://developer.github.com/v3/activity/events/types/#pullrequestevent

 

From there, you should be able to parse it as JSON and extract the data yourself. It looks like @abinoda is working on a generic way to extract these, but you should be able to use your language of choice to parse the information you need from that file. 

Ground Controller Lvl 1
Message 5 of 8

Re: GitHub Actions: get the PR ID that started it?

I have just started experimenting with this....
Could you please point me to a sample of this?

 

action "GitHub Action for Slack" {
uses = "Ilshidur/action-slack@f37693b4e0589604815219454efd5cb9b404fb85"
secrets = ["SLACK_WEBHOOK"]
args =
}

 

I want a link to the PR in the args

Pilot Lvl 1
Message 6 of 8

Re: GitHub Actions: get the PR ID that started it?

@mrcasalsCan you post your use case here?

 

I'm working on creating example workflows similar to what you're describing.

Copilot Lvl 3
Message 7 of 8

Re: GitHub Actions: get the PR ID that started it?

Done, thanks!

 

Maybe it's better if we use an action to set some env variables based on the `GITHUB_EVENT_PATH` contents, and use your Slack image to send the contents of those variables, as the docs say that "any action can create [...] environment variables":

 

https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#envi...

Pilot Lvl 1
Message 8 of 8

Re: GitHub Actions: get the PR ID that started it?

@mrcasalsI think we're thinking along the same lines. I responded to your comment on that issue. If you'd like, maybe close this ticket here and we can continue collaborating on the issue thread?