diff --git a/app/models/event.rb b/app/models/event.rb index 74525c12b32..a71d598a6fc 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -14,7 +14,7 @@ class Event < ActiveRecord::Base belongs_to :project belongs_to :target, :polymorphic => true - serialize :data + serialize :data, GitlabSerialize.new scope :recent, order("created_at DESC") scope :code_push, where(:action => Pushed) @@ -36,7 +36,7 @@ class Event < ActiveRecord::Base end def push? - action == self.class::Pushed + action == self.class::Pushed && valid_push? end def merged? diff --git a/app/models/event/push_trait.rb b/app/models/event/push_trait.rb index cf0bc731f8b..4e131cec8e2 100644 --- a/app/models/event/push_trait.rb +++ b/app/models/event/push_trait.rb @@ -1,19 +1,25 @@ module Event::PushTrait as_trait do + def valid_push? + data["ref"] + rescue => ex + false + end + def tag? - data[:ref]["refs/tags"] + data["ref"]["refs/tags"] end def new_branch? - data[:before] =~ /^00000/ + commit_from =~ /^00000/ end def new_ref? - data[:before] =~ /^00000/ + commit_from =~ /^00000/ end def rm_ref? - data[:after] =~ /^00000/ + commit_to =~ /^00000/ end def md_ref? @@ -21,11 +27,11 @@ module Event::PushTrait end def commit_from - data[:before] + data["before"] end def commit_to - data[:after] + data["after"] end def ref_name @@ -37,16 +43,16 @@ module Event::PushTrait end def branch_name - @branch_name ||= data[:ref].gsub("refs/heads/", "") + @branch_name ||= data["ref"].gsub("refs/heads/", "") end def tag_name - @tag_name ||= data[:ref].gsub("refs/tags/", "") + @tag_name ||= data["ref"].gsub("refs/tags/", "") end def commits - @commits ||= data[:commits].map do |commit| - project.commit(commit[:id]) + @commits ||= data["commits"].map do |commit| + project.commit(commit["id"]) end end diff --git a/app/models/gitlab_serialize.rb b/app/models/gitlab_serialize.rb new file mode 100644 index 00000000000..d5fda2a7a66 --- /dev/null +++ b/app/models/gitlab_serialize.rb @@ -0,0 +1,17 @@ +class GitlabSerialize + # Called to deserialize data to ruby object. + def load(data) + JSON.load(data) + rescue JSON::ParserError + begin + YAML.load(data) + rescue Psych::SyntaxError + nil + end + end + + # Called to convert from ruby object to serialized data. + def dump(obj) + JSON.dump(obj) + end +end diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index d25c7562a5f..cd81724c6d5 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -44,7 +44,7 @@ = link_to profile_path, :class => "btn" do Your Profile ยป .span10.left= render "dashboard/projects_feed", :projects => @active_projects - - if @last_push + - if @last_push && @last_push.valid_push? .padded.prepend-top-20 %h5 %small Latest push was to the #{@last_push.branch_name} branch of #{@last_push.project.name}: