Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Bitbucket webhook pull request event type #539

Open
magarvo opened this issue Sep 30, 2020 · 0 comments
Open

Support Bitbucket webhook pull request event type #539

magarvo opened this issue Sep 30, 2020 · 0 comments

Comments

@magarvo
Copy link

magarvo commented Sep 30, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant