Events improved & refactored. Dashboard pollished
This commit is contained in:
parent
3ac9c3ad7f
commit
00dc34e192
11 changed files with 139 additions and 126 deletions
|
@ -9,6 +9,8 @@ class Event < ActiveRecord::Base
|
|||
Commented = 6
|
||||
Merged = 7
|
||||
|
||||
does "event/push"
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :target, :polymorphic => true
|
||||
|
||||
|
@ -30,14 +32,17 @@ class Event < ActiveRecord::Base
|
|||
# - new issue
|
||||
# - merge request
|
||||
def allowed?
|
||||
push? || new_issue? || new_merge_request? ||
|
||||
changed_merge_request? || changed_issue?
|
||||
push? || issue? || merge_request?
|
||||
end
|
||||
|
||||
def push?
|
||||
action == self.class::Pushed
|
||||
end
|
||||
|
||||
def merged?
|
||||
action == self.class::Merged
|
||||
end
|
||||
|
||||
def closed?
|
||||
action == self.class::Closed
|
||||
end
|
||||
|
@ -46,28 +51,12 @@ class Event < ActiveRecord::Base
|
|||
action == self.class::Reopened
|
||||
end
|
||||
|
||||
def new_tag?
|
||||
data[:ref]["refs/tags"]
|
||||
def issue?
|
||||
target_type == "Issue"
|
||||
end
|
||||
|
||||
def new_branch?
|
||||
data[:before] =~ /^00000/
|
||||
end
|
||||
|
||||
def commit_from
|
||||
data[:before]
|
||||
end
|
||||
|
||||
def commit_to
|
||||
data[:after]
|
||||
end
|
||||
|
||||
def branch_name
|
||||
@branch_name ||= data[:ref].gsub("refs/heads/", "")
|
||||
end
|
||||
|
||||
def tag_name
|
||||
@tag_name ||= data[:ref].gsub("refs/tags/", "")
|
||||
def merge_request?
|
||||
target_type == "MergeRequest"
|
||||
end
|
||||
|
||||
def new_issue?
|
||||
|
@ -101,10 +90,14 @@ class Event < ActiveRecord::Base
|
|||
def author
|
||||
@author ||= User.find(author_id)
|
||||
end
|
||||
|
||||
def commits
|
||||
@commits ||= data[:commits].map do |commit|
|
||||
project.commit(commit[:id])
|
||||
|
||||
def action_name
|
||||
if closed?
|
||||
"closed"
|
||||
elsif merged?
|
||||
"merged"
|
||||
else
|
||||
"opened"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
67
app/models/event/push_trait.rb
Normal file
67
app/models/event/push_trait.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
module Event::PushTrait
|
||||
as_trait do
|
||||
def tag?
|
||||
data[:ref]["refs/tags"]
|
||||
end
|
||||
|
||||
def new_branch?
|
||||
data[:before] =~ /^00000/
|
||||
end
|
||||
|
||||
def new_ref?
|
||||
data[:before] =~ /^00000/
|
||||
end
|
||||
|
||||
def rm_ref?
|
||||
data[:after] =~ /^00000/
|
||||
end
|
||||
|
||||
def md_ref?
|
||||
!(rm_ref? || new_ref?)
|
||||
end
|
||||
|
||||
def commit_from
|
||||
data[:before]
|
||||
end
|
||||
|
||||
def commit_to
|
||||
data[:after]
|
||||
end
|
||||
|
||||
def ref_name
|
||||
if tag?
|
||||
tag_name
|
||||
else
|
||||
branch_name
|
||||
end
|
||||
end
|
||||
|
||||
def branch_name
|
||||
@branch_name ||= data[:ref].gsub("refs/heads/", "")
|
||||
end
|
||||
|
||||
def tag_name
|
||||
@tag_name ||= data[:ref].gsub("refs/tags/", "")
|
||||
end
|
||||
|
||||
def commits
|
||||
@commits ||= data[:commits].map do |commit|
|
||||
project.commit(commit[:id])
|
||||
end
|
||||
end
|
||||
|
||||
def ref_type
|
||||
tag? ? "tag" : "branch"
|
||||
end
|
||||
|
||||
def push_action_name
|
||||
if new_ref?
|
||||
"pushed new"
|
||||
elsif rm_ref?
|
||||
"removed #{ref_type}"
|
||||
else
|
||||
"pushed to"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue