From 28b11963b1613f420aecbee6718d753a6f9733a9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 9 Feb 2016 13:10:16 +0100 Subject: [PATCH] Move builds badge implementation to new badges controller --- app/controllers/projects/badges_controller.rb | 11 +++++++++++ app/controllers/projects/builds_controller.rb | 10 ---------- config/routes.rb | 8 ++++++-- doc/ci/quick_start/README.md | 2 +- features/steps/project/builds/badge.rb | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 app/controllers/projects/badges_controller.rb diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb new file mode 100644 index 00000000000..a4dd94b941c --- /dev/null +++ b/app/controllers/projects/badges_controller.rb @@ -0,0 +1,11 @@ +class Projects::BadgesController < Projects::ApplicationController + def build + respond_to do |format| + format.html { render_404 } + format.svg do + image = Ci::ImageForBuildService.new.execute(project, ref: params[:ref]) + send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml') + end + end + end +end diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 0aef477811f..ec379c53b8f 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -56,16 +56,6 @@ class Projects::BuildsController < Projects::ApplicationController render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha) end - def badge - respond_to do |format| - format.html { render_404 } - format.svg do - image = Ci::ImageForBuildService.new.execute(project, ref: params[:ref]) - send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml') - end - end - end - private def build diff --git a/config/routes.rb b/config/routes.rb index 081ff428406..507bcbc53d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -611,8 +611,6 @@ Rails.application.routes.draw 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 @@ -699,6 +697,12 @@ Rails.application.routes.draw do end resources :runner_projects, only: [:create, :destroy] + resources :badges, only: [], path: 'badges/*ref', + constraints: { ref: Gitlab::Regex.git_reference_regex } do + collection do + get :build, constraints: { format: /svg/ } + end + end end end end diff --git a/doc/ci/quick_start/README.md b/doc/ci/quick_start/README.md index 6598843049e..ae7b760fa67 100644 --- a/doc/ci/quick_start/README.md +++ b/doc/ci/quick_start/README.md @@ -189,7 +189,7 @@ GitLab, such as **Commits** and **Merge Requests**. You can access a builds badge image using following link: ``` -http://example.gitlab.com/namespace/project/builds/status/branch/badge.svg +http://example.gitlab.com/namespace/project/badges/branch/build.svg ``` ## Next steps diff --git a/features/steps/project/builds/badge.rb b/features/steps/project/builds/badge.rb index 65f5e0f766f..52ef3b4484e 100644 --- a/features/steps/project/builds/badge.rb +++ b/features/steps/project/builds/badge.rb @@ -5,7 +5,7 @@ class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps include RepoHelpers step 'I display builds badge for a master branch' do - visit badge_namespace_project_builds_path(@project.namespace, @project, ref: :master, format: :svg) + visit build_namespace_project_badges_path(@project.namespace, @project, ref: :master, format: :svg) end step 'I should see a build success badge' do -- GitLab