Module: AutomateSoup
- Defined in:
- lib/automate_soup.rb,
lib/automate_soup/api.rb,
lib/automate_soup/rest.rb,
lib/automate_soup/stage.rb,
lib/automate_soup/change.rb,
lib/automate_soup/version.rb,
lib/automate_soup/credentials.rb
Overview
Top level module
Defined Under Namespace
Modules: Rest Classes: API, Change, Credentials, Stage
Constant Summary collapse
- VERSION =
'0.2.6'
Class Attribute Summary collapse
-
.api ⇒ Object
Returns the value of attribute api.
-
.credentials ⇒ Object
Returns the value of attribute credentials.
-
.enterprise ⇒ Object
Returns the value of attribute enterprise.
-
.organization ⇒ Object
Returns the value of attribute organization.
-
.pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Fetch a projects pipeline under an enterprise, organization pair.
-
.project ⇒ Object
Returns the value of attribute project.
-
.url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.approve_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean
Approve a change by change topic.
-
.change_by_topic(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil) ⇒ AutomateSoup::Change
Find a change by topic.
-
.deliver_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean
Delivery a change by a topic.
-
.orgs(enterprise = 'default') ⇒ Object
Fetch all organizations under an enterprise.
-
.pipeline_topics(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Array
Filters out the topics from the pipelines changes .
-
.pipelines(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch all project pipelines under an enterprise, organization pair.
-
.projects(enterprise: 'default', organization: nil) ⇒ Object
Get the projects under and organization given the enterprise.
-
.setup(url: nil, username: nil, token: nil, password: nil, enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Setup Automate Soup client.
-
.status ⇒ Object
Check the status of Automate.
Class Attribute Details
.api ⇒ Object
Returns the value of attribute api.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def api @api end |
.credentials ⇒ Object
Returns the value of attribute credentials.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def credentials @credentials end |
.enterprise ⇒ Object
Returns the value of attribute enterprise.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def enterprise @enterprise end |
.organization ⇒ Object
Returns the value of attribute organization.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def organization @organization end |
.pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Fetch a projects pipeline under an enterprise, organization pair
default.
95 96 97 |
# File 'lib/automate_soup.rb', line 95 def pipeline @pipeline end |
.project ⇒ Object
Returns the value of attribute project.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def project @project end |
.url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/automate_soup.rb', line 14 def url @url end |
Class Method Details
.approve_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean
Approve a change by change topic.
default. to 10
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/automate_soup.rb', line 160 def approve_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) return true if !o.nil? && o.delivered? if wait && !o.approvable? && !o.deliverable? times = 1 while times <= retries o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) break if o.approvable? return false if o.current_stage.failed? puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}" sleep timeout times += 1 end end app = o.approve return true if !wait && !app.nil? && o.deliverable? if app.nil? && !o.deliverable? puts "Could not approve change #{o.current_stage.stage}: #{o.current_stage.status}" return false end times = 1 while times <= retries o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) break if o.deliverable? return false if o.current_stage.failed? puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}" times += 1 sleep timeout end true end |
.change_by_topic(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil) ⇒ AutomateSoup::Change
Find a change by topic.
default.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/automate_soup.rb', line 133 def change_by_topic(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil) o = self.pipeline( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline ).select { |p| p.topic.eql?(topic) } first = o.first raise "Cannot find topic #{topic} in #{o}" if first.nil? AutomateSoup::Change.new first end |
.deliver_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean
Delivery a change by a topic
default. to 10
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/automate_soup.rb', line 230 def deliver_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) return false if !o.deliverable? if wait && !o.deliverable? times = 1 while times <= retries o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) break if o.deliverable? return false if o.current_stage.failed? puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}" sleep timeout times += 1 end end de = o.deliver return true if !wait && !de.nil? && o.delivered? if de.nil? && !o.deliverable? puts "Could not deliver change #{o.current_stage.stage}: #{o.current_stage.status}" return false end times = 1 while times <= retries o = self.change_by_topic( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline, topic: topic ) break if o.delivered? return false if o.current_stage.failed? puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}" times += 1 sleep timeout end true end |
.orgs(enterprise = 'default') ⇒ Object
Fetch all organizations under an enterprise
59 60 61 |
# File 'lib/automate_soup.rb', line 59 def orgs(enterprise = 'default') @api.orgs enterprise end |
.pipeline_topics(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Array
Filters out the topics from the pipelines changes .
default.
113 114 115 116 117 118 119 120 |
# File 'lib/automate_soup.rb', line 113 def pipeline_topics(enterprise: 'default', organization: nil, project: nil, pipeline: nil) self.pipeline( enterprise: enterprise, organization: organization, project: project, pipeline: pipeline ).map { |p| p.topic } end |
.pipelines(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch all project pipelines under an enterprise, organization pair
default.
82 83 84 |
# File 'lib/automate_soup.rb', line 82 def pipelines(enterprise: 'default', organization: nil, project: nil) @api.pipelines(enterprise: enterprise, organization: organization, project: project) end |
.projects(enterprise: 'default', organization: nil) ⇒ Object
Get the projects under and organization given the enterprise.
default.
70 71 72 |
# File 'lib/automate_soup.rb', line 70 def projects(enterprise: 'default', organization: nil) @api.projects(enterprise: enterprise, organization: organization) end |
.setup(url: nil, username: nil, token: nil, password: nil, enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Setup Automate Soup client.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/automate_soup.rb', line 24 def setup( url: nil, username: nil, token: nil, password: nil, enterprise: 'default', organization: nil, project: nil, pipeline: nil ) @url = url @credentials = if token token_credentials(username, token) else password_credentials(username, password) end @api = AutomateSoup::API.new(self) @enterprise = enterprise @organization = organization @project = project @pipeline = pipeline self end |
.status ⇒ Object
Check the status of Automate
51 52 53 54 |
# File 'lib/automate_soup.rb', line 51 def status o = @api.status OpenStruct.new o end |