Created
March 12, 2013 01:11
-
-
Save tatey/5139450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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