Commit 2086483b authored by Z.J. van de Weg's avatar Z.J. van de Weg

Rename build to pipeline for status badges

First commit in probably 2, for resolve gitlab-org/gitlab-ce#15582. This
commit is renaming files and classes from build to pipeline. Also
wording is editted to pipeline. Given `pipeline` had more characters
than `build`, I've made the field a bit wider. The width now matchers
the one for the coverage badge, so they look nice when in a table
format, or in a list.

As soon as this commit is merged to master, and released, the build.svg
is deprecated, meaning that all users which already placed a badge
should update it. However, to make sure it keeps working tests are added
for this case.
parent eaceee0f
...@@ -3,11 +3,11 @@ class Projects::BadgesController < Projects::ApplicationController ...@@ -3,11 +3,11 @@ class Projects::BadgesController < Projects::ApplicationController
before_action :authorize_admin_project!, only: [:index] before_action :authorize_admin_project!, only: [:index]
before_action :no_cache_headers, except: [:index] before_action :no_cache_headers, except: [:index]
def build def pipeline
build_status = Gitlab::Badge::Build::Status pipeline_status = Gitlab::Badge::Pipeline::Status
.new(project, params[:ref]) .new(project, params[:ref])
render_badge build_status render_badge pipeline_status
end end
def coverage def coverage
......
...@@ -35,7 +35,7 @@ module Projects ...@@ -35,7 +35,7 @@ module Projects
def define_badges_variables def define_badges_variables
@ref = params[:ref] || @project.default_branch || 'master' @ref = params[:ref] || @project.default_branch || 'master'
@badges = [Gitlab::Badge::Build::Status, @badges = [Gitlab::Badge::Pipeline::Status,
Gitlab::Badge::Coverage::Report] Gitlab::Badge::Coverage::Report]
@badges.map! do |badge| @badges.map! do |badge|
......
...@@ -379,7 +379,9 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -379,7 +379,9 @@ constraints(ProjectUrlConstrainer.new) do
collection do collection do
scope '*ref', constraints: { ref: Gitlab::PathRegex.git_reference_regex } do scope '*ref', constraints: { ref: Gitlab::PathRegex.git_reference_regex } do
constraints format: /svg/ do constraints format: /svg/ do
get :build # Keep around until 10.0, see gitlab-org/gitlab-ce#35307
get :build, to: "badges#pipeline"
get :pipeline
get :coverage get :coverage
end end
end end
......
...@@ -5,7 +5,7 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps ...@@ -5,7 +5,7 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps
include RepoHelpers include RepoHelpers
step 'I display builds badge for a master branch' do step 'I display builds badge for a master branch' do
visit build_project_badges_path(@project, ref: :master, format: :svg) visit pipeline_project_badges_path(@project, ref: :master, format: :svg)
end end
step 'I should see a build success badge' do step 'I should see a build success badge' do
......
module Gitlab module Gitlab
module Badge module Badge
module Build module Pipeline
## ##
# Class that describes build badge metadata # Class that describes pipeline badge metadata
# #
class Metadata < Badge::Metadata class Metadata < Badge::Metadata
def initialize(badge) def initialize(badge)
...@@ -11,11 +11,11 @@ module Gitlab ...@@ -11,11 +11,11 @@ module Gitlab
end end
def title def title
'build status' 'pipeline status'
end end
def image_url def image_url
build_project_badges_url(@project, @ref, format: :svg) pipeline_project_badges_url(@project, @ref, format: :svg)
end end
def link_url def link_url
......
module Gitlab module Gitlab
module Badge module Badge
module Build module Pipeline
## ##
# Build status badge # Pipeline status badge
# #
class Status < Badge::Base class Status < Badge::Base
attr_reader :project, :ref attr_reader :project, :ref
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def entity def entity
'build' 'pipeline'
end end
def status def status
...@@ -25,11 +25,11 @@ module Gitlab ...@@ -25,11 +25,11 @@ module Gitlab
end end
def metadata def metadata
@metadata ||= Build::Metadata.new(self) @metadata ||= Pipeline::Metadata.new(self)
end end
def template def template
@template ||= Build::Template.new(self) @template ||= Pipeline::Template.new(self)
end end
end end
end end
......
module Gitlab module Gitlab
module Badge module Badge
module Build module Pipeline
## ##
# Class that represents a build badge template. # Class that represents a pipeline badge template.
# #
# Template object will be passed to badge.svg.erb template. # Template object will be passed to badge.svg.erb template.
# #
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
end end
def key_width def key_width
38 62
end end
def value_width def value_width
......
require 'spec_helper'
describe Projects::BadgesController do
let(:project) { pipeline.project }
let!(:pipeline) { create(:ci_empty_pipeline) }
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
end
it 'requests the pipeline badge successfully' do
get_badge(:pipeline)
expect(response).to have_http_status(:ok)
end
it 'requests the coverage badge successfully' do
get_badge(:coverage)
expect(response).to have_http_status(:ok)
end
def get_badge(badge)
get badge, namespace_id: project.namespace.to_param, project_id: project, ref: pipeline.ref, format: :svg
end
end
...@@ -10,16 +10,16 @@ feature 'list of badges' do ...@@ -10,16 +10,16 @@ feature 'list of badges' do
end end
scenario 'user wants to see build status badge' do scenario 'user wants to see build status badge' do
page.within('.build-status') do page.within('.pipeline-status') do
expect(page).to have_content 'build status' expect(page).to have_content 'pipeline status'
expect(page).to have_content 'Markdown' expect(page).to have_content 'Markdown'
expect(page).to have_content 'HTML' expect(page).to have_content 'HTML'
expect(page).to have_content 'AsciiDoc' expect(page).to have_content 'AsciiDoc'
expect(page).to have_css('.highlight', count: 3) expect(page).to have_css('.highlight', count: 3)
expect(page).to have_xpath("//img[@alt='build status']") expect(page).to have_xpath("//img[@alt='pipeline status']")
page.within('.highlight', match: :first) do page.within('.highlight', match: :first) do
expect(page).to have_content 'badges/master/build.svg' expect(page).to have_content 'badges/master/pipeline.svg'
end end
end end
end end
...@@ -40,14 +40,14 @@ feature 'list of badges' do ...@@ -40,14 +40,14 @@ feature 'list of badges' do
end end
scenario 'user changes current ref of build status badge', js: true do scenario 'user changes current ref of build status badge', js: true do
page.within('.build-status') do page.within('.pipeline-status') do
first('.js-project-refs-dropdown').click first('.js-project-refs-dropdown').click
page.within '.project-refs-form' do page.within '.project-refs-form' do
click_link 'improve/awesome' click_link 'improve/awesome'
end end
expect(page).to have_content 'badges/improve/awesome/build.svg' expect(page).to have_content 'badges/improve/awesome/pipeline.svg'
end end
end end
end end
require 'spec_helper' require 'spec_helper'
require 'lib/gitlab/badge/shared/metadata' require 'lib/gitlab/badge/shared/metadata'
describe Gitlab::Badge::Build::Metadata do describe Gitlab::Badge::Pipeline::Metadata do
let(:badge) { double(project: create(:empty_project), ref: 'feature') } let(:badge) { double(project: create(:empty_project), ref: 'feature') }
let(:metadata) { described_class.new(badge) } let(:metadata) { described_class.new(badge) }
...@@ -9,13 +9,13 @@ describe Gitlab::Badge::Build::Metadata do ...@@ -9,13 +9,13 @@ describe Gitlab::Badge::Build::Metadata do
describe '#title' do describe '#title' do
it 'returns build status title' do it 'returns build status title' do
expect(metadata.title).to eq 'build status' expect(metadata.title).to eq 'pipeline status'
end end
end end
describe '#image_url' do describe '#image_url' do
it 'returns valid url' do it 'returns valid url' do
expect(metadata.image_url).to include 'badges/feature/build.svg' expect(metadata.image_url).to include 'badges/feature/pipeline.svg'
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Build::Status do describe Gitlab::Badge::Pipeline::Status do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:sha) { project.commit.sha } let(:sha) { project.commit.sha }
let(:branch) { 'master' } let(:branch) { 'master' }
let(:badge) { described_class.new(project, branch) } let(:badge) { described_class.new(project, branch) }
describe '#entity' do describe '#entity' do
it 'always says build' do it 'always says pipeline' do
expect(badge.entity).to eq 'build' expect(badge.entity).to eq 'pipeline'
end end
end end
describe '#template' do describe '#template' do
it 'returns badge template' do it 'returns badge template' do
expect(badge.template.key_text).to eq 'build' expect(badge.template.key_text).to eq 'pipeline'
end end
end end
describe '#metadata' do describe '#metadata' do
it 'returns badge metadata' do it 'returns badge metadata' do
expect(badge.metadata.image_url) expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg'
.to include 'badges/master/build.svg'
end end
end end
context 'build exists' do context 'pipeline exists' do
let!(:build) { create_build(project, sha, branch) } let!(:pipeline) { create_pipeline(project, sha, branch) }
context 'build success' do context 'pipeline success' do
before do before do
build.success! pipeline.success!
end end
describe '#status' do describe '#status' do
...@@ -40,9 +39,9 @@ describe Gitlab::Badge::Build::Status do ...@@ -40,9 +39,9 @@ describe Gitlab::Badge::Build::Status do
end end
end end
context 'build failed' do context 'pipeline failed' do
before do before do
build.drop! pipeline.drop!
end end
describe '#status' do describe '#status' do
...@@ -54,10 +53,10 @@ describe Gitlab::Badge::Build::Status do ...@@ -54,10 +53,10 @@ describe Gitlab::Badge::Build::Status do
context 'when outdated pipeline for given ref exists' do context 'when outdated pipeline for given ref exists' do
before do before do
build.success! pipeline.success!
old_build = create_build(project, '11eeffdd', branch) old_pipeline = create_pipeline(project, '11eeffdd', branch)
old_build.drop! old_pipeline.drop!
end end
it 'does not take outdated pipeline into account' do it 'does not take outdated pipeline into account' do
...@@ -67,10 +66,10 @@ describe Gitlab::Badge::Build::Status do ...@@ -67,10 +66,10 @@ describe Gitlab::Badge::Build::Status do
context 'when multiple pipelines exist for given sha' do context 'when multiple pipelines exist for given sha' do
before do before do
build.drop! pipeline.drop!
new_build = create_build(project, sha, branch) new_pipeline = create_pipeline(project, sha, branch)
new_build.success! new_pipeline.success!
end end
it 'does not take outdated pipeline into account' do it 'does not take outdated pipeline into account' do
...@@ -87,7 +86,7 @@ describe Gitlab::Badge::Build::Status do ...@@ -87,7 +86,7 @@ describe Gitlab::Badge::Build::Status do
end end
end end
def create_build(project, sha, branch) def create_pipeline(project, sha, branch)
pipeline = create(:ci_empty_pipeline, pipeline = create(:ci_empty_pipeline,
project: project, project: project,
sha: sha, sha: sha,
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Build::Template do describe Gitlab::Badge::Pipeline::Template do
let(:badge) { double(entity: 'build', status: 'success') } let(:badge) { double(entity: 'pipeline', status: 'success') }
let(:template) { described_class.new(badge) } let(:template) { described_class.new(badge) }
describe '#key_text' do describe '#key_text' do
it 'is always says build' do it 'is always says pipeline' do
expect(template.key_text).to eq 'build' expect(template.key_text).to eq 'pipeline'
end end
end end
...@@ -18,11 +18,11 @@ describe Gitlab::Badge::Build::Template do ...@@ -18,11 +18,11 @@ describe Gitlab::Badge::Build::Template do
describe 'widths and text anchors' do describe 'widths and text anchors' do
it 'has fixed width and text anchors' do it 'has fixed width and text anchors' do
expect(template.width).to eq 92 expect(template.width).to eq 116
expect(template.key_width).to eq 38 expect(template.key_width).to eq 62
expect(template.value_width).to eq 54 expect(template.value_width).to eq 54
expect(template.key_text_anchor).to eq 19 expect(template.key_text_anchor).to eq 31
expect(template.value_text_anchor).to eq 65 expect(template.value_text_anchor).to eq 89
end end
end end
......
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