Class: GithubStatusNotifier::Notifier
- Inherits:
-
Object
- Object
- GithubStatusNotifier::Notifier
- 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]
- CONTEXT =
'github_status_notifier'
Instance Method Summary collapse
- #decide_context(text) ⇒ Object
- #decide_state(state, exit_status) ⇒ Object
- #logger ⇒ Object
- #notify(params = {}) ⇒ Object
Instance Method Details
#decide_context(text) ⇒ Object
26 27 28 |
# File 'lib/github_status_notifier/notifier.rb', line 26 def decide_context(text) text || CONTEXT 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 InvalidStateError, "state: #{state} is invalid. allowed #{ALLOWED_STATUS}" elsif exit_status return SUCCESS if exit_status.to_i == 0 return FAILURE else fail ArgumentError, 'require state or exit-state' end end |
#logger ⇒ Object
42 43 44 |
# File 'lib/github_status_notifier/notifier.rb', line 42 def logger ::GithubStatusNotifier.logger end |
#notify(params = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/github_status_notifier/notifier.rb', line 10 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. logger.error e.backtrace end |