Commit a951e6f8ae3b8c958c91e3174a596b7afd93fc10

Authored by Dmitriy Zaporozhets
1 parent 8aa5076d

GitlabSerialize: cause of invalid yaml in some events we migrate to json serialization

app/models/event.rb
... ... @@ -14,7 +14,7 @@ class Event < ActiveRecord::Base
14 14 belongs_to :project
15 15 belongs_to :target, :polymorphic => true
16 16  
17   - serialize :data
  17 + serialize :data, GitlabSerialize.new
18 18  
19 19 scope :recent, order("created_at DESC")
20 20 scope :code_push, where(:action => Pushed)
... ... @@ -36,7 +36,7 @@ class Event < ActiveRecord::Base
36 36 end
37 37  
38 38 def push?
39   - action == self.class::Pushed
  39 + action == self.class::Pushed && valid_push?
40 40 end
41 41  
42 42 def merged?
... ...
app/models/event/push_trait.rb
1 1 module Event::PushTrait
2 2 as_trait do
  3 + def valid_push?
  4 + data["ref"]
  5 + rescue => ex
  6 + false
  7 + end
  8 +
3 9 def tag?
4   - data[:ref]["refs/tags"]
  10 + data["ref"]["refs/tags"]
5 11 end
6 12  
7 13 def new_branch?
8   - data[:before] =~ /^00000/
  14 + commit_from =~ /^00000/
9 15 end
10 16  
11 17 def new_ref?
12   - data[:before] =~ /^00000/
  18 + commit_from =~ /^00000/
13 19 end
14 20  
15 21 def rm_ref?
16   - data[:after] =~ /^00000/
  22 + commit_to =~ /^00000/
17 23 end
18 24  
19 25 def md_ref?
... ... @@ -21,11 +27,11 @@ module Event::PushTrait
21 27 end
22 28  
23 29 def commit_from
24   - data[:before]
  30 + data["before"]
25 31 end
26 32  
27 33 def commit_to
28   - data[:after]
  34 + data["after"]
29 35 end
30 36  
31 37 def ref_name
... ... @@ -37,16 +43,16 @@ module Event::PushTrait
37 43 end
38 44  
39 45 def branch_name
40   - @branch_name ||= data[:ref].gsub("refs/heads/", "")
  46 + @branch_name ||= data["ref"].gsub("refs/heads/", "")
41 47 end
42 48  
43 49 def tag_name
44   - @tag_name ||= data[:ref].gsub("refs/tags/", "")
  50 + @tag_name ||= data["ref"].gsub("refs/tags/", "")
45 51 end
46 52  
47 53 def commits
48   - @commits ||= data[:commits].map do |commit|
49   - project.commit(commit[:id])
  54 + @commits ||= data["commits"].map do |commit|
  55 + project.commit(commit["id"])
50 56 end
51 57 end
52 58  
... ...
app/models/gitlab_serialize.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class GitlabSerialize
  2 + # Called to deserialize data to ruby object.
  3 + def load(data)
  4 + JSON.load(data)
  5 + rescue JSON::ParserError
  6 + begin
  7 + YAML.load(data)
  8 + rescue Psych::SyntaxError
  9 + nil
  10 + end
  11 + end
  12 +
  13 + # Called to convert from ruby object to serialized data.
  14 + def dump(obj)
  15 + JSON.dump(obj)
  16 + end
  17 +end
... ...
app/views/dashboard/index.html.haml
... ... @@ -44,7 +44,7 @@
44 44 = link_to profile_path, :class => "btn" do
45 45 Your Profile »
46 46 .span10.left= render "dashboard/projects_feed", :projects => @active_projects
47   - - if @last_push
  47 + - if @last_push && @last_push.valid_push?
48 48 .padded.prepend-top-20
49 49 %h5
50 50 %small Latest push was to the #{@last_push.branch_name} branch of #{@last_push.project.name}:
... ...