Class: GithubToSlack::Communicator

Inherits:
Object
  • Object
show all
Defined in:
app/models/github_to_slack/communicator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Communicator

Returns a new instance of Communicator.



6
7
8
# File 'app/models/github_to_slack/communicator.rb', line 6

def initialize(payload)
  @payload = payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'app/models/github_to_slack/communicator.rb', line 4

def payload
  @payload
end

Instance Method Details

#build_messageObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/github_to_slack/communicator.rb', line 10

def build_message
  puts "Parsing json"
  params = JSON.parse(payload).with_indifferent_access

  pr_url = params[:pull_request][:html_url]
  pr_title = params[:pull_request][:title]

  action = params[:action].to_sym
  label_name = params[:label][:name]
   = params[:sender][:login]

  alert_message = "_#{sender_login}_ #{label_actions[action]} `#{label_name}` label to *#{pr_title}*.\nPR Link: #{pr_url}"
end

#deliver_messageObject



24
25
26
# File 'app/models/github_to_slack/communicator.rb', line 24

def deliver_message
  SlackMessage.notify(build_message)
end

#label_actionsObject



28
29
30
31
32
33
# File 'app/models/github_to_slack/communicator.rb', line 28

def label_actions
  {
    labeled: :added,
    unlabeled: :removed
  }
end