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

Instance Method Details

#check_run?Boolean

Public: Return <true> if the event type is of type ‘check_run’; otherwise, <false>

Returns:

  • (Boolean)


48
49
50
# File 'app/helpers/github_bot/github_request_helper.rb', line 48

def check_run?
  github_event == 'check_run'
end

#comment_bodyObject

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_eventObject

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_payloadObject

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_rawObject

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_signatureObject

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>

Returns:

  • (Boolean)


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>

Returns:

  • (Boolean)


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>

Returns:

  • (Boolean)


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>

Returns:

  • (Boolean)


33
34
35
# File 'app/helpers/github_bot/github_request_helper.rb', line 33

def ping?
  github_event == 'ping'
end

#pull_requestObject

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>

Returns:

  • (Boolean)


38
39
40
# File 'app/helpers/github_bot/github_request_helper.rb', line 38

def pull_request?
  github_event == 'pull_request'
end

#pull_request_actionObject

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>

Returns:

  • (Boolean)


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>

Parameters:

  • option (String)

    represents which validation to run

Returns:

  • (Boolean)


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?

  options = recheck_options(comment_body)
  options.include?(option) || options.include?('all')
end

#repositoryObject

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>

Returns:

  • (Boolean)


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>

Returns:

  • (Boolean)


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>

Returns:

  • (Boolean)


95
96
97
# File 'app/helpers/github_bot/github_request_helper.rb', line 95

def unlabeled?
  github_event == 'unlabeled'
end