From a2f61368f9d62cded366a3b8813969f66c4be4dd Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 08:54:23 +0100 Subject: [PATCH 01/17] Add deprecation warning for old CI status badge action We keep this only for backwards compatibility with projects that have been migrated from GitLab CI. New project badge will go elsewhere. --- app/controllers/ci/projects_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 711c2847d5..7838994433 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -12,9 +12,12 @@ module Ci # 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 image = Ci::ImageForBuildService.new.execute(@project, params) - send_file image.path, filename: image.name, disposition: 'inline', type:"image/svg+xml" end From 01a406f5b02a7c8f5133012931b56696c3d21fe8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 08:55:25 +0100 Subject: [PATCH 02/17] Render 404 if there is no project for old CI status badge --- app/controllers/ci/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 7838994433..d1824b481d 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -17,6 +17,7 @@ module Ci # 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 From 14f928b73005300f419adb839cfd7bb06435abb8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 12:38:10 +0100 Subject: [PATCH 03/17] Add CI status badge implementation to commit controller --- app/controllers/projects/commit_controller.rb | 6 ++++++ config/routes.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 21f4d9f44e..637a911177 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -57,6 +57,12 @@ class Projects::CommitController < Projects::ApplicationController render layout: false end + def status + status_sha = ci_commit.sha if ci_commit + image = Ci::ImageForBuildService.new.execute(@project, sha: status_sha) + send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml') + end + private def commit diff --git a/config/routes.rb b/config/routes.rb index 3f6561a1fe..30e42e197f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -493,6 +493,13 @@ Rails.application.routes.draw do constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }, as: :commits ) + + get( + '/status/*id/badge', + to: 'commit#status', + constraints: { format: /png/ }, + as: :commit_status + ) end resource :avatar, only: [:show, :destroy] From 28c4c949a5965f0328bb94d7ab1a318c9e226ff7 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 14:22:58 +0100 Subject: [PATCH 04/17] Improve CI status badge implementation --- app/controllers/projects/commit_controller.rb | 5 ++--- app/services/ci/image_for_build_service.rb | 19 +++++++------------ config/routes.rb | 4 ++-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 637a911177..36fef1740e 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -57,9 +57,8 @@ class Projects::CommitController < Projects::ApplicationController render layout: false end - def status - status_sha = ci_commit.sha if ci_commit - image = Ci::ImageForBuildService.new.execute(@project, sha: status_sha) + def badge + image = Ci::ImageForBuildService.new.execute(@project, ref: params[:id]) send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml') end diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb index f469b13e90..005a5c4661 100644 --- a/app/services/ci/image_for_build_service.rb +++ b/app/services/ci/image_for_build_service.rb @@ -1,28 +1,23 @@ module Ci class ImageForBuildService - def execute(project, params) - sha = params[:sha] - sha ||= - if params[:ref] - project.commit(params[:ref]).try(:sha) - end + def execute(project, opts) + sha = opts[:sha] || ref_sha(project, opts[:ref]) commit = project.ci_commits.ordered.find_by(sha: sha) image_name = image_for_commit(commit) image_path = Rails.root.join('public/ci', image_name) - - OpenStruct.new( - path: image_path, - name: 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_commit(commit) return 'build-unknown.svg' unless commit - 'build-' + commit.status + ".svg" end end diff --git a/config/routes.rb b/config/routes.rb index 30e42e197f..152a04061f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -496,9 +496,9 @@ Rails.application.routes.draw do get( '/status/*id/badge', - to: 'commit#status', + to: 'commit#badge', constraints: { format: /png/ }, - as: :commit_status + as: :commit_badge ) end From 442a49db2bc5e3f6cea827879fa4f5c532a5f6f1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 14:42:01 +0100 Subject: [PATCH 05/17] Skip authentication when requesting commit status badge --- app/controllers/projects/commit_controller.rb | 8 +++++++- config/routes.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 36fef1740e..493cd332d9 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -10,6 +10,11 @@ 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 @@ -58,7 +63,8 @@ class Projects::CommitController < Projects::ApplicationController end def badge - image = Ci::ImageForBuildService.new.execute(@project, ref: params[:id]) + 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 diff --git a/config/routes.rb b/config/routes.rb index 152a04061f..6b710bc45e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -498,7 +498,7 @@ Rails.application.routes.draw do '/status/*id/badge', to: 'commit#badge', constraints: { format: /png/ }, - as: :commit_badge + as: :build_badge ) end From 52352dccc377a2f9f89c1e749f21b9ebd986f7c3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 08:51:10 +0100 Subject: [PATCH 06/17] Move badge implementation to builds controller --- app/controllers/projects/builds_controller.rb | 15 ++++++++++----- app/controllers/projects/commit_controller.rb | 11 ----------- config/routes.rb | 11 +++-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 9e89296e71..8ca6e02dab 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -1,10 +1,12 @@ 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 diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 493cd332d9..21f4d9f44e 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 6b710bc45e..ea14ba3819 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 From 479d412e09bb8ce9550aef83af42aa60766ea812 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 08:57:09 +0100 Subject: [PATCH 07/17] Respond to proper format for build badge request --- app/controllers/projects/builds_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 8ca6e02dab..9d419b07e5 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -62,8 +62,14 @@ class Projects::BuildsController < Projects::ApplicationController 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') + + 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 From eb7721e183337784de9fcaf219a64d443b6b3f0c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 10:34:19 +0100 Subject: [PATCH 08/17] Add second build for each commit in build seeds --- db/fixtures/development/14_builds.rb | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 03a1232384..e3ca2b4eea 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,24 +1,13 @@ class Gitlab::Seeder::Builds - BUILD_STATUSES = %w(running pending success failed canceled) - def initialize(project) @project = project end def seed! ci_commits.each do |ci_commit| - build = Ci::Build.new(build_attributes_for(ci_commit)) - - artifacts_cache_file(artifacts_archive_path) do |file| - build.artifacts_file = file - end - - artifacts_cache_file(artifacts_metadata_path) do |file| - build.artifacts_metadata = file - end - begin - build.save! + build_create!(ci_commit, name: 'test build 1') + build_create!(ci_commit, status: 'success', name: 'test build 2') print '.' rescue ActiveRecord::RecordInvalid print 'F' @@ -36,6 +25,28 @@ class Gitlab::Seeder::Builds [] end + def build_create!(ci_commit, opts = {}) + attributes = build_attributes_for(ci_commit).merge(opts) + build = Ci::Build.new(attributes) + + if %w(success failed).include?(build.status) + artifacts_cache_file(artifacts_archive_path) do |file| + build.artifacts_file = file + end + + artifacts_cache_file(artifacts_metadata_path) do |file| + build.artifacts_metadata = file + end + end + + build.save! + + if %w(running success failed).include?(build.status) + # We need to set build trace after saving a build (id required) + build.trace = FFaker::Lorem.paragraphs(6).join("\n\n") + end + end + def build_attributes_for(ci_commit) { name: 'test build', commands: "$ build command", stage: 'test', stage_idx: 1, ref: 'master', @@ -49,7 +60,7 @@ class Gitlab::Seeder::Builds end def build_status - BUILD_STATUSES.sample + Ci::Build::AVAILABLE_STATUSES.sample end def artifacts_archive_path From cf0eab504772c05b067ca60f78bc76779342c912 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 12:23:56 +0100 Subject: [PATCH 09/17] Add feature tests for builds status badge --- features/project/builds/badge.feature | 17 +++++++++++++++++ features/steps/project/builds/badge.rb | 25 +++++++++++++++++++++++++ features/steps/shared/builds.rb | 12 ++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 features/project/builds/badge.feature create mode 100644 features/steps/project/builds/badge.rb diff --git a/features/project/builds/badge.feature b/features/project/builds/badge.feature new file mode 100644 index 0000000000..4a198488f3 --- /dev/null +++ b/features/project/builds/badge.feature @@ -0,0 +1,17 @@ +Feature: Project Builds Badge + Background: + Given project exists in some group namespace + And project has CI enabled + And project has a recent build + + Scenario: I want to see a badge for successfully built project + Given recent build is successfull + When I display builds badge for a master branch + Then I should see a build success badge + And build badge is a svg image + + Scenario: I want to see a badge for project with filed builds + Given recent build failed + When I display builds badge for a master branch + Then I should see a build failed badge + And build badge is a svg image diff --git a/features/steps/project/builds/badge.rb b/features/steps/project/builds/badge.rb new file mode 100644 index 0000000000..3cf1e2cab5 --- /dev/null +++ b/features/steps/project/builds/badge.rb @@ -0,0 +1,25 @@ +class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps + include SharedProject + include SharedBuilds + 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) + end + + step 'I should see a build success badge' do + expect(svg.at('text:contains("success")')).to be_truthy + end + + step 'I should see a build failed badge' do + expect(svg.at('text:contains("failed")')).to be_truthy + end + + step 'build badge is a svg image' do + expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') + end + + def svg + Nokogiri::HTML.parse(page.body) + end +end diff --git a/features/steps/shared/builds.rb b/features/steps/shared/builds.rb index 726e2e814a..055ebe1c81 100644 --- a/features/steps/shared/builds.rb +++ b/features/steps/shared/builds.rb @@ -6,8 +6,16 @@ module SharedBuilds end step 'project has a recent build' do - ci_commit = create :ci_commit, project: @project, sha: sample_commit.id - @build = create :ci_build, commit: ci_commit + @ci_commit = create(:ci_commit, project: @project, sha: @project.commit.sha) + @build = create(:ci_build, commit: @ci_commit) + end + + step 'recent build is successfull' do + @build.update_column(:status, 'success') + end + + step 'recent build failed' do + @build.update_column(:status, 'failed') end step 'I visit recent build details page' do From 29f2600ab6b04d95c7ef4fbfea7c4c9ecf638e97 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 12:42:35 +0100 Subject: [PATCH 10/17] Improve build badge tests, add another test case --- features/project/builds/badge.feature | 8 ++++++-- features/steps/project/builds/badge.rb | 13 +++++++++---- features/steps/shared/builds.rb | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/features/project/builds/badge.feature b/features/project/builds/badge.feature index 4a198488f3..64263b2f53 100644 --- a/features/project/builds/badge.feature +++ b/features/project/builds/badge.feature @@ -8,10 +8,14 @@ Feature: Project Builds Badge Given recent build is successfull When I display builds badge for a master branch Then I should see a build success badge - And build badge is a svg image Scenario: I want to see a badge for project with filed builds Given recent build failed When I display builds badge for a master branch Then I should see a build failed badge - And build badge is a svg image + + Scenario: I want to see a badge for project with running builds + Given recent build is successfull + And project has an another build that is running + When I display builds badge for a master branch + Then I should see a build running badge diff --git a/features/steps/project/builds/badge.rb b/features/steps/project/builds/badge.rb index 3cf1e2cab5..0ceb4ddcd2 100644 --- a/features/steps/project/builds/badge.rb +++ b/features/steps/project/builds/badge.rb @@ -8,18 +8,23 @@ class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps end step 'I should see a build success badge' do - expect(svg.at('text:contains("success")')).to be_truthy + expect_badge('success') end step 'I should see a build failed badge' do - expect(svg.at('text:contains("failed")')).to be_truthy + expect_badge('failed') end - step 'build badge is a svg image' do - expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') + step 'I should see a build running badge' do + expect_badge('running') end def svg Nokogiri::HTML.parse(page.body) end + + def expect_badge(status) + expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') + expect(svg.at(%Q{text:contains("#{status}")})).to be_truthy + end end diff --git a/features/steps/shared/builds.rb b/features/steps/shared/builds.rb index 055ebe1c81..7e1d9bb405 100644 --- a/features/steps/shared/builds.rb +++ b/features/steps/shared/builds.rb @@ -18,6 +18,10 @@ module SharedBuilds @build.update_column(:status, 'failed') end + step 'project has an another build that is running' do + create(:ci_build, commit: @ci_commit, name: 'second build', status: 'running') + end + step 'I visit recent build details page' do visit namespace_project_build_path(@project.namespace, @project, @build) end From 418e761ad132351b9d4ab2d7ae3e0742169ddc60 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 13:17:29 +0100 Subject: [PATCH 11/17] Add short builds badge documentation --- doc/ci/quick_start/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/ci/quick_start/README.md b/doc/ci/quick_start/README.md index a9b36139de..85f46469f8 100644 --- a/doc/ci/quick_start/README.md +++ b/doc/ci/quick_start/README.md @@ -184,6 +184,16 @@ you expected. You are also able to view the status of any commit in the various pages in GitLab, such as **Commits** and **Merge Requests**. +## Builds badge + +You can access a builds badge image using following link: + +``` +http://example.gitlab.com/namespace/project/builds/status/branch/badge.svg +``` + +Build badge is available for everyone, even if your project is private or internal. + ## Next steps Awesome! You started using CI in GitLab! From 7e1453f2f01d40f53d927ff43aae1baae3b4b272 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 13:18:37 +0100 Subject: [PATCH 12/17] Fix rubocop offence in routes for build badge --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index ea14ba3819..081ff42840 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -612,7 +612,7 @@ Rails.application.routes.draw do collection do post :cancel_all get :badge, path: 'status/*ref/badge', - constraints: { ref: Gitlab::Regex.git_reference_regex, format: /svg/ } + constraints: { ref: Gitlab::Regex.git_reference_regex, format: /svg/ } end member do From d51e8e1b77d78dd80a9fb9d362219b8b47b83904 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 13:53:30 +0100 Subject: [PATCH 13/17] Inherit build badge access permissions from project --- app/controllers/projects/builds_controller.rb | 14 ++++---------- doc/ci/quick_start/README.md | 2 -- features/project/builds/badge.feature | 3 ++- features/steps/project/builds/badge.rb | 1 + 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 9d419b07e5..0aef477811 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -4,10 +4,6 @@ class Projects::BuildsController < Projects::ApplicationController before_action :authorize_update_build!, except: [:index, :show, :status] 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] @all_builds = project.builds @@ -51,18 +47,16 @@ class Projects::BuildsController < Projects::ApplicationController redirect_to build_path(build) end - def status - render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha) - end - def cancel @build.cancel redirect_to build_path(@build) end - def badge - project = Project.find_with_namespace("#{params[:namespace_id]}/#{params[:project_id]}") + def status + 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 diff --git a/doc/ci/quick_start/README.md b/doc/ci/quick_start/README.md index 85f46469f8..6598843049 100644 --- a/doc/ci/quick_start/README.md +++ b/doc/ci/quick_start/README.md @@ -192,8 +192,6 @@ You can access a builds badge image using following link: http://example.gitlab.com/namespace/project/builds/status/branch/badge.svg ``` -Build badge is available for everyone, even if your project is private or internal. - ## Next steps Awesome! You started using CI in GitLab! diff --git a/features/project/builds/badge.feature b/features/project/builds/badge.feature index 64263b2f53..9eb34475e6 100644 --- a/features/project/builds/badge.feature +++ b/features/project/builds/badge.feature @@ -1,6 +1,7 @@ Feature: Project Builds Badge Background: - Given project exists in some group namespace + Given I sign in as a user + And I own a project And project has CI enabled And project has a recent build diff --git a/features/steps/project/builds/badge.rb b/features/steps/project/builds/badge.rb index 0ceb4ddcd2..65f5e0f766 100644 --- a/features/steps/project/builds/badge.rb +++ b/features/steps/project/builds/badge.rb @@ -1,4 +1,5 @@ class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps + include SharedAuthentication include SharedProject include SharedBuilds include RepoHelpers From ee1bee5834929f893ec560ddbd3947ef7caaadae Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 8 Feb 2016 14:00:59 +0100 Subject: [PATCH 14/17] Add Changelog entry for changes in builds badge --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index ceb5c17cae..e2a501fb82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -48,6 +48,7 @@ v 8.5.0 (unreleased) - Title for milestones should be unique (Zeger-Jan van de Weg) - Validate correctness of maximum attachment size application setting - Replaces "Create merge request" link with one to the "Merge Request" when one exists + - Fix CI builds badge, add a new link to builds badge, deprecate the old one v 8.4.4 - Update omniauth-saml gem to 1.4.2 From 28b11963b1613f420aecbee6718d753a6f9733a9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 9 Feb 2016 13:10:16 +0100 Subject: [PATCH 15/17] 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 0000000000..a4dd94b941 --- /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 0aef477811..ec379c53b8 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 081ff42840..507bcbc53d 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 6598843049..ae7b760fa6 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 65f5e0f766..52ef3b4484 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 From debaa813294f81d127e92bc75a3ae0751af7a316 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 10 Feb 2016 12:20:01 +0100 Subject: [PATCH 16/17] Move build badge specs to badges directory --- .../project/{builds/badge.feature => badges/build.feature} | 2 +- .../steps/project/{builds/badge.rb => badges/build.rb} | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) rename features/project/{builds/badge.feature => badges/build.feature} (96%) rename features/steps/project/{builds/badge.rb => badges/build.rb} (85%) diff --git a/features/project/builds/badge.feature b/features/project/badges/build.feature similarity index 96% rename from features/project/builds/badge.feature rename to features/project/badges/build.feature index 9eb34475e6..bdd934651e 100644 --- a/features/project/builds/badge.feature +++ b/features/project/badges/build.feature @@ -1,4 +1,4 @@ -Feature: Project Builds Badge +Feature: Project Badges Build Background: Given I sign in as a user And I own a project diff --git a/features/steps/project/builds/badge.rb b/features/steps/project/badges/build.rb similarity index 85% rename from features/steps/project/builds/badge.rb rename to features/steps/project/badges/build.rb index 52ef3b4484..10b27d61fd 100644 --- a/features/steps/project/builds/badge.rb +++ b/features/steps/project/badges/build.rb @@ -1,4 +1,4 @@ -class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps +class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps include SharedAuthentication include SharedProject include SharedBuilds @@ -20,11 +20,8 @@ class Spinach::Features::ProjectBuildsBadge < Spinach::FeatureSteps expect_badge('running') end - def svg - Nokogiri::HTML.parse(page.body) - end - def expect_badge(status) + svg = Nokogiri::HTML.parse(page.body) expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') expect(svg.at(%Q{text:contains("#{status}")})).to be_truthy end From 9e6190485b2213c9dfdd3d5b22853fc6e2263c2a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 11 Feb 2016 10:27:53 +0100 Subject: [PATCH 17/17] Parse XML instead of HTML in tests for a SVG build badge --- features/project/badges/build.feature | 8 ++++---- features/steps/project/badges/build.rb | 2 +- features/steps/shared/builds.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/features/project/badges/build.feature b/features/project/badges/build.feature index bdd934651e..9417f62d68 100644 --- a/features/project/badges/build.feature +++ b/features/project/badges/build.feature @@ -6,17 +6,17 @@ Feature: Project Badges Build And project has a recent build Scenario: I want to see a badge for successfully built project - Given recent build is successfull + Given recent build is successful When I display builds badge for a master branch Then I should see a build success badge - Scenario: I want to see a badge for project with filed builds + Scenario: I want to see a badge for project with failed builds Given recent build failed When I display builds badge for a master branch Then I should see a build failed badge Scenario: I want to see a badge for project with running builds - Given recent build is successfull - And project has an another build that is running + Given recent build is successful + And project has another build that is running When I display builds badge for a master branch Then I should see a build running badge diff --git a/features/steps/project/badges/build.rb b/features/steps/project/badges/build.rb index 10b27d61fd..cbfc35bed6 100644 --- a/features/steps/project/badges/build.rb +++ b/features/steps/project/badges/build.rb @@ -21,7 +21,7 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps end def expect_badge(status) - svg = Nokogiri::HTML.parse(page.body) + svg = Nokogiri::XML.parse(page.body) expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') expect(svg.at(%Q{text:contains("#{status}")})).to be_truthy end diff --git a/features/steps/shared/builds.rb b/features/steps/shared/builds.rb index 7e1d9bb405..fa54c93df0 100644 --- a/features/steps/shared/builds.rb +++ b/features/steps/shared/builds.rb @@ -10,7 +10,7 @@ module SharedBuilds @build = create(:ci_build, commit: @ci_commit) end - step 'recent build is successfull' do + step 'recent build is successful' do @build.update_column(:status, 'success') end @@ -18,7 +18,7 @@ module SharedBuilds @build.update_column(:status, 'failed') end - step 'project has an another build that is running' do + step 'project has another build that is running' do create(:ci_build, commit: @ci_commit, name: 'second build', status: 'running') end