Exception: Escobar::GitHub::DeploymentError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/escobar/github/deployment_error.rb

Overview

Consolidate GitHub deployment api failures for easier messaging

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, response, required_commit_contexts) ⇒ DeploymentError

Returns a new instance of DeploymentError.



7
8
9
10
11
# File 'lib/escobar/github/deployment_error.rb', line 7

def initialize(repo, response, required_commit_contexts)
  @repo = repo
  @response = response
  @required_commit_contexts = required_commit_contexts
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



5
6
7
# File 'lib/escobar/github/deployment_error.rb', line 5

def repo
  @repo
end

#required_commit_contextsObject

Returns the value of attribute required_commit_contexts.



5
6
7
# File 'lib/escobar/github/deployment_error.rb', line 5

def required_commit_contexts
  @required_commit_contexts
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/escobar/github/deployment_error.rb', line 5

def response
  @response
end

Instance Method Details

#default_messageObject



36
37
38
# File 'lib/escobar/github/deployment_error.rb', line 36

def default_message
  "Unable to create GitHub deployments for #{repo}: #{response_message}"
end

#missing_contextsObject



28
29
30
# File 'lib/escobar/github/deployment_error.rb', line 28

def missing_contexts
  required_commit_contexts - succeeded_required_contexts
end

#missing_contexts?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/escobar/github/deployment_error.rb', line 13

def missing_contexts?
  missing_contexts.any?
end

#response_messageObject



32
33
34
# File 'lib/escobar/github/deployment_error.rb', line 32

def response_message
  response["message"]
end

#succeeded_required_contextsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/escobar/github/deployment_error.rb', line 17

def succeeded_required_contexts
  error = response.fetch("errors", [])[0]
  return [] unless error && error["field"] == "required_contexts"
  contexts = error["contexts"]
  contexts.each_with_object([]) do |context, succeeded|
    success = (context["state"] == "success")
    required = required_commit_contexts.include?(context["context"])
    succeeded << context["context"] if required && success
  end
end