From the doc you linked, the push property contains:
The details of the push, which includes the changes property. This property contains an array with all the references that the push updated and the following properties:
So no, you can't just look at the first value. If the user pushes multiple branches at once (git push origin --all
, for example), you may have multiple objects in the changes
array. For instance, one branch could have been deleted, another one created (old
would be null), and a third could have been updated. So in processing these push events, you should make sure to handle multiple possible reference updates at once.
How to most reliably get latest hash
What exactly are you trying to accomplish by getting the latest hash? If you just need to record all the hashes, it should suffice to just map over the changes
array, e.g.
const hashes = body.push.changes.map(change => change.new.target.hash);
But it seems like you're making the assumption that you can handle repository changes one at a time. This is most likely false -- someone can clone a repository, change a ton of branches in diverging ways, and push (or force push!) those changes up.
pullrequest
field with this kind of object: confluence.atlassian.com/bitbucket/… which in turn has asource
anddestination
field that contains the commits you're interested in. – Fag