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

Commit

Permalink
Move repo_user/name parsing to webhook_json_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjfisher committed Nov 2, 2017
1 parent 50355a8 commit 4db317f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
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
24 changes: 22 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,24 @@ def deleted?
false
end
end

def repo_name
case @vcs
when 'github'
@data['repository']['name']
end
# TODO: Bitbucket, Stash/Bitbucket Server, Gitlab, TFS
nil
end

def repo_user
case @vcs
when 'github'
@data['repository']['owner']['login']
end
# TODO: Bitbucket, Stash/Bitbucket Server, Gitlab, TFS
nil
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

0 comments on commit 4db317f

Please sign in to comment.