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

Added support for BitBucket merge hooks #193

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
$webhook_bin_template = 'r10k/webhook.bin.erb'
$webhook_yaml_template = 'r10k/webhook.yaml.erb'
$webhook_command_prefix = '' # 'sudo' is the canonical example for this
$webhook_git_provider = 'github'

if $::osfamily == 'Debian' {
$functions_path = '/lib/lsb/init-functions'
Expand Down
9 changes: 9 additions & 0 deletions manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@
$private_key_path = $r10k::params::webhook_private_key_path,
$yaml_template = $r10k::params::webhook_yaml_template,
$command_prefix = $r10k::params::webhook_command_prefix,
$git_provider = $r10k::params::webhook_git_provider,
$configfile = '/etc/webhook.yaml',
$manage_symlink = false,
$configfile_symlink = '/etc/webhook.yaml',
) inherits r10k::params {
$valid_git_providers = [
'github',
'bitbucket'
]
if ! member($valid_git_providers, $git_provider) {
fail("Webhook does not support git provider: ${git_provider}. Currently only support: ${valid_git_providers}")
}

if $hash == 'UNSET' {
$webhook_hash = {
Expand All @@ -56,6 +64,7 @@
'public_key_path' => $public_key_path,
'private_key_path' => $private_key_path,
'command_prefix' => $command_prefix,
'git_provider' => $git_provider,
}
} else {
validate_hash($hash)
Expand Down
16 changes: 14 additions & 2 deletions templates/webhook.bin.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ class Server < Sinatra::Base

data = JSON.parse(decoded, :quirks_mode => true)

module_name = ( data['repository']['name'] ).sub(/^.*-/, '')
if $config['git_provider'] == 'github'
module_name = ( data['repository']['name'] ).sub(/^.*-/, '')
elsif $config['git_provider'] == 'bitbucket'
module_name = (data['pullrequest_merged']['destination']['repository']['name']).sub(/^.*-/, '')
else
$logger.error("Unsupport git provider: #{$config['git_provider']}")
end

deploy_module(module_name)
end
Expand Down Expand Up @@ -108,7 +114,13 @@ class Server < Sinatra::Base
data = JSON.parse(decoded, :quirks_mode => true)

# github sends a 'ref', stash sends an array in 'refChanges'
branch = ( data['ref'] || data['refChanges'][0]['refId'] ).sub('refs/heads/', '')
if $config['git_provider'] == 'github'
branch = ( data['ref'] || data['refChanges'][0]['refId'] ).sub('refs/heads/', '')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code actually is not just github, its github, gitlab and stash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I gathered that when I looked at my Gitlab environment, I needed a variable name to standardize on, so I chose GitHub as in "GitHub compliant," figured githublabstash would be too messy :) I am certainly open to suggestions of change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Basically I would want to make this a required option for all services or fully automatic like it is now, My assumtion is you could just move your code data['pullrequest_merged']['destination']['branch']['name'] to the end of the || conditionals and this would work out of the box without the need for the param to exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work. I was concerned with the logic clause becoming unmanageable over time. Either way actually works for me. I can resubmit.

elsif $config['git_provider'] == 'bitbucket'
branch = data['pullrequest_merged']['destination']['branch']['name']
else
$logger.error("Unsupport git provider: #{$config['git_provider']}")
end

# If prefix is enabled in our config file run the command to determine the prefix
if $config['prefix']
Expand Down