diff options
author | Rémy Coutable <remy@rymai.me> | 2017-03-02 15:48:19 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-03-02 15:48:19 +0300 |
commit | 9f181b33258e606e3ac2815103ba39a4089ce6f4 (patch) | |
tree | f0590eab79a52104d63962ec979c66a6c02f77bf | |
parent | be49b15a732684d0a95cf4e69baf677ab3bab3ab (diff) | |
parent | aa83c6ed2e70e7ac4c59821c419aae254c7271df (diff) |
Merge branch 'fix/gb/remove-deprecated-ci-build-status-badge' into 'master'
Remove deprecated build status badge and related services
Closes #14757
See merge request !9620
-rw-r--r-- | app/controllers/ci/projects_controller.rb | 47 | ||||
-rw-r--r-- | app/services/ci/image_for_build_service.rb | 25 | ||||
-rw-r--r-- | changelogs/unreleased/fix-gb-remove-deprecated-ci-build-status-badge.yml | 4 | ||||
-rw-r--r-- | config/routes/ci.rb | 8 | ||||
-rw-r--r-- | public/ci/build-canceled.svg | 1 | ||||
-rw-r--r-- | public/ci/build-failed.svg | 1 | ||||
-rw-r--r-- | public/ci/build-pending.svg | 1 | ||||
-rw-r--r-- | public/ci/build-running.svg | 1 | ||||
-rw-r--r-- | public/ci/build-skipped.svg | 1 | ||||
-rw-r--r-- | public/ci/build-success.svg | 1 | ||||
-rw-r--r-- | public/ci/build-unknown.svg | 1 | ||||
-rw-r--r-- | spec/controllers/ci/projects_controller_spec.rb | 74 | ||||
-rw-r--r-- | spec/services/ci/image_for_build_service_spec.rb | 50 |
13 files changed, 5 insertions, 210 deletions
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/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: 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/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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="97" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="97" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#9f9f9f" d="M37 0h60v20H37z"/><path fill="url(#b)" d="M0 0h97v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="66" y="15" fill="#010101" fill-opacity=".3">canceled</text><text x="66" y="14">canceled</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#e05d44" d="M37 0h41v20H37z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="56.5" y="15" fill="#010101" fill-opacity=".3">failed</text><text x="56.5" y="14">failed</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="92" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="92" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#dfb317" d="M37 0h55v20H37z"/><path fill="url(#b)" d="M0 0h92v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="63.5" y="15" fill="#010101" fill-opacity=".3">pending</text><text x="63.5" y="14">pending</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="90" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="90" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#dfb317" d="M37 0h53v20H37z"/><path fill="url(#b)" d="M0 0h90v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="62.5" y="15" fill="#010101" fill-opacity=".3">running</text><text x="62.5" y="14">running</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="97" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="97" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#9f9f9f" d="M37 0h60v20H37z"/><path fill="url(#b)" d="M0 0h97v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="66" y="15" fill="#010101" fill-opacity=".3">skipped</text><text x="66" y="14">skipped</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="91" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="91" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#4c1" d="M37 0h54v20H37z"/><path fill="url(#b)" d="M0 0h91v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="63" y="15" fill="#010101" fill-opacity=".3">success</text><text x="63" y="14">success</text></g></svg>
\ 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 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="98" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="98" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h37v20H0z"/><path fill="#9f9f9f" d="M37 0h61v20H37z"/><path fill="url(#b)" d="M0 0h98v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="18.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="18.5" y="14">build</text><text x="66.5" y="15" fill="#010101" fill-opacity=".3">unknown</text><text x="66.5" y="14">unknown</text></g></svg>
\ No newline at end of file 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 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 |