Skip to content

Instantly share code, notes, and snippets.

@tatey
Created March 12, 2013 01:11
Show Gist options
  • Save tatey/5139450 to your computer and use it in GitHub Desktop.
Save tatey/5139450 to your computer and use it in GitHub Desktop.
class Hook
attr_reader :payload
def initialize(payload)
@payload = payload
end
def operation_attributes
send(:"#{action}_operation_attributes")
end
def action
case
when create_or_push? then Operation::Actions.deploy
when delete? then Operation::Actions.teardown
end
end
def branch
payload['ref'].match(/[^\/]+\Z/).to_s
end
protected
def create_or_push?
payload.fetch('created') ||
!payload.fetch('created') && !payload.fetch('deleted')
end
def delete?
payload.fetch('deleted')
end
def deploy_operation_attributes
{
action: action,
head_commit_id: head_commit['id'],
head_commit_url: head_commit['url']
}
end
def teardown_operation_attributes
{action: action}
end
def head_commit
payload['head_commit']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment