Introduce Projects::ArtifactsController#search:

So we redirect from ref and build_name to the particular build, namely:

* /u/r/artifacts/ref/build_name/* -> /u/r/builds/:build_id/artifacts/*

For:

* download
* browse
* file
This commit is contained in:
Lin Jen-Shin 2016-07-11 18:17:32 +08:00
parent 8f469c33cc
commit f601ec54fc
2 changed files with 28 additions and 2 deletions

View File

@ -35,14 +35,34 @@ class Projects::ArtifactsController < Projects::ApplicationController
redirect_to namespace_project_build_path(project.namespace, project, build)
end
def search
url = namespace_project_build_url(project.namespace, project, build)
if params[:path]
redirect_to "#{url}/artifacts/#{params[:path]}"
else
render_404
end
end
private
def validate_artifacts!
render_404 unless build.artifacts?
render_404 unless build && build.artifacts?
end
def build
@build ||= project.builds.find_by!(id: params[:build_id])
@build ||= build_from_id || build_from_ref
end
def build_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id]
end
def build_from_ref
if params[:ref]
project.builds_for(params[:build_name], params[:ref]).latest.first
end
end
def artifacts_file

View File

@ -733,6 +733,12 @@ Rails.application.routes.draw do
resources :environments, only: [:index, :show, :new, :create, :destroy]
resources :artifacts, only: [] do
collection do
get :search, path: ':ref/:build_name(/*path)', format: false
end
end
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do
post :cancel_all