Class: Capistrano::Redmine::Deployment::Client
- Inherits:
-
Object
- Object
- Capistrano::Redmine::Deployment::Client
- Defined in:
- lib/capistrano/redmine/deployment/client.rb
Overview
HTTP layer that talks to the Redmine-side redmine_deployment plugin.
The client POSTs deployment receipts to, and GETs deployment entries
from, {host}/projects/{project}/deploy/{repository}.json, authenticating
with an X-Redmine-API-Key header. A response carrying a deployment key
is treated as success; anything else (or an errors array) is a failure.
All connection details (host, project, repository, api_key, ca_file,
host_verification) are read from the supplied Config. SSL is enabled
automatically when the host URI uses the https scheme. Console logging
is on by default and can be turned off via #silent! or the logging:
initializer flag.
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
The resolved configuration this client reads from.
Class Method Summary collapse
-
.deploy_fail!(config, deployment) ⇒ Boolean
Logs a failed deployment.
-
.deploy_success!(config, deployment) ⇒ Boolean
Logs a successful deployment.
-
.receive_deployment(config) ⇒ Hash, ...
Fetches a single deployment entry to verify connectivity.
Instance Method Summary collapse
-
#deploy!(deployment) ⇒ Boolean
POSTs a deployment receipt to Redmine.
-
#initialize(config, logging: true) ⇒ Client
constructor
A new instance of Client.
-
#log? ⇒ Boolean
Whether console logging is currently enabled.
-
#receive_deployment ⇒ Hash, ...
Receives a single deployment entry from the redmine repository.
-
#silent! ⇒ false
Disables console logging for this client.
Constructor Details
#initialize(config, logging: true) ⇒ Client
Returns a new instance of Client.
81 82 83 84 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 81 def initialize(config, logging: true) @config = config @logging = logging end |
Instance Attribute Details
#config ⇒ Config (readonly)
Returns the resolved configuration this client reads from.
31 32 33 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 31 def config @config end |
Class Method Details
.deploy_fail!(config, deployment) ⇒ Boolean
Logs a failed deployment.
Tags the deployment as 'fail' and POSTs it to Redmine via a fresh
instance.
58 59 60 61 62 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 58 def deploy_fail!(config, deployment) deployment[:result] = 'fail' new(config).deploy!(deployment) end |
.deploy_success!(config, deployment) ⇒ Boolean
Logs a successful deployment.
Tags the deployment as 'success' and POSTs it to Redmine via a
fresh instance.
43 44 45 46 47 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 43 def deploy_success!(config, deployment) deployment[:result] = 'success' new(config).deploy!(deployment) end |
.receive_deployment(config) ⇒ Hash, ...
Fetches a single deployment entry to verify connectivity.
Convenience wrapper that builds a fresh instance and delegates to #receive_deployment.
72 73 74 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 72 def receive_deployment(config) new(config).receive_deployment end |
Instance Method Details
#deploy!(deployment) ⇒ Boolean
POSTs a deployment receipt to Redmine.
Logs the outgoing deployment, sends it, and reports the outcome. A
response containing a deployment key counts as success; anything
else is logged as an error.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 109 def deploy!(deployment) log_deploy(deployment) if log? response = send_deployment(deployment) if response['deployment'] log_deploy_done(response) if log? true else log_deploy_errors(response) if log? false end end |
#log? ⇒ Boolean
Returns whether console logging is currently enabled.
94 95 96 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 94 def log? @logging end |
#receive_deployment ⇒ Hash, ...
Receives a single deployment entry from the redmine repository.
Used to verify that the configured credentials / host / project / repository actually resolve to a reachable redmine_deployment endpoint. A successful response with NO entries is still considered valid - it just means no deployment has been logged yet.
135 136 137 138 139 140 141 142 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 135 def receive_deployment response = fetch_deployments return false unless response.is_a?(Hash) return false if response['errors'] extract_deployment(response) end |
#silent! ⇒ false
Disables console logging for this client.
89 90 91 |
# File 'lib/capistrano/redmine/deployment/client.rb', line 89 def silent! @logging = false end |