Class: GithubStatusNotifier::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/github_status_notifier/notifier.rb

Constant Summary collapse

PENDING =
'pending'
SUCCESS =
'success'
ERROR =
'error'
FAILURE =
'failure'
ALLOWED_STATUS =
[PENDING, SUCCESS, ERROR, FAILURE]

Instance Method Summary collapse

Instance Method Details

#decide_context(text) ⇒ Object



26
27
28
# File 'lib/github_status_notifier/notifier.rb', line 26

def decide_context(text)
  text || 'github_status_notifier'
end

#decide_state(state, exit_status) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/github_status_notifier/notifier.rb', line 30

def decide_state(state, exit_status)
  if state
    return state.downcase if ALLOWED_STATUS.include?(state.downcase)
    fail Error("state: #{state} is invalid. allowed #{ALLOWED_STATUS}")
  elsif exit_status
    return SUCCESS if exit_status.to_i == 0
    return FAILURE
  else
    fail Error('require state or exit-state')
  end
end

#loggerObject



42
43
44
# File 'lib/github_status_notifier/notifier.rb', line 42

def logger
  ::GithubStatusNotifier.logger
end

#notify(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/github_status_notifier/notifier.rb', line 9

def notify(params)
  state = decide_state(params[:state], params[:exit_status])
  repo_path = '.'
  repo = Repository.new(repo_path)
  client = Client.new(repo)
  pass_params = {
    target_url: params[:target_url],
    description: params[:description],
    context: decide_context(params[:context])
  }
  client.create_status(state, pass_params)
rescue StandardError => e
  logger.error e.message
  logger.error e.backtrace
  client.create_status(ERROR, pass_params)
end