module GitHub::Payload::Helpers::Push
Public Class Methods
sample_payload()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 173 def self.sample_payload { "after" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", "ref" => "refs/heads/master", "before" => "4c8124ffcf4039d292442eeccabdeca5af5c5017", "compare" => "http://github.com/mojombo/grit/compare/4c8124f...a47fd41", "repository" => { "name" => "grit", "url" => "http://github.com/mojombo/grit", "owner" => { "name" => "mojombo", "email" => "tom@mojombo.com" } }, "pusher" => { "name" => "rtomayko" }, "commits" => [ { "distinct" => true, "removed" => [], "message" => "stub git call for Grit#heads test f:15 Case#1", "added" => [], "timestamp" => "2007-10-10T00:11:02-07:00", "modified" => ["lib/grit/grit.rb", "test/helper.rb", "test/test_grit.rb"], "url" => "http://github.com/mojombo/grit/commit/06f63b43050935962f84fe54473a7c5de7977325", "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, "id" => "06f63b43050935962f84fe54473a7c5de7977325" }, { "distinct" => true, "removed" => [], "message" => "clean up heads test f:2hrs", "added" => [], "timestamp" => "2007-10-10T00:18:20-07:00", "modified" => ["test/test_grit.rb"], "url" => "http://github.com/mojombo/grit/commit/5057e76a11abd02e83b7d3d3171c4b68d9c88480", "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, "id" => "5057e76a11abd02e83b7d3d3171c4b68d9c88480" }, { "distinct" => true, "removed" => [], "message" => "add more comments throughout", "added" => [], "timestamp" => "2007-10-10T00:50:39-07:00", "modified" => ["lib/grit.rb", "lib/grit/commit.rb", "lib/grit/grit.rb"], "url" => "http://github.com/mojombo/grit/commit/a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, "id" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425" } ] } end
Public Instance Methods
after_sha()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 43 def after_sha payload['after'][0..6] end
after_sha_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 143 def after_sha_url repo_url + "/commit/#{after_sha}" end
base_ref()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 21 def base_ref payload['base_ref'] end
base_ref_name()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 35 def base_ref_name payload['base_ref_name'] ||= base_ref.sub(/\Arefs\/(heads|tags)\//, '') end
before_sha()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 39 def before_sha payload['before'][0..6] end
before_sha_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 139 def before_sha_url repo_url + "/commit/#{before_sha}" end
branch_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 135 def branch_url repo_url + "/commits/#{branch_name}" end
commit_messages()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 52 def commit_messages distinct_commits.map do |commit| format_commit_message(commit) end end
commits()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 163 def commits Array(payload['commits']) end
compare_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 131 def compare_url payload['compare'] end
created?()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 5 def created? payload['created'] || !!(payload['before'] =~ /0{40}/) end
deleted?()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 9 def deleted? payload['deleted'] || !!(payload['after'] =~ /0{40}/) end
distinct_commits()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 167 def distinct_commits payload['distinct_commits'] ||= Array(commits.select do |commit| commit['distinct'] and !commit['message'].to_s.strip.empty? end) end
forced?()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 13 def forced? payload['forced'] end
format_commit_message(commit)
click to toggle source
# File lib/github/payload/helpers/push.rb, line 47 def format_commit_message(commit) short = commit['message'].split("\n", 2).first "[#{repo_name}/#{branch_name}] #{short} - #{commit['author']['name']}" end
name_with_owner()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 159 def name_with_owner File.join(owner_name, repo_name) end
owner_name()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 151 def owner_name payload['repository']['owner']['name'] end
pusher_name()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 147 def pusher_name payload.include?('pusher') ? payload['pusher']['name'] : "somebody" end
ref()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 17 def ref payload['ref'].to_s end
ref_name()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 29 def ref_name payload['ref_name'] ||= ref.sub(/\Arefs\/(heads|tags)\//, '') end
Also aliased as: tag_name, branch_name
repo_name()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 155 def repo_name payload['repository']['name'] end
repo_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 127 def repo_url payload['repository']['url'] end
summary_message()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 58 def summary_message message = [] message << "[#{repo_name}] #{pusher_name}" if created? if tag? message << "tagged #{tag_name} at" message << (base_ref ? base_ref_name : after_sha) else message << "created #{branch_name}" if base_ref message << "from #{base_ref_name}" elsif distinct_commits.empty? message << "at #{after_sha}" end if distinct_commits.any? num = distinct_commits.size message << "(+#{num} new commit#{num > 1 ? 's' : ''})" end end elsif deleted? message << "deleted #{branch_name} at #{before_sha}" elsif forced? message << "force-pushed #{branch_name} from #{before_sha} to #{after_sha}" elsif commits.any? and distinct_commits.empty? if base_ref message << "merged #{base_ref_name} into #{branch_name}" else message << "fast-forwarded #{branch_name} from #{before_sha} to #{after_sha}" end elsif distinct_commits.any? num = distinct_commits.size message << "pushed #{num} new commit#{num > 1 ? 's' : ''} to #{branch_name}" else message << "pushed nothing" end message.join(' ') end
summary_url()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 105 def summary_url if created? if distinct_commits.empty? branch_url else compare_url end elsif deleted? before_sha_url elsif forced? branch_url elsif distinct_commits.size == 1 distinct_commits.first['url'] else compare_url end end
tag?()
click to toggle source
# File lib/github/payload/helpers/push.rb, line 25 def tag? !!(ref =~ %r|^refs/tags/|) end