Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /task/:id to redirect to deploys/tasks/rollbacks #886

Merged
merged 3 commits into from Apr 9, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -2,7 +2,7 @@ module Shipit
class TasksController < ShipitController
include Pagination

before_action :stack
before_action :stack, except: [:lookup]

self.default_page_size = 20

@@ -50,8 +50,20 @@ def tail
render json: TailTaskSerializer.new(task, context: params)
end

def lookup
@task = Task.find(params[:id])

redirect_to url_for_task
end

private

def url_for_task
base_task = @task.is_a?(Deploy) ? @task.becomes(Deploy) : @task

url_for([base_task.stack, base_task])
end

def task
@task ||= stack.tasks.find(params[:id])
end
@@ -7,7 +7,7 @@ class Commit < ActiveRecord::Base
belongs_to :stack
has_many :deploys
has_many :statuses, -> { order(created_at: :desc) }, dependent: :destroy, inverse_of: :commit
has_many :check_runs, -> { order(created_at: :desc) }, dependent: :destroy
has_many :check_runs, -> { order(created_at: :desc) }, dependent: :destroy, inverse_of: :commit
has_many :commit_deployments, dependent: :destroy
has_many :release_statuses, dependent: :destroy
belongs_to :pull_request, inverse_of: :merge_commit, optional: true
@@ -65,6 +65,10 @@
post :clear_git_cache, controller: :stacks
end

scope '/task/:id', controller: :tasks do
get '/', action: :lookup
end

scope '/*stack_id', stack_id: stack_id_format, as: :stack do
get '/commit/:sha/checks' => 'commit_checks#show', as: :commit_checks
get '/commit/:sha/checks/tail' => 'commit_checks#tail', as: :tail_commit_checks, defaults: {format: :json}
@@ -123,5 +123,29 @@ class TasksControllerTest < ActionController::TestCase
assert_response :success
assert_json_keys %w(status output rollback_url)
end

test ":lookup returns stack task url if the task is an instance of Task" do
@task = shipit_tasks(:shipit_restart)

get :lookup, params: {id: @task.id}

assert_redirected_to stack_task_path(@task.stack, @task)
end

test ":lookup returns stack deploy url if the task is an instance of Deploy" do
@task = shipit_tasks(:shipit)

get :lookup, params: {id: @task.id}

assert_redirected_to stack_deploy_path(@task.stack, @task)
end

test ":lookup returns stack deploy url if the task is an instance of Rollback" do
@task = shipit_tasks(:shipit_rollback)

get :lookup, params: {id: @task.id}

assert_redirected_to stack_deploy_path(@task.stack, @task)
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.