Class: BitbucketPayload
- Defined in:
- lib/robot_sweatshop/payload/bitbucket.rb
Overview
A parser for Bitbucket payload data
Instance Method Summary collapse
- #author ⇒ Object
- #branch ⇒ Object
- #clone_url ⇒ Object
- #hash ⇒ Object
-
#initialize(data) ⇒ BitbucketPayload
constructor
A new instance of BitbucketPayload.
- #latest_commit ⇒ Object
- #message ⇒ Object
- #repo_slug ⇒ Object
- #repository ⇒ Object
- #source_url ⇒ Object
Methods inherited from Payload
Constructor Details
#initialize(data) ⇒ BitbucketPayload
Returns a new instance of BitbucketPayload.
7 8 9 10 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 7 def initialize(data) data = URI.decode_www_form(data)[0][1] @data = JSON.parse data || {} end |
Instance Method Details
#author ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 22 def return {} if latest_commit['raw_author'].nil? name, email = latest_commit['raw_author'].split(/\s+</) email.slice! '>' unless email.nil? { 'name' => name, 'email' => email || '', 'username' => latest_commit['author'] } end |
#branch ⇒ Object
41 42 43 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 41 def branch latest_commit['branch'] end |
#clone_url ⇒ Object
33 34 35 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 33 def clone_url "#{ @data['canon_url'] }#{ repository['absolute_url'] }" end |
#hash ⇒ Object
37 38 39 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 37 def hash latest_commit['raw_node'] end |
#latest_commit ⇒ Object
12 13 14 15 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 12 def latest_commit return {} if @data['commits'].nil? @data['commits'].last end |
#message ⇒ Object
45 46 47 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 45 def latest_commit['message'] end |
#repo_slug ⇒ Object
49 50 51 52 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 49 def repo_slug slug = repository['absolute_url'] slug.nil? ? nil : slug[1...-1] end |
#repository ⇒ Object
17 18 19 20 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 17 def repository return {} if @data['repository'].nil? @data['repository'] end |
#source_url ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/robot_sweatshop/payload/bitbucket.rb', line 54 def source_url return '' if @data['canon_url'].nil? || repository.empty? || latest_commit.empty? base_url = @data['canon_url'] "#{base_url}/#{repo_slug}/commits/#{hash}/?at=#{branch}" end |