From c9db6bb3f2bea55cbb2bf3073cbb2a4c73c104fa Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 2 Apr 2012 19:51:20 +0300 Subject: [PATCH] prevent app crash for events without git resources --- app/models/event/push_trait.rb | 14 ++++++++++++++ app/views/events/_event_push.html.haml | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/event/push_trait.rb b/app/models/event/push_trait.rb index 7ed0c281..cf0bc731 100644 --- a/app/models/event/push_trait.rb +++ b/app/models/event/push_trait.rb @@ -63,5 +63,19 @@ module Event::PushTrait "pushed to" end end + + def parent_commit + commits.first.prev_commit + rescue => ex + nil + end + + def last_commit + commits.last + end + + def push_with_commits? + md_ref? && commits.any? && parent_commit && last_commit + end end end diff --git a/app/views/events/_event_push.html.haml b/app/views/events/_event_push.html.haml index fb4ffc56..4c6102d0 100644 --- a/app/views/events/_event_push.html.haml +++ b/app/views/events/_event_push.html.haml @@ -10,10 +10,10 @@ = time_ago_in_words(event.created_at) ago. - - if event.md_ref? + - if event.push_with_commits? - if event.commits.count > 1 - = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do - %strong #{event.commits.first.commit.id[0..7]}...#{event.commits.last.id[0..7]} + = link_to compare_project_commits_path(event.project, :from => event.parent_commit.id, :to => event.last_commit.id) do + %strong #{event.commits.first.id[0..7]}...#{event.last_commit.id[0..7]} - project = event.project %ul.unstyled.event_commits - if event.commits.size > 3