Commit c9db6bb3f2bea55cbb2bf3073cbb2a4c73c104fa
1 parent
f1799a23
Exists in
master
and in
4 other branches
prevent app crash for events without git resources
Showing
2 changed files
with
17 additions
and
3 deletions
Show diff stats
app/models/event/push_trait.rb
| ... | ... | @@ -63,5 +63,19 @@ module Event::PushTrait |
| 63 | 63 | "pushed to" |
| 64 | 64 | end |
| 65 | 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 | 80 | end |
| 67 | 81 | end | ... | ... |
app/views/events/_event_push.html.haml
| ... | ... | @@ -10,10 +10,10 @@ |
| 10 | 10 | = time_ago_in_words(event.created_at) |
| 11 | 11 | ago. |
| 12 | 12 | |
| 13 | - - if event.md_ref? | |
| 13 | + - if event.push_with_commits? | |
| 14 | 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 | 17 | - project = event.project |
| 18 | 18 | %ul.unstyled.event_commits |
| 19 | 19 | - if event.commits.size > 3 | ... | ... |