Class: Shipit::Api::RollbacksController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/shipit/api/rollbacks_controller.rb

Constant Summary

Constants included from Paginable

Paginable::LINK

Instance Method Summary collapse

Methods inherited from BaseController

#index, require_permission

Methods included from Cacheable

#render_resource, #render_resources

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/shipit/api/rollbacks_controller.rb', line 14

def create
  commit = stack.commits.by_sha(params.sha) || param_error!(:sha, 'Unknown revision')
  param_error!(:force, "Can't rollback a locked stack") if !params.force && stack.locked?
  deploy = stack.deploys.find_by(until_commit: commit) || param_error!(:sha, 'Cant find associated deploy')
  rollback_env = stack.filter_rollback_envs(params.env)

  response = nil
  if !params.force && stack.active_task?
    param_error!(:force, "Can't rollback, deploy in progress")
  elsif stack.active_task?
    active_task = stack.active_task
    active_task.abort!(aborted_by: current_user, rollback_once_aborted_to: deploy, rollback_once_aborted: true)
    response = active_task
  else
    response = deploy.trigger_rollback(current_user, env: rollback_env, force: params.force, lock: params.lock)
  end

  render_resource(response, status: :accepted)
end