2012-06-07 08:44:57 -04:00
|
|
|
module PushEvent
|
|
|
|
def valid_push?
|
|
|
|
data[:ref]
|
|
|
|
rescue => ex
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-10-08 20:10:04 -04:00
|
|
|
def tag?
|
2012-06-07 08:44:57 -04:00
|
|
|
data[:ref]["refs/tags"]
|
|
|
|
end
|
|
|
|
|
2012-10-08 20:10:04 -04:00
|
|
|
def branch?
|
2012-06-21 11:41:22 -04:00
|
|
|
data[:ref]["refs/heads"]
|
|
|
|
end
|
|
|
|
|
2012-06-07 08:44:57 -04:00
|
|
|
def new_branch?
|
|
|
|
commit_from =~ /^00000/
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_ref?
|
|
|
|
commit_from =~ /^00000/
|
|
|
|
end
|
|
|
|
|
|
|
|
def rm_ref?
|
|
|
|
commit_to =~ /^00000/
|
|
|
|
end
|
|
|
|
|
2012-10-08 20:10:04 -04:00
|
|
|
def md_ref?
|
2012-06-07 08:44:57 -04:00
|
|
|
!(rm_ref? || new_ref?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_from
|
|
|
|
data[:before]
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_to
|
|
|
|
data[:after]
|
|
|
|
end
|
|
|
|
|
2012-10-08 20:10:04 -04:00
|
|
|
def ref_name
|
2012-06-07 08:44:57 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
# Max 20 commits from push DESC
|
|
|
|
def commits
|
|
|
|
@commits ||= data[:commits].map { |commit| project.commit(commit[:id]) }.reverse
|
|
|
|
end
|
|
|
|
|
|
|
|
def commits_count
|
|
|
|
data[:total_commits_count] || commits.count || 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def ref_type
|
|
|
|
tag? ? "tag" : "branch"
|
|
|
|
end
|
|
|
|
|
|
|
|
def push_action_name
|
|
|
|
if new_ref?
|
|
|
|
"pushed new"
|
|
|
|
elsif rm_ref?
|
2012-09-30 09:04:43 -04:00
|
|
|
"deleted"
|
2012-06-07 08:44:57 -04:00
|
|
|
else
|
|
|
|
"pushed to"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def parent_commit
|
|
|
|
project.commit(commit_from)
|
|
|
|
rescue => ex
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_commit
|
|
|
|
project.commit(commit_to)
|
|
|
|
rescue => ex
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def push_with_commits?
|
|
|
|
md_ref? && commits.any? && parent_commit && last_commit
|
2012-08-28 19:03:04 -04:00
|
|
|
rescue Grit::NoSuchPathError
|
|
|
|
false
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|
2012-06-21 11:41:22 -04:00
|
|
|
|
|
|
|
def last_push_to_non_root?
|
|
|
|
branch? && project.default_branch != branch_name
|
|
|
|
end
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|