Class: Issue::Payload
- Inherits:
-
Object
- Object
- Issue::Payload
- Defined in:
- lib/issue/payload.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
-
#assigned? ⇒ Boolean
True if the payload is coming from un/assigning an issue.
-
#closed? ⇒ Boolean
True if the payload is coming from an issue that has just been closed.
-
#commented? ⇒ Boolean
True if the payload is coming from a new comment.
-
#edited? ⇒ Boolean
True if the payload is coming from an edition of a comment or issue.
-
#initialize(json_data, event) ⇒ Payload
constructor
Initialize Issue::Payload object with:.
-
#labeled? ⇒ Boolean
True if the payload is coming from un/labeling an issue.
-
#locked? ⇒ Boolean
True if the payload is coming from locking an issue.
-
#opened? ⇒ Boolean
True if the payload is coming from an issue that has just been opened.
-
#pinned? ⇒ Boolean
True if the payload is coming from pinning or unpinning an issue.
-
#unlocked? ⇒ Boolean
True if the payload is coming from unlocking an issue.
Constructor Details
#initialize(json_data, event) ⇒ Payload
Initialize Issue::Payload object with:
json_data: the parsed json sent from a GitHub webhook
event: the value of the HTTP_X_GITHUB_EVENT header
Initializing a new Issue::Payload instance makes all this info from the json webhook available via accessor methods:
action
event
issue_id
issue_title
issue_body
repo
sender
event_action
raw_payload
And when the event is ‘issue_comment’ also:
comment_body
comment_created_at
comment_url
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/issue/payload.rb', line 33 def initialize(json_data, event) action = json_data.dig("action") sender = json_data.dig("sender", "login") repo = json_data.dig("repository", "full_name") if event == "pull_request" issue_id = json_data.dig("pull_request", "number") issue_title = json_data.dig("pull_request", "title") issue_body = json_data.dig("pull_request", "body") issue_labels = json_data.dig("pull_request", "labels") = json_data.dig("pull_request", "user", "login") else issue_id = json_data.dig("issue", "number") issue_title = json_data.dig("issue", "title") issue_body = json_data.dig("issue", "body") issue_labels = json_data.dig("issue", "labels") = json_data.dig("issue", "user", "login") end @context = OpenStruct.new( action: action, event: event, issue_id: issue_id, issue_title: issue_title, issue_body: issue_body, issue_author: , issue_labels: issue_labels, repo: repo, sender: sender, event_action: "#{event}.#{action}", raw_payload: json_data ) if event == "issue_comment" @context[:comment_id] = json_data.dig("comment", "id") @context[:comment_body] = json_data.dig("comment", "body") @context[:comment_created_at] = json_data.dig("comment", "created_at") @context[:comment_url] = json_data.dig("comment", "html_url") end @context.each_pair do |method_name, value| define_singleton_method(method_name) {value} end end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/issue/payload.rb', line 6 def context @context end |
Instance Method Details
#assigned? ⇒ Boolean
True if the payload is coming from un/assigning an issue
114 115 116 |
# File 'lib/issue/payload.rb', line 114 def assigned? action == "assigned" || action == "unassigned" end |
#closed? ⇒ Boolean
True if the payload is coming from an issue that has just been closed
84 85 86 |
# File 'lib/issue/payload.rb', line 84 def closed? action == "closed" end |
#commented? ⇒ Boolean
True if the payload is coming from a new comment
89 90 91 |
# File 'lib/issue/payload.rb', line 89 def commented? action == "created" end |
#edited? ⇒ Boolean
True if the payload is coming from an edition of a comment or issue
94 95 96 |
# File 'lib/issue/payload.rb', line 94 def edited? action == "edited" end |
#labeled? ⇒ Boolean
True if the payload is coming from un/labeling an issue
119 120 121 |
# File 'lib/issue/payload.rb', line 119 def labeled? action == "labeled" || action == "unlabeled" end |
#locked? ⇒ Boolean
True if the payload is coming from locking an issue
99 100 101 |
# File 'lib/issue/payload.rb', line 99 def locked? action == "locked" end |
#opened? ⇒ Boolean
True if the payload is coming from an issue that has just been opened
79 80 81 |
# File 'lib/issue/payload.rb', line 79 def opened? action == "opened" || action == "reopened" end |
#pinned? ⇒ Boolean
True if the payload is coming from pinning or unpinning an issue
109 110 111 |
# File 'lib/issue/payload.rb', line 109 def pinned? action == "pinned" || action == "unpinned" end |
#unlocked? ⇒ Boolean
True if the payload is coming from unlocking an issue
104 105 106 |
# File 'lib/issue/payload.rb', line 104 def unlocked? action == "unlocked" end |