2012-04-01 23:24:45 +02:00
|
|
|
module Event::PushTrait
|
|
|
|
as_trait do
|
2012-04-04 01:25:33 +02:00
|
|
|
def valid_push?
|
2012-04-04 01:59:58 +02:00
|
|
|
data[:ref]
|
2012-04-04 01:25:33 +02:00
|
|
|
rescue => ex
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-04-01 23:24:45 +02:00
|
|
|
def tag?
|
2012-04-04 01:59:58 +02:00
|
|
|
data[:ref]["refs/tags"]
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_branch?
|
2012-04-04 01:25:33 +02:00
|
|
|
commit_from =~ /^00000/
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_ref?
|
2012-04-04 01:25:33 +02:00
|
|
|
commit_from =~ /^00000/
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def rm_ref?
|
2012-04-04 01:25:33 +02:00
|
|
|
commit_to =~ /^00000/
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def md_ref?
|
|
|
|
!(rm_ref? || new_ref?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_from
|
2012-04-04 01:59:58 +02:00
|
|
|
data[:before]
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def commit_to
|
2012-04-04 01:59:58 +02:00
|
|
|
data[:after]
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ref_name
|
|
|
|
if tag?
|
|
|
|
tag_name
|
|
|
|
else
|
|
|
|
branch_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_name
|
2012-04-04 01:59:58 +02:00
|
|
|
@branch_name ||= data[:ref].gsub("refs/heads/", "")
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_name
|
2012-04-04 01:59:58 +02:00
|
|
|
@tag_name ||= data[:ref].gsub("refs/tags/", "")
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def commits
|
2012-04-04 01:59:58 +02:00
|
|
|
@commits ||= data[:commits].map do |commit|
|
2012-04-04 01:25:33 +02:00
|
|
|
project.commit(commit["id"])
|
2012-04-01 23:24:45 +02:00
|
|
|
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
|
2012-04-02 18:51:20 +02:00
|
|
|
|
|
|
|
def parent_commit
|
|
|
|
commits.first.prev_commit
|
|
|
|
rescue => ex
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_commit
|
|
|
|
commits.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def push_with_commits?
|
|
|
|
md_ref? && commits.any? && parent_commit && last_commit
|
|
|
|
end
|
2012-04-01 23:24:45 +02:00
|
|
|
end
|
|
|
|
end
|