From 6fdbc22960d36111b501c5feeb33192edf47684f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 1 Mar 2017 14:48:44 +0100 Subject: [PATCH 1/4] Remove deprecated legacy CI project status badge --- app/controllers/ci/projects_controller.rb | 47 ------------ app/services/ci/image_for_build_service.rb | 25 ------- config/routes/ci.rb | 8 +- .../ci/projects_controller_spec.rb | 74 ------------------- 4 files changed, 1 insertion(+), 153 deletions(-) delete mode 100644 app/controllers/ci/projects_controller.rb delete mode 100644 app/services/ci/image_for_build_service.rb delete mode 100644 spec/controllers/ci/projects_controller_spec.rb diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb deleted file mode 100644 index ff297d6ff13..00000000000 --- a/app/controllers/ci/projects_controller.rb +++ /dev/null @@ -1,47 +0,0 @@ -module Ci - class ProjectsController < ::ApplicationController - before_action :project - before_action :no_cache, only: [:badge] - before_action :authorize_read_project!, except: [:badge, :index] - skip_before_action :authenticate_user!, only: [:badge] - protect_from_forgery - - def index - redirect_to root_path - end - - def show - # Temporary compatibility with CI badges pointing to CI project page - redirect_to namespace_project_path(project.namespace, project) - end - - # Project status badge - # Image with build status for sha or ref - # - # This action in DEPRECATED, this is here only for backwards compatibility - # with projects migrated from GitLab CI. - # - def badge - return render_404 unless @project - - image = Ci::ImageForBuildService.new.execute(@project, params) - send_file image.path, filename: image.name, disposition: 'inline', type: "image/svg+xml" - end - - protected - - def project - @project ||= Project.find_by(ci_id: params[:id].to_i) - end - - def no_cache - response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" - response.headers["Pragma"] = "no-cache" - response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" - end - - def authorize_read_project! - return access_denied! unless can?(current_user, :read_project, project) - end - end -end diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb deleted file mode 100644 index 240ddabec36..00000000000 --- a/app/services/ci/image_for_build_service.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Ci - class ImageForBuildService - def execute(project, opts) - ref = opts[:ref] - sha = opts[:sha] || ref_sha(project, ref) - pipelines = project.pipelines.where(sha: sha) - - image_name = image_for_status(pipelines.latest_status(ref)) - image_path = Rails.root.join('public/ci', image_name) - - OpenStruct.new(path: image_path, name: image_name) - end - - private - - def ref_sha(project, ref) - project.commit(ref).try(:sha) if ref - end - - def image_for_status(status) - status ||= 'unknown' - 'build-' + status + ".svg" - end - end -end diff --git a/config/routes/ci.rb b/config/routes/ci.rb index 47a049d5b20..8d23aa8fbf6 100644 --- a/config/routes/ci.rb +++ b/config/routes/ci.rb @@ -5,11 +5,5 @@ namespace :ci do resource :lint, only: [:show, :create] - resources :projects, only: [:index, :show] do - member do - get :status, to: 'projects#badge' - end - end - - root to: 'projects#index' + root to: redirect('/') end diff --git a/spec/controllers/ci/projects_controller_spec.rb b/spec/controllers/ci/projects_controller_spec.rb deleted file mode 100644 index 86f01f437a2..00000000000 --- a/spec/controllers/ci/projects_controller_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'spec_helper' - -describe Ci::ProjectsController do - let(:visibility) { :public } - let!(:project) { create(:empty_project, visibility, ci_id: 1) } - let(:ci_id) { project.ci_id } - - describe '#index' do - context 'user signed in' do - before do - sign_in(create(:user)) - get(:index) - end - - it 'redirects to /' do - expect(response).to redirect_to(root_path) - end - end - - context 'user not signed in' do - before { get(:index) } - - it 'redirects to sign in page' do - expect(response).to redirect_to(new_user_session_path) - end - end - end - - ## - # Specs for *deprecated* CI badge - # - describe '#badge' do - shared_examples 'badge provider' do - it 'shows badge' do - expect(response.status).to eq 200 - expect(response.headers) - .to include('Content-Type' => 'image/svg+xml') - end - end - - context 'user not signed in' do - before { get(:badge, id: ci_id) } - - context 'project has no ci_id reference' do - let(:ci_id) { 123 } - - it 'returns 404' do - expect(response.status).to eq 404 - end - end - - context 'project is public' do - let(:visibility) { :public } - it_behaves_like 'badge provider' - end - - context 'project is private' do - let(:visibility) { :private } - it_behaves_like 'badge provider' - end - end - - context 'user signed in' do - let(:user) { create(:user) } - before { sign_in(user) } - before { get(:badge, id: ci_id) } - - context 'private is internal' do - let(:visibility) { :internal } - it_behaves_like 'badge provider' - end - end - end -end From 3f2bb8d535608ed11f287d587568d7fe96857483 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 1 Mar 2017 14:50:17 +0100 Subject: [PATCH 2/4] Remove specs for legacy build image service --- .../ci/image_for_build_service_spec.rb | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 spec/services/ci/image_for_build_service_spec.rb diff --git a/spec/services/ci/image_for_build_service_spec.rb b/spec/services/ci/image_for_build_service_spec.rb deleted file mode 100644 index b3e0a7b9b58..00000000000 --- a/spec/services/ci/image_for_build_service_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -module Ci - describe ImageForBuildService, services: true do - let(:service) { ImageForBuildService.new } - let(:project) { FactoryGirl.create(:empty_project) } - let(:commit_sha) { '01234567890123456789' } - let(:pipeline) { project.ensure_pipeline('master', commit_sha) } - let(:build) { FactoryGirl.create(:ci_build, pipeline: pipeline) } - - describe '#execute' do - before { build } - - context 'branch name' do - before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) } - before { build.run! } - let(:image) { service.execute(project, ref: 'master') } - - it { expect(image).to be_kind_of(OpenStruct) } - it { expect(image.path.to_s).to include('public/ci/build-running.svg') } - it { expect(image.name).to eq('build-running.svg') } - end - - context 'unknown branch name' do - let(:image) { service.execute(project, ref: 'feature') } - - it { expect(image).to be_kind_of(OpenStruct) } - it { expect(image.path.to_s).to include('public/ci/build-unknown.svg') } - it { expect(image.name).to eq('build-unknown.svg') } - end - - context 'commit sha' do - before { build.run! } - let(:image) { service.execute(project, sha: build.sha) } - - it { expect(image).to be_kind_of(OpenStruct) } - it { expect(image.path.to_s).to include('public/ci/build-running.svg') } - it { expect(image.name).to eq('build-running.svg') } - end - - context 'unknown commit sha' do - let(:image) { service.execute(project, sha: '0000000') } - - it { expect(image).to be_kind_of(OpenStruct) } - it { expect(image.path.to_s).to include('public/ci/build-unknown.svg') } - it { expect(image.name).to eq('build-unknown.svg') } - end - end - end -end From 3896735f3d499690746bb1c49ddcbe05aa95c824 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 1 Mar 2017 14:51:02 +0100 Subject: [PATCH 3/4] Remove legacy build status svg for deprecated service --- public/ci/build-canceled.svg | 1 - public/ci/build-failed.svg | 1 - public/ci/build-pending.svg | 1 - public/ci/build-running.svg | 1 - public/ci/build-skipped.svg | 1 - public/ci/build-success.svg | 1 - public/ci/build-unknown.svg | 1 - 7 files changed, 7 deletions(-) delete mode 100644 public/ci/build-canceled.svg delete mode 100644 public/ci/build-failed.svg delete mode 100644 public/ci/build-pending.svg delete mode 100644 public/ci/build-running.svg delete mode 100644 public/ci/build-skipped.svg delete mode 100644 public/ci/build-success.svg delete mode 100644 public/ci/build-unknown.svg diff --git a/public/ci/build-canceled.svg b/public/ci/build-canceled.svg deleted file mode 100644 index 922e28bf696..00000000000 --- a/public/ci/build-canceled.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildcanceledcanceled \ No newline at end of file diff --git a/public/ci/build-failed.svg b/public/ci/build-failed.svg deleted file mode 100644 index 1aefd3f1761..00000000000 --- a/public/ci/build-failed.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildfailedfailed \ No newline at end of file diff --git a/public/ci/build-pending.svg b/public/ci/build-pending.svg deleted file mode 100644 index 536931af84d..00000000000 --- a/public/ci/build-pending.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildpendingpending \ No newline at end of file diff --git a/public/ci/build-running.svg b/public/ci/build-running.svg deleted file mode 100644 index 0d71eef3c34..00000000000 --- a/public/ci/build-running.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildrunningrunning \ No newline at end of file diff --git a/public/ci/build-skipped.svg b/public/ci/build-skipped.svg deleted file mode 100644 index f15507188e0..00000000000 --- a/public/ci/build-skipped.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildskippedskipped \ No newline at end of file diff --git a/public/ci/build-success.svg b/public/ci/build-success.svg deleted file mode 100644 index 43b67e45f42..00000000000 --- a/public/ci/build-success.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildsuccesssuccess \ No newline at end of file diff --git a/public/ci/build-unknown.svg b/public/ci/build-unknown.svg deleted file mode 100644 index c72a2f5a7f5..00000000000 --- a/public/ci/build-unknown.svg +++ /dev/null @@ -1 +0,0 @@ -buildbuildunknownunknown \ No newline at end of file From aa83c6ed2e70e7ac4c59821c419aae254c7271df Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 2 Mar 2017 11:55:46 +0100 Subject: [PATCH 4/4] Add Changelog for deprecated build badge removal --- .../fix-gb-remove-deprecated-ci-build-status-badge.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased/fix-gb-remove-deprecated-ci-build-status-badge.yml diff --git a/changelogs/unreleased/fix-gb-remove-deprecated-ci-build-status-badge.yml b/changelogs/unreleased/fix-gb-remove-deprecated-ci-build-status-badge.yml new file mode 100644 index 00000000000..71ff768a190 --- /dev/null +++ b/changelogs/unreleased/fix-gb-remove-deprecated-ci-build-status-badge.yml @@ -0,0 +1,4 @@ +--- +title: Remove deprecated build status badge and related services +merge_request: 9620 +author: