diff --git a/lib/helpers/data_parsers.rb b/lib/helpers/data_parsers.rb index 24065fe..638441e 100644 --- a/lib/helpers/data_parsers.rb +++ b/lib/helpers/data_parsers.rb @@ -15,19 +15,4 @@ def verify_signature(payload_body) signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), settings.github_secret, payload_body) throw(:halt, [500, "Signatures didn't match!\n"]) unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE']) end - - # rubocop:disable Style/RescueModifier - # TODO: Move the code from these methods to our parser class - def repo_name(data) - # Only tested with Github - # TODO: Extend for Bitbucket, Bitbucket Server, and Gitlab - data['repository']['name'] rescue nil - end - - def repo_user(data) - # Only tested with Github - # TODO: Extend for Bitbucket, Bitbucket Server, and Gitlab - data['repository']['owner']['login'] rescue nil - end - # rubocop:enable Style/RescueModifier end diff --git a/lib/parsers/webhook_json_parser.rb b/lib/parsers/webhook_json_parser.rb index 07e7e31..c7dd92c 100644 --- a/lib/parsers/webhook_json_parser.rb +++ b/lib/parsers/webhook_json_parser.rb @@ -8,8 +8,10 @@ def call(body) @data = JSON.parse(body, quirks_mode: true) @vcs = detect_vcs { - branch: branch, - deleted: deleted? + branch: branch, + deleted: deleted?, + repo_name: repo_name, + repo_user: repo_user } end @@ -96,6 +98,26 @@ def deleted? false end end + + def repo_name + case @vcs + when 'github' + @data['repository']['name'] + when 'gitlab' + @data['project']['name'] + end + # TODO: Bitbucket, Stash/Bitbucket Server, TFS + end + + def repo_user + case @vcs + when 'github' + @data['repository']['owner']['login'] + when 'gitlab' + @data['user_username'] + end + # TODO: Bitbucket, Stash/Bitbucket Server, TFS + end end end end diff --git a/lib/puppet_webhook.rb b/lib/puppet_webhook.rb index b67c030..13a61da 100644 --- a/lib/puppet_webhook.rb +++ b/lib/puppet_webhook.rb @@ -96,9 +96,9 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation # If prefix is enabled in our config file, determine what the prefix should be prefix = case settings.prefix when :repo - repo_name(data) + params['repo_name'] when :user - repo_user(data) + params['repo_user'] when :command, TrueClass run_prefix_command(data.to_json) when String