Class: Vx::ServiceConnector::Github::Payload
- Inherits:
-
Object
- Object
- Vx::ServiceConnector::Github::Payload
- Defined in:
- lib/vx/service_connector/github/payload.rb
Instance Method Summary collapse
- #base ⇒ Object
- #branch ⇒ Object
- #branch_label ⇒ Object
- #closed_pull_request? ⇒ Boolean
- #foreign_pull_request? ⇒ Boolean
- #head ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(params) ⇒ Payload
constructor
A new instance of Payload.
- #pull_request? ⇒ Boolean
- #pull_request_base_repo_id ⇒ Object
- #pull_request_head_repo_id ⇒ Object
- #pull_request_number ⇒ Object
- #tag? ⇒ Boolean
- #to_model ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(params) ⇒ Payload
Returns a new instance of Payload.
6 7 8 |
# File 'lib/vx/service_connector/github/payload.rb', line 6 def initialize(params) @params = params || {} end |
Instance Method Details
#base ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/vx/service_connector/github/payload.rb', line 32 def base if pull_request? pull_request["base"]["sha"] else self["before"] end end |
#branch ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/vx/service_connector/github/payload.rb', line 40 def branch if pull_request? pull_request["head"]["ref"] else self["ref"].to_s.split("refs/heads/").last end end |
#branch_label ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/vx/service_connector/github/payload.rb', line 48 def branch_label if pull_request? pull_request["head"]["label"] else branch end end |
#closed_pull_request? ⇒ Boolean
76 77 78 |
# File 'lib/vx/service_connector/github/payload.rb', line 76 def closed_pull_request? pull_request? && (pull_request["state"] == 'closed') end |
#foreign_pull_request? ⇒ Boolean
80 81 82 |
# File 'lib/vx/service_connector/github/payload.rb', line 80 def foreign_pull_request? pull_request? && (pull_request_head_repo_id != pull_request_base_repo_id) end |
#head ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/vx/service_connector/github/payload.rb', line 24 def head if pull_request? pull_request["head"]["sha"] else self["after"] end end |
#ignore? ⇒ Boolean
84 85 86 87 88 89 90 91 |
# File 'lib/vx/service_connector/github/payload.rb', line 84 def ignore? if pull_request? closed_pull_request? || !foreign_pull_request? else head == '0000000000000000000000000000000000000000' || tag? end end |
#pull_request? ⇒ Boolean
10 11 12 |
# File 'lib/vx/service_connector/github/payload.rb', line 10 def pull_request? key? "pull_request" end |
#pull_request_base_repo_id ⇒ Object
70 71 72 73 74 |
# File 'lib/vx/service_connector/github/payload.rb', line 70 def pull_request_base_repo_id if pull_request? pull_request['base']['repo']['id'] end end |
#pull_request_head_repo_id ⇒ Object
64 65 66 67 68 |
# File 'lib/vx/service_connector/github/payload.rb', line 64 def pull_request_head_repo_id if pull_request? pull_request['head']['repo']['id'] end end |
#pull_request_number ⇒ Object
18 19 20 21 22 |
# File 'lib/vx/service_connector/github/payload.rb', line 18 def pull_request_number if pull_request? && key?("number") self["number"] end end |
#tag? ⇒ Boolean
14 15 16 |
# File 'lib/vx/service_connector/github/payload.rb', line 14 def tag? !pull_request? && self['ref'] =~ /^#{Regexp.escape 'refs/tags/'}/ end |
#to_model ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vx/service_connector/github/payload.rb', line 93 def to_model ServiceConnector::Model::Payload.new( !!pull_request, pull_request_number, head, base, branch, branch_label, url, !!ignore? ) end |
#url ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/vx/service_connector/github/payload.rb', line 56 def url if pull_request? pull_request["url"] else self["compare"] end end |