Class: Lita::GithubPrList::CommentHook
- Inherits:
-
Object
- Object
- Lita::GithubPrList::CommentHook
- Defined in:
- lib/lita/github_pr_list/comment_hook.rb
Instance Attribute Summary collapse
-
#comment_body ⇒ Object
Returns the value of attribute comment_body.
-
#commenter ⇒ Object
Returns the value of attribute commenter.
-
#github_client ⇒ Object
Returns the value of attribute github_client.
-
#github_organization ⇒ Object
Returns the value of attribute github_organization.
-
#issue_body ⇒ Object
Returns the value of attribute issue_body.
-
#issue_html_url ⇒ Object
Returns the value of attribute issue_html_url.
-
#issue_owner ⇒ Object
Returns the value of attribute issue_owner.
-
#issue_title ⇒ Object
Returns the value of attribute issue_title.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ CommentHook
constructor
A new instance of CommentHook.
- #message ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ CommentHook
Returns a new instance of CommentHook.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 7 def initialize(params = {}) self.response = params.fetch(:response, nil) self.request = params.fetch(:request, nil) self.redis = params.fetch(:redis, nil) self.github_organization = params.fetch(:github_organization, nil) github_token = params.fetch(:github_token, nil) self.github_client = Octokit::Client.new(access_token: github_token, auto_paginate: true) raise "invalid params in #{self.class.name}" if response.nil? || request.nil? || redis.nil? # https://developer.github.com/v3/activity/events/types/#issuecommentevent self.payload = JSON.parse(request.body.read) self.commenter = redis.get("alias:#{payload["sender"]["login"]}") || payload["sender"]["login"] self.issue_owner = redis.get("alias:#{payload["issue"]["user"]["login"]}") || payload["issue"]["user"]["login"] self.issue_title = payload["issue"]["title"] self.issue_html_url = payload["issue"]["html_url"] self.issue_body = payload["issue"]["body"] self.comment_body = payload["comment"]["body"] end |
Instance Attribute Details
#comment_body ⇒ Object
Returns the value of attribute comment_body.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def comment_body @comment_body end |
#commenter ⇒ Object
Returns the value of attribute commenter.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def commenter @commenter end |
#github_client ⇒ Object
Returns the value of attribute github_client.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def github_client @github_client end |
#github_organization ⇒ Object
Returns the value of attribute github_organization.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def github_organization @github_organization end |
#issue_body ⇒ Object
Returns the value of attribute issue_body.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def issue_body @issue_body end |
#issue_html_url ⇒ Object
Returns the value of attribute issue_html_url.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def issue_html_url @issue_html_url end |
#issue_owner ⇒ Object
Returns the value of attribute issue_owner.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def issue_owner @issue_owner end |
#issue_title ⇒ Object
Returns the value of attribute issue_title.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def issue_title @issue_title end |
#payload ⇒ Object
Returns the value of attribute payload.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def payload @payload end |
#redis ⇒ Object
Returns the value of attribute redis.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def redis @redis end |
#request ⇒ Object
Returns the value of attribute request.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def response @response end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4 def status @status end |
Instance Method Details
#message ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lita/github_pr_list/comment_hook.rb', line 27 def self.status = repo_status(payload["repository"]["full_name"], payload["issue"]) if !comment_body.empty? if comment_body.match Lita::GithubPrList::Status::REVIEW_REGEX "@#{commenter} is currently reviewing: #{issue_title}. #{issue_html_url}, @#{commenter}++" elsif comment_body.match Lita::GithubPrList::Status::FAIL_REGEX "@#{issue_owner} your pull request: #{issue_title} has failed. #{issue_html_url}" elsif comment_body.match Lita::GithubPrList::Status::FIXED_REGEX "#{issue_title} has been fixed: #{issue_html_url}" elsif comment_body.match Lita::GithubPrList::Status::PASS_DEV_REGEX pass_dev? elsif comment_body.match Lita::GithubPrList::Status::PASS_DESIGN_REGEX pass_design? end else nil end end |