Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Move repo_user/name parsing to webhook_json_parser #14

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 0 additions & 15 deletions lib/helpers/data_parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 24 additions & 2 deletions lib/parsers/webhook_json_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/puppet_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down