puppet-r10k
puppet-r10k copied to clipboard
Support Bitbucket webhook pull request event type
Affected Puppet, Ruby, OS and module versions/distributions
- Puppet: 6.12.1-1.el7
- Ruby: 2.0.0p648
- Distribution: CentOS 7.8.2003
- Module version: 9.0.0
I have deployed r10k/webhook using the Puppet module provided in the Puppet forge (puppet-r10k ).
I'm looking to trigger a deployment based on webhooks from Bitbucket.
- During testing I've been able to trigger an environment deployment manually ('r10k deoploy environment').
- Also sucessful in triggering a webhook for a 'Repository' event (push, modified etc).
- But I've been without success using the 'Pull request' event (merge, opened etc).
The event payload for a pull request event type is different than a 'Repository' event type and needs to be handled separately. https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/
The problem is that the branch name can't be read and the script continues with a NilClass variable.
[2020-09-29 15:04:28] INFO module or branch name '' had to be escaped!
[2020-09-29 15:04:28] INFO Deploying environment '' in the background
# Iterate the data structure to determine what's should be deployed
branch = (
data['ref'] || # github & gitlab
data['refChanges'][0]['refId'] rescue nil || # stash
data['push']['changes'][0]['new']['name'] rescue nil || # bitbucket
data['changes'][0]['ref']['displayId'] rescue nil || # bitbucket server repository event
data['pullRequest']['fromRef']['displayId'] rescue nil || # bitbucket server pull request event << Added this
data['resource']['refUpdates'][0]['name'] rescue nil || # TFS/VisualStudio-Git
data['repository']['default_branch'] # github tagged release; no ref.
).sub('refs/heads/', '') rescue nil