Commit c9db6bb3f2bea55cbb2bf3073cbb2a4c73c104fa

Authored by Dmitriy Zaporozhets
1 parent f1799a23

prevent app crash for events without git resources

app/models/event/push_trait.rb
@@ -63,5 +63,19 @@ module Event::PushTrait @@ -63,5 +63,19 @@ module Event::PushTrait
63 "pushed to" 63 "pushed to"
64 end 64 end
65 end 65 end
  66 +
  67 + def parent_commit
  68 + commits.first.prev_commit
  69 + rescue => ex
  70 + nil
  71 + end
  72 +
  73 + def last_commit
  74 + commits.last
  75 + end
  76 +
  77 + def push_with_commits?
  78 + md_ref? && commits.any? && parent_commit && last_commit
  79 + end
66 end 80 end
67 end 81 end
app/views/events/_event_push.html.haml
@@ -10,10 +10,10 @@ @@ -10,10 +10,10 @@
10 = time_ago_in_words(event.created_at) 10 = time_ago_in_words(event.created_at)
11 ago. 11 ago.
12 12
13 - - if event.md_ref? 13 + - if event.push_with_commits?
14 - if event.commits.count > 1 14 - if event.commits.count > 1
15 - = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do  
16 - %strong #{event.commits.first.commit.id[0..7]}...#{event.commits.last.id[0..7]} 15 + = link_to compare_project_commits_path(event.project, :from => event.parent_commit.id, :to => event.last_commit.id) do
  16 + %strong #{event.commits.first.id[0..7]}...#{event.last_commit.id[0..7]}
17 - project = event.project 17 - project = event.project
18 %ul.unstyled.event_commits 18 %ul.unstyled.event_commits
19 - if event.commits.size > 3 19 - if event.commits.size > 3