Class: Lita::GithubPrList::CommentHook

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/github_pr_list/comment_hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_bodyObject

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

#commenterObject

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_clientObject

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_organizationObject

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_bodyObject

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_urlObject

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_ownerObject

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_titleObject

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

#payloadObject

Returns the value of attribute payload.



4
5
6
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4

def payload
  @payload
end

#redisObject

Returns the value of attribute redis.



4
5
6
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4

def redis
  @redis
end

#requestObject

Returns the value of attribute request.



4
5
6
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4

def request
  @request
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/lita/github_pr_list/comment_hook.rb', line 4

def response
  @response
end

#statusObject

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

#messageObject



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 message
  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