BigW Consortium Gitlab

Commit 52352dcc by Grzegorz Bizon

Move badge implementation to builds controller

parent 442a49db
class Projects::BuildsController < Projects::ApplicationController
before_action :build, except: [:index, :cancel_all]
before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry]
before_action :authorize_update_build!, except: [:index, :show, :status]
layout 'project'
layout "project"
# Skip authentication for status badge only
skip_before_action :authenticate_user!, :reject_blocked!, :project,
:repository, :authorize_manage_builds!, :build, only: [:badge]
def index
@scope = params[:scope]
......@@ -24,7 +26,6 @@ class Projects::BuildsController < Projects::ApplicationController
def cancel_all
@project.builds.running_or_pending.each(&:cancel)
redirect_to namespace_project_builds_path(project.namespace, project)
end
......@@ -47,7 +48,6 @@ class Projects::BuildsController < Projects::ApplicationController
end
build = Ci::Build.retry(@build)
redirect_to build_path(build)
end
......@@ -57,10 +57,15 @@ class Projects::BuildsController < Projects::ApplicationController
def cancel
@build.cancel
redirect_to build_path(@build)
end
def badge
project = Project.find_with_namespace("#{params[:namespace_id]}/#{params[:project_id]}")
image = Ci::ImageForBuildService.new.execute(project, ref: params[:ref])
send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml')
end
private
def build
......
......@@ -10,11 +10,6 @@ class Projects::CommitController < Projects::ApplicationController
before_action :commit
before_action :define_show_vars, only: [:show, :builds]
# Skip authentication for status badge only
skip_before_action :authenticate_user!, :reject_blocked!, :project,
:repository, :require_non_empty_project, :authorize_download_code!,
:commit, only: [:badge]
def show
return git_not_found! unless @commit
......@@ -62,12 +57,6 @@ class Projects::CommitController < Projects::ApplicationController
render layout: false
end
def badge
project = Project.find_with_namespace("#{params[:namespace_id]}/#{params[:project_id]}")
image = Ci::ImageForBuildService.new.execute(project, ref: params[:id])
send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml')
end
private
def commit
......
......@@ -493,13 +493,6 @@ Rails.application.routes.draw do
constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
as: :commits
)
get(
'/status/*id/badge',
to: 'commit#badge',
constraints: { format: /png/ },
as: :build_badge
)
end
resource :avatar, only: [:show, :destroy]
......@@ -615,9 +608,11 @@ Rails.application.routes.draw do
resource :variables, only: [:show, :update]
resources :triggers, only: [:index, :create, :destroy]
resources :builds, only: [:index, :show] do
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do
post :cancel_all
get :badge, path: 'status/*ref/badge',
constraints: { ref: Gitlab::Regex.git_reference_regex, format: /svg/ }
end
member do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment