I was working on automating an integration between Jira and Github where a ticket transitions its state (in progress -> code review -> done) through a workflow based on the status / lifecycle of a pull request.
Pull request created: ticket transitions to code review state
Pull request merged: ticket transitions to done state
The issue I'm having is how to send enough data for the Jira automation process. Developers commit messages include ticket ID's (git commit -m 'ID-22, <commit message here>
) that I am looking for, I also need to know pull request data to know the status of the PR.
When configuring the webhook for this, I selected to receive events for both pull requests as well as pushes to be sent to my Jira automation workflow.
The events are sent individually, which is the main issue as I need both events to apply the ticket automation. For instance this is the commit webhook, which successfully found the ticket from a commit, however pull request data is missing so there was no action it could take.
The very next event is the pull request event which cannot find the ticket because it lacks commits in the payload.
Is there an event that I can use that includes data about commits and PR's? I would prefer to avoid setting up a bot / server to merge these together if possible.
I could technically make the pull request event work (by itself) if the branch name included the ticket, however that requires a change in process + a lot of the time pull requests will include fixes for multiple tickets, branch name strategy is too 1:1. Ideally I'd like to discover tickets from the commit messages
Thanks for reading!
My experience with using GitHub APIs: commits and pull requests are not associated to each other. So a pull request event has no context of any commits, vice versa.
That being said, it's still doable:
Use "pull requests" event, which fires off every time there is an event of the pull request itself, such as opened, synchronized (new commit), ready for review, etc.
Then:
Option 1. With the pull request info, query GitHub API to get commit info: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request.
Option 2. Not only let developers mention work ID in their commits, let them mention work ID in PR title as well, that way you don't need to make a separate API call, since PR title is included in pull request event payload (https://developer.github.com/webhooks/event-payloads/#pull_request)