Skip to content

Commit

Permalink
Merge pull request #79 from idobata/review-request-events
Browse files Browse the repository at this point in the history
Support review request events
  • Loading branch information
hibariya authored May 12, 2017
2 parents 6c2fd37 + ad7124f commit ad58dbf
Show file tree
Hide file tree
Showing 4 changed files with 997 additions and 10 deletions.
35 changes: 25 additions & 10 deletions lib/hooks/github/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ def md(source)
end

def render_action(payload, suffix)
if labeled_action?(payload.action)
case payload.action
when 'labeled', 'unlabeled'
render_labeled(payload)
elsif assigned_action?(payload.action)
when 'assigned', 'unassigned'
render_assigned(payload)
when 'review_requested'
render_review_request(payload)
when 'review_request_removed'
render_review_request_removed(payload)
else
action = payload.pull_request.try(:merged) ? 'merged' : payload.action # `payload.action` is 'closed' on merge.

Expand All @@ -56,10 +61,6 @@ def render_action(payload, suffix)

private

def labeled_action?(action)
%w(labeled unlabeled).include?(action)
end

def render_labeled(payload)
render_as_haml(<<-'HAML'.strip_heredoc, payload: payload)
= payload.action
Expand All @@ -68,10 +69,6 @@ def render_labeled(payload)
HAML
end

def assigned_action?(action)
%w(assigned unassigned).include?(payload.action)
end

def render_assigned(paylaod)
render_as_haml(<<-HAML.strip_heredoc, payload: payload)
= payload.action
Expand All @@ -81,6 +78,24 @@ def render_assigned(paylaod)
HAML
end

def render_review_request(paylaod)
render_as_haml(<<-HAML.strip_heredoc, payload: payload)
requested
%span= avatar_image_tag payload.requested_reviewer.avatar_url
%a{href: payload.requested_reviewer.html_url}= payload.requested_reviewer.login
to review
HAML
end

def render_review_request_removed(paylaod)
render_as_haml(<<-HAML.strip_heredoc, payload: payload)
removed
a review request for
%span= avatar_image_tag payload.requested_reviewer.avatar_url
%a{href: payload.requested_reviewer.html_url}= payload.requested_reviewer.login
HAML
end

def render_as_haml(haml, locals)
Haml::Engine.new(haml, escape_html: true).render(self, locals)
end
Expand Down
Loading

0 comments on commit ad58dbf

Please sign in to comment.