Events improved. Open/close issue, merge request events displayed
This commit is contained in:
parent
98b484b996
commit
94befdd502
13 changed files with 98 additions and 19 deletions
|
@ -1,12 +1,25 @@
|
|||
class ActivityObserver < ActiveRecord::Observer
|
||||
observe :issue, :merge_request, :note
|
||||
observe :issue, :merge_request
|
||||
|
||||
def after_create(record)
|
||||
Event.create(
|
||||
:project => record.project,
|
||||
:target_id => record.id,
|
||||
:target_type => record.class.name,
|
||||
:action => Event.determine_action(record)
|
||||
:action => Event.determine_action(record),
|
||||
:author_id => record.author_id
|
||||
)
|
||||
end
|
||||
|
||||
def after_save(record)
|
||||
if record.changed.include?("closed")
|
||||
Event.create(
|
||||
:project => record.project,
|
||||
:target_id => record.id,
|
||||
:target_type => record.class.name,
|
||||
:action => (record.closed ? Event::Closed : Event::Reopened),
|
||||
:author_id => record.author_id_of_changes
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Event < ActiveRecord::Base
|
||||
default_scope where("author_id IS NOT NULL")
|
||||
|
||||
Created = 1
|
||||
Updated = 2
|
||||
Closed = 3
|
||||
|
@ -26,13 +28,22 @@ class Event < ActiveRecord::Base
|
|||
# - new issue
|
||||
# - merge request
|
||||
def allowed?
|
||||
push? || new_issue? || new_merge_request?
|
||||
push? || new_issue? || new_merge_request? ||
|
||||
changed_merge_request? || changed_issue?
|
||||
end
|
||||
|
||||
def push?
|
||||
action == self.class::Pushed
|
||||
end
|
||||
|
||||
def closed?
|
||||
action == self.class::Closed
|
||||
end
|
||||
|
||||
def reopened?
|
||||
action == self.class::Reopened
|
||||
end
|
||||
|
||||
def new_tag?
|
||||
data[:ref]["refs/tags"]
|
||||
end
|
||||
|
@ -57,10 +68,6 @@ class Event < ActiveRecord::Base
|
|||
@tag_name ||= data[:ref].gsub("refs/tags/", "")
|
||||
end
|
||||
|
||||
def pusher
|
||||
User.find_by_id(data[:user_id])
|
||||
end
|
||||
|
||||
def new_issue?
|
||||
target_type == "Issue" &&
|
||||
action == Created
|
||||
|
@ -71,6 +78,16 @@ class Event < ActiveRecord::Base
|
|||
action == Created
|
||||
end
|
||||
|
||||
def changed_merge_request?
|
||||
target_type == "MergeRequest" &&
|
||||
[Closed, Reopened].include?(action)
|
||||
end
|
||||
|
||||
def changed_issue?
|
||||
target_type == "Issue" &&
|
||||
[Closed, Reopened].include?(action)
|
||||
end
|
||||
|
||||
def issue
|
||||
target if target_type == "Issue"
|
||||
end
|
||||
|
@ -80,7 +97,7 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def author
|
||||
target.author
|
||||
@author ||= User.find(author_id)
|
||||
end
|
||||
|
||||
def commits
|
||||
|
@ -89,7 +106,6 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
delegate :id, :name, :email, :to => :pusher, :prefix => true, :allow_nil => true
|
||||
delegate :name, :email, :to => :author, :prefix => true, :allow_nil => true
|
||||
delegate :title, :to => :issue, :prefix => true, :allow_nil => true
|
||||
delegate :title, :to => :merge_request, :prefix => true, :allow_nil => true
|
||||
|
|
|
@ -5,6 +5,7 @@ class Issue < ActiveRecord::Base
|
|||
has_many :notes, :as => :noteable, :dependent => :destroy
|
||||
|
||||
attr_protected :author, :author_id, :project, :project_id
|
||||
attr_accessor :author_id_of_changes
|
||||
|
||||
validates_presence_of :project_id
|
||||
validates_presence_of :assignee_id
|
||||
|
|
|
@ -5,6 +5,7 @@ class MergeRequest < ActiveRecord::Base
|
|||
has_many :notes, :as => :noteable, :dependent => :destroy
|
||||
|
||||
attr_protected :author, :author_id, :project, :project_id
|
||||
attr_accessor :author_id_of_changes
|
||||
|
||||
validates_presence_of :project_id
|
||||
validates_presence_of :assignee_id
|
||||
|
|
|
@ -68,7 +68,8 @@ class Project < ActiveRecord::Base
|
|||
Event.create(
|
||||
:project => self,
|
||||
:action => Event::Pushed,
|
||||
:data => data
|
||||
:data => data,
|
||||
:author_id => Key.find_by_identifier(author_key_id).user.id
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue