Class: Hubstats::EventsHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/hubstats/events_handler.rb

Instance Method Summary collapse

Instance Method Details

#comment_processor(payload, kind) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/hubstats/events_handler.rb', line 26

def comment_processor(payload,kind)
  comment = payload[:comment]
  comment[:kind] = kind
  comment[:repo_id] = payload[:repository][:id]
  comment[:pull_number] = get_pull_number(payload)

  Hubstats::Comment.create_or_update(comment.with_indifferent_access)
end

#get_pull_number(payload) ⇒ Object

grabs the number off of anyone of the various places it can be



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hubstats/events_handler.rb', line 36

def get_pull_number(payload)
  if payload[:pull_request]
    return payload[:pull_request][:number]
  elsif payload[:issue]
    return payload[:issue][:number]
  elsif payload[:comment][:pull_request_url]
    return payload[:comment][:pull_request_url].split('/')[-1]
  else
    return nil
  end
end

#pull_processor(payload) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/hubstats/events_handler.rb', line 17

def pull_processor(payload)
  pull_request = payload[:pull_request]
  pull_request[:repository] = payload[:repository]
  new_pull = Hubstats::PullRequest.create_or_update(pull_request.with_indifferent_access)
  repo_name = Hubstats::Repo.where(id: new_pull.repo_id).first.full_name
  labels = Hubstats::GithubAPI.get_labels_for_pull(repo_name, new_pull.number )
  new_pull.add_labels(labels)
end

#route(payload, type) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/hubstats/events_handler.rb', line 4

def route(payload, type) 
  case type
  when "issue_comment", "IssueCommentEvent"
    comment_processor(payload,"Issue")
  when "commit_comment", "CommitCommentEvent"
    comment_processor(payload,"Commit")
  when "pull_request", "PullRequestEvent"
    pull_processor(payload)
  when "pull_request_review_comment", "PullRequestReviewCommentEvent"
    comment_processor(payload,"PullRequest")
  end
end