Module: GitHub::Payload::Helpers::Push
- Included in:
- Formatter::CreateEvent, Formatter::DeleteEvent, Formatter::IssueCommentEvent, Formatter::PublicEvent, Formatter::PushEvent
- Defined in:
- lib/github/payload/helpers/push.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_sha ⇒ Object
- #after_sha_url ⇒ Object
- #base_ref ⇒ Object
- #base_ref_name ⇒ Object
- #before_sha ⇒ Object
- #before_sha_url ⇒ Object
- #branch_url ⇒ Object
- #commit_messages ⇒ Object
- #commits ⇒ Object
- #compare_url ⇒ Object
- #created? ⇒ Boolean
- #deleted? ⇒ Boolean
- #distinct_commits ⇒ Object
- #forced? ⇒ Boolean
- #format_commit_message(commit) ⇒ Object
- #name_with_owner ⇒ Object
- #owner_name ⇒ Object
- #pusher_name ⇒ Object
- #ref ⇒ Object
- #ref_name ⇒ Object (also: #tag_name, #branch_name)
- #repo_name ⇒ Object
- #repo_url ⇒ Object
- #summary_message ⇒ Object
- #summary_url ⇒ Object
- #tag? ⇒ Boolean
Class Method Details
.sample_payload ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# 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" => "[email protected]" } }, "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" => "[email protected]" }, "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" => "[email protected]" }, "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" => "[email protected]" }, "id" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425" } ] } end |
Instance Method Details
#after_sha ⇒ Object
43 44 45 |
# File 'lib/github/payload/helpers/push.rb', line 43 def after_sha payload['after'][0..6] end |
#after_sha_url ⇒ Object
143 144 145 |
# File 'lib/github/payload/helpers/push.rb', line 143 def after_sha_url repo_url + "/commit/#{after_sha}" end |
#base_ref ⇒ Object
21 22 23 |
# File 'lib/github/payload/helpers/push.rb', line 21 def base_ref payload['base_ref'] end |
#base_ref_name ⇒ Object
35 36 37 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/github/payload/helpers/push.rb', line 39 def before_sha payload['before'][0..6] end |
#before_sha_url ⇒ Object
139 140 141 |
# File 'lib/github/payload/helpers/push.rb', line 139 def before_sha_url repo_url + "/commit/#{before_sha}" end |
#branch_url ⇒ Object
135 136 137 |
# File 'lib/github/payload/helpers/push.rb', line 135 def branch_url repo_url + "/commits/#{branch_name}" end |
#commit_messages ⇒ Object
52 53 54 55 56 |
# File 'lib/github/payload/helpers/push.rb', line 52 def distinct_commits.map do |commit| (commit) end end |
#commits ⇒ Object
163 164 165 |
# File 'lib/github/payload/helpers/push.rb', line 163 def commits Array(payload['commits']) end |
#compare_url ⇒ Object
131 132 133 |
# File 'lib/github/payload/helpers/push.rb', line 131 def compare_url payload['compare'] end |
#created? ⇒ Boolean
5 6 7 |
# File 'lib/github/payload/helpers/push.rb', line 5 def created? payload['created'] || !!(payload['before'] =~ /0{40}/) end |
#deleted? ⇒ Boolean
9 10 11 |
# File 'lib/github/payload/helpers/push.rb', line 9 def deleted? payload['deleted'] || !!(payload['after'] =~ /0{40}/) end |
#distinct_commits ⇒ Object
167 168 169 170 171 |
# 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? ⇒ Boolean
13 14 15 |
# File 'lib/github/payload/helpers/push.rb', line 13 def forced? payload['forced'] end |
#format_commit_message(commit) ⇒ Object
47 48 49 50 |
# File 'lib/github/payload/helpers/push.rb', line 47 def (commit) short = commit['message'].split("\n", 2).first "[#{repo_name}/#{branch_name}] #{short} - #{commit['author']['name']}" end |
#name_with_owner ⇒ Object
159 160 161 |
# File 'lib/github/payload/helpers/push.rb', line 159 def name_with_owner File.join(owner_name, repo_name) end |
#owner_name ⇒ Object
151 152 153 |
# File 'lib/github/payload/helpers/push.rb', line 151 def owner_name payload['repository']['owner']['name'] end |
#pusher_name ⇒ Object
147 148 149 |
# File 'lib/github/payload/helpers/push.rb', line 147 def pusher_name payload.include?('pusher') ? payload['pusher']['name'] : "somebody" end |
#ref ⇒ Object
17 18 19 |
# File 'lib/github/payload/helpers/push.rb', line 17 def ref payload['ref'].to_s end |
#ref_name ⇒ Object Also known as: tag_name, branch_name
29 30 31 |
# File 'lib/github/payload/helpers/push.rb', line 29 def ref_name payload['ref_name'] ||= ref.sub(/\Arefs\/(heads|tags)\//, '') end |
#repo_name ⇒ Object
155 156 157 |
# File 'lib/github/payload/helpers/push.rb', line 155 def repo_name payload['repository']['name'] end |
#repo_url ⇒ Object
127 128 129 |
# File 'lib/github/payload/helpers/push.rb', line 127 def repo_url payload['repository']['url'] end |
#summary_message ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/github/payload/helpers/push.rb', line 58 def = [] << "[#{repo_name}] #{pusher_name}" if created? if tag? << "tagged #{tag_name} at" << (base_ref ? base_ref_name : after_sha) else << "created #{branch_name}" if base_ref << "from #{base_ref_name}" elsif distinct_commits.empty? << "at #{after_sha}" end if distinct_commits.any? num = distinct_commits.size << "(+#{num} new commit#{num > 1 ? 's' : ''})" end end elsif deleted? << "deleted #{branch_name} at #{before_sha}" elsif forced? << "force-pushed #{branch_name} from #{before_sha} to #{after_sha}" elsif commits.any? and distinct_commits.empty? if base_ref << "merged #{base_ref_name} into #{branch_name}" else << "fast-forwarded #{branch_name} from #{before_sha} to #{after_sha}" end elsif distinct_commits.any? num = distinct_commits.size << "pushed #{num} new commit#{num > 1 ? 's' : ''} to #{branch_name}" else << "pushed nothing" end .join(' ') end |
#summary_url ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# 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? ⇒ Boolean
25 26 27 |
# File 'lib/github/payload/helpers/push.rb', line 25 def tag? !!(ref =~ %r|^refs/tags/|) end |