Skip to content

Commit

Permalink
Cleanup unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Feb 7, 2023
1 parent 2705401 commit 15a6344
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions src/api/app/models/github_payload_extractor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class GithubPayloadExtractor < ScmPayloadExtractor
EVENT_CLASSES = {
'pull_request' => Github::PullRequest,
'push' => Github::Push
}.freeze

attr_reader :event, :webhook_payload

def initialize(event, webhook_payload)
Expand All @@ -8,33 +13,7 @@ def initialize(event, webhook_payload)
end

def payload
payload = {
scm: 'github',
event: event,
api_endpoint: github_api_endpoint
}

case event
when 'pull_request'
return Github::PullRequest.new(event, webhook_payload).payload
when 'push' # GitHub doesn't have different push events for commits and tags
return Github::Push.new(event, webhook_payload).payload
end

payload
end

private

def github_api_endpoint
sender_url = webhook_payload.dig(:sender, :url)
return unless sender_url

host = URI.parse(sender_url).host
if host.start_with?('api.github.com')
"https://#{host}"
else
"https://#{host}/api/v3/"
end
# TODO: Implement a null object for when we don't hit any event class
EVENT_CLASSES[event].new(event, webhook_payload).payload
end
end

0 comments on commit 15a6344

Please sign in to comment.