Commit a951e6f8ae3b8c958c91e3174a596b7afd93fc10
1 parent
8aa5076d
Exists in
master
and in
4 other branches
GitlabSerialize: cause of invalid yaml in some events we migrate to json serialization
Showing
4 changed files
with
36 additions
and
13 deletions
Show diff stats
app/models/event.rb
@@ -14,7 +14,7 @@ class Event < ActiveRecord::Base | @@ -14,7 +14,7 @@ class Event < ActiveRecord::Base | ||
14 | belongs_to :project | 14 | belongs_to :project |
15 | belongs_to :target, :polymorphic => true | 15 | belongs_to :target, :polymorphic => true |
16 | 16 | ||
17 | - serialize :data | 17 | + serialize :data, GitlabSerialize.new |
18 | 18 | ||
19 | scope :recent, order("created_at DESC") | 19 | scope :recent, order("created_at DESC") |
20 | scope :code_push, where(:action => Pushed) | 20 | scope :code_push, where(:action => Pushed) |
@@ -36,7 +36,7 @@ class Event < ActiveRecord::Base | @@ -36,7 +36,7 @@ class Event < ActiveRecord::Base | ||
36 | end | 36 | end |
37 | 37 | ||
38 | def push? | 38 | def push? |
39 | - action == self.class::Pushed | 39 | + action == self.class::Pushed && valid_push? |
40 | end | 40 | end |
41 | 41 | ||
42 | def merged? | 42 | def merged? |
app/models/event/push_trait.rb
1 | module Event::PushTrait | 1 | module Event::PushTrait |
2 | as_trait do | 2 | as_trait do |
3 | + def valid_push? | ||
4 | + data["ref"] | ||
5 | + rescue => ex | ||
6 | + false | ||
7 | + end | ||
8 | + | ||
3 | def tag? | 9 | def tag? |
4 | - data[:ref]["refs/tags"] | 10 | + data["ref"]["refs/tags"] |
5 | end | 11 | end |
6 | 12 | ||
7 | def new_branch? | 13 | def new_branch? |
8 | - data[:before] =~ /^00000/ | 14 | + commit_from =~ /^00000/ |
9 | end | 15 | end |
10 | 16 | ||
11 | def new_ref? | 17 | def new_ref? |
12 | - data[:before] =~ /^00000/ | 18 | + commit_from =~ /^00000/ |
13 | end | 19 | end |
14 | 20 | ||
15 | def rm_ref? | 21 | def rm_ref? |
16 | - data[:after] =~ /^00000/ | 22 | + commit_to =~ /^00000/ |
17 | end | 23 | end |
18 | 24 | ||
19 | def md_ref? | 25 | def md_ref? |
@@ -21,11 +27,11 @@ module Event::PushTrait | @@ -21,11 +27,11 @@ module Event::PushTrait | ||
21 | end | 27 | end |
22 | 28 | ||
23 | def commit_from | 29 | def commit_from |
24 | - data[:before] | 30 | + data["before"] |
25 | end | 31 | end |
26 | 32 | ||
27 | def commit_to | 33 | def commit_to |
28 | - data[:after] | 34 | + data["after"] |
29 | end | 35 | end |
30 | 36 | ||
31 | def ref_name | 37 | def ref_name |
@@ -37,16 +43,16 @@ module Event::PushTrait | @@ -37,16 +43,16 @@ module Event::PushTrait | ||
37 | end | 43 | end |
38 | 44 | ||
39 | def branch_name | 45 | def branch_name |
40 | - @branch_name ||= data[:ref].gsub("refs/heads/", "") | 46 | + @branch_name ||= data["ref"].gsub("refs/heads/", "") |
41 | end | 47 | end |
42 | 48 | ||
43 | def tag_name | 49 | def tag_name |
44 | - @tag_name ||= data[:ref].gsub("refs/tags/", "") | 50 | + @tag_name ||= data["ref"].gsub("refs/tags/", "") |
45 | end | 51 | end |
46 | 52 | ||
47 | def commits | 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 | end | 56 | end |
51 | end | 57 | end |
52 | 58 |
@@ -0,0 +1,17 @@ | @@ -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,7 +44,7 @@ | ||
44 | = link_to profile_path, :class => "btn" do | 44 | = link_to profile_path, :class => "btn" do |
45 | Your Profile » | 45 | Your Profile » |
46 | .span10.left= render "dashboard/projects_feed", :projects => @active_projects | 46 | .span10.left= render "dashboard/projects_feed", :projects => @active_projects |
47 | - - if @last_push | 47 | + - if @last_push && @last_push.valid_push? |
48 | .padded.prepend-top-20 | 48 | .padded.prepend-top-20 |
49 | %h5 | 49 | %h5 |
50 | %small Latest push was to the #{@last_push.branch_name} branch of #{@last_push.project.name}: | 50 | %small Latest push was to the #{@last_push.branch_name} branch of #{@last_push.project.name}: |