Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine branch name or id in webhook push event?

I was ecstatic when I got a simple webhook event listener working with GitHub push events on my Azure site, but I realize now I'm not seeing the branch name or id in the json payload (example here https://developer.github.com/v3/activity/events/types/#pushevent)

I thought maybe "tree_id" would be it, but it doesn't seem to be. I couldn't find any info about this in GitHubs's doc. Maybe I need to take one of the id's from the event and make another api call to get the branch? The reason for this is I want to be able to link GitHub push events with my app portfolio, which has branches defined. So, the push events are a way to see code change activity on my different apps -- and knowing the branch is therefore important.

like image 385
Adam O'Neil Avatar asked Feb 07 '17 21:02

Adam O'Neil


People also ask

What is payload URL in GitHub webhook?

The payload URL is the URL of the server that will receive the webhook POST requests.

What is payload webhook?

The Webhook payload is sent in standard JSON format and contains an event object with the following information represented by key-value pairs (KVPs): A unique event ID. The booking lifecycle event that triggered the payload (e.g. booking. scheduled ; booking.


1 Answers

I wrote to GitHub support, and they told me that the branch name is part of the "ref" element in the root of the json payload. When parsing from a JToken object called jsonBody, the C# looks like this

var branchName = jsonBody["ref"].ToString().Split('/').Last();

For example in "refs/heads/master", the branch name is "master"

like image 74
Adam O'Neil Avatar answered Dec 20 '22 04:12

Adam O'Neil