Module: GithubBot::GithubRequestHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/github_bot/github_request_helper.rb
Overview
Public: A request helper for understanding the incoming request context
Instance Method Summary collapse
-
#check_run? ⇒ Boolean
Public: Return <true> if the event type is of type ‘check_run’; otherwise, <false>.
-
#comment_body ⇒ Object
Public: Returns <String> of the comment’s body from the github payload.
-
#github_event ⇒ Object
Public: Returns the GitHub event type of the incoming request.
-
#github_payload ⇒ Object
Public: Returns the <Json> representation of the github payload.
-
#github_payload_raw ⇒ Object
Public: Returns the raw content of the github payload’s body content.
-
#github_signature ⇒ Object
Public: Returns if the GitHub signature of the incoming request.
-
#issue_comment? ⇒ Boolean
Public: Return <true> if the action type is of type ‘issue_comment’; otherwise, <false>.
-
#issue_comment_recheck? ⇒ Boolean
Public: Return <true> if the action type is of type ‘issue_comment’ and the comment message contains “run_validation”; otherwise, <false>.
-
#labeled? ⇒ Boolean
Public: Return <true> if the action type is of type ‘labeled’; otherwise, <false>.
-
#ping? ⇒ Boolean
Public: Returns <true> if the event type is of type ‘ping’; otherwise, <false>.
-
#pull_request ⇒ Object
Public: Returns the pull request content from the payload.
-
#pull_request? ⇒ Boolean
Public: Return <true> if the event type is of type ‘pull_request’; otherwise, <false>.
-
#pull_request_action ⇒ Object
Public: Returns the pull request action type from the payload.
-
#pull_request_review? ⇒ Boolean
Public: Return <true> if the event type is of type ‘pull_request_review’; otherwise, <false>.
-
#recheck_application?(option) ⇒ Boolean
Public: Return <true> if issue_comment_recheck? is true and the comment message contains option; otherwise, <false>.
-
#repository ⇒ Object
Public: Returns the repository payload.
-
#review_request_removed? ⇒ Boolean
Public: Return <true> if the action type is of type ‘review_request_removed’; otherwise, <false>.
-
#review_requested? ⇒ Boolean
Public: Return <true> if the action type is of type ‘review_requested’; otherwise, <false>.
-
#unlabeled? ⇒ Boolean
Public: Return <true> if the action type is of type ‘unlabeled’; otherwise, <false>.
Instance Method Details
#check_run? ⇒ Boolean
Public: Return <true> if the event type is of type ‘check_run’; otherwise, <false>
48 49 50 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 48 def check_run? github_event == 'check_run' end |
#comment_body ⇒ Object
Public: Returns <String> of the comment’s body from the github payload
73 74 75 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 73 def comment_body github_payload['comment']['body'] end |
#github_event ⇒ Object
Public: Returns the GitHub event type of the incoming request
7 8 9 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 7 def github_event request.env['HTTP_X_GITHUB_EVENT'] end |
#github_payload ⇒ Object
Public: Returns the <Json> representation of the github payload
22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 22 def github_payload return @github_payload if @github_payload begin @github_payload = JSON.parse(github_payload_raw).with_indifferent_access rescue StandardError => e raise StandardError, "Invalid JSON (#{e}): #{@github_payload_raw}" end end |
#github_payload_raw ⇒ Object
Public: Returns the raw content of the github payload’s body content
17 18 19 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 17 def github_payload_raw @github_payload_raw ||= request.body.read end |
#github_signature ⇒ Object
Public: Returns if the GitHub signature of the incoming request
12 13 14 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 12 def github_signature request.env['HTTP_X_HUB_SIGNATURE'] || 'no-signature' end |
#issue_comment? ⇒ Boolean
Public: Return <true> if the action type is of type ‘issue_comment’; otherwise, <false>
68 69 70 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 68 def issue_comment? github_event == 'issue_comment' end |
#issue_comment_recheck? ⇒ Boolean
Public: Return <true> if the action type is of type ‘issue_comment’ and the comment message contains “run_validation”; otherwise, <false>
79 80 81 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 79 def issue_comment_recheck? github_event == 'issue_comment' && comment_body.include?('run_validation') end |
#labeled? ⇒ Boolean
Public: Return <true> if the action type is of type ‘labeled’; otherwise, <false>
63 64 65 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 63 def labeled? github_event == 'labeled' end |
#ping? ⇒ Boolean
Public: Returns <true> if the event type is of type ‘ping’; otherwise, <false>
33 34 35 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 33 def ping? github_event == 'ping' end |
#pull_request ⇒ Object
Public: Returns the pull request content from the payload
105 106 107 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 105 def pull_request github_payload['pull_request'] end |
#pull_request? ⇒ Boolean
Public: Return <true> if the event type is of type ‘pull_request’; otherwise, <false>
38 39 40 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 38 def pull_request? github_event == 'pull_request' end |
#pull_request_action ⇒ Object
Public: Returns the pull request action type from the payload
100 101 102 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 100 def pull_request_action github_payload['action'] end |
#pull_request_review? ⇒ Boolean
Public: Return <true> if the event type is of type ‘pull_request_review’; otherwise, <false>
43 44 45 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 43 def pull_request_review? github_event == 'pull_request_review' end |
#recheck_application?(option) ⇒ Boolean
Public: Return <true> if issue_comment_recheck? is true and the comment message contains option; otherwise, <false>
87 88 89 90 91 92 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 87 def recheck_application?(option) return false unless issue_comment_recheck? = (comment_body) .include?(option) || .include?('all') end |
#repository ⇒ Object
Public: Returns the repository payload
110 111 112 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 110 def repository github_payload['repository'] end |
#review_request_removed? ⇒ Boolean
Public: Return <true> if the action type is of type ‘review_request_removed’; otherwise, <false>
58 59 60 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 58 def review_request_removed? github_event == 'review_request_removed' end |
#review_requested? ⇒ Boolean
Public: Return <true> if the action type is of type ‘review_requested’; otherwise, <false>
53 54 55 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 53 def review_requested? github_event == 'review_requested' end |
#unlabeled? ⇒ Boolean
Public: Return <true> if the action type is of type ‘unlabeled’; otherwise, <false>
95 96 97 |
# File 'app/helpers/github_bot/github_request_helper.rb', line 95 def unlabeled? github_event == 'unlabeled' end |