Commit da66c90b authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fix-external-ci-services' into 'master'

Allow to access statuses for external CI services

Closes #30714, #29369, and #15220

See merge request !11176
parents 0037cf63 25b99a5b
...@@ -80,10 +80,6 @@ class Projects::ApplicationController < ApplicationController ...@@ -80,10 +80,6 @@ class Projects::ApplicationController < ApplicationController
cookies.permanent[:diff_view] = params.delete(:view) if params[:view].present? cookies.permanent[:diff_view] = params.delete(:view) if params[:view].present?
end end
def builds_enabled
return render_404 unless @project.feature_available?(:builds, current_user)
end
def require_pages_enabled! def require_pages_enabled!
not_found unless Gitlab.config.pages.enabled not_found unless Gitlab.config.pages.enabled
end end
......
...@@ -5,7 +5,6 @@ class Projects::GraphsController < Projects::ApplicationController ...@@ -5,7 +5,6 @@ class Projects::GraphsController < Projects::ApplicationController
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :assign_ref_vars before_action :assign_ref_vars
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :builds_enabled, only: :ci
def show def show
respond_to do |format| respond_to do |format|
......
...@@ -4,7 +4,6 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -4,7 +4,6 @@ class Projects::PipelinesController < Projects::ApplicationController
before_action :authorize_read_pipeline! before_action :authorize_read_pipeline!
before_action :authorize_create_pipeline!, only: [:new, :create] before_action :authorize_create_pipeline!, only: [:new, :create]
before_action :authorize_update_pipeline!, only: [:retry, :cancel] before_action :authorize_update_pipeline!, only: [:retry, :cancel]
before_action :builds_enabled, only: :charts
wrap_parameters Ci::Pipeline wrap_parameters Ci::Pipeline
......
...@@ -218,6 +218,10 @@ module ProjectsHelper ...@@ -218,6 +218,10 @@ module ProjectsHelper
nav_tabs << :container_registry nav_tabs << :container_registry
end end
if project.builds_enabled? && can?(current_user, :read_pipeline, project)
nav_tabs << :pipelines
end
tab_ability_map.each do |tab, ability| tab_ability_map.each do |tab, ability|
if can?(current_user, ability, project) if can?(current_user, ability, project)
nav_tabs << tab nav_tabs << tab
...@@ -231,7 +235,6 @@ module ProjectsHelper ...@@ -231,7 +235,6 @@ module ProjectsHelper
{ {
environments: :read_environment, environments: :read_environment,
milestones: :read_milestone, milestones: :read_milestone,
pipelines: :read_pipeline,
snippets: :read_project_snippet, snippets: :read_project_snippet,
settings: :admin_project, settings: :admin_project,
builds: :read_build, builds: :read_build,
......
...@@ -11,6 +11,7 @@ class GenericCommitStatus < CommitStatus ...@@ -11,6 +11,7 @@ class GenericCommitStatus < CommitStatus
def set_default_values def set_default_values
self.context ||= 'default' self.context ||= 'default'
self.stage ||= 'external' self.stage ||= 'external'
self.stage_idx ||= 1000000
end end
def tags def tags
......
...@@ -203,7 +203,7 @@ class ProjectPolicy < BasePolicy ...@@ -203,7 +203,7 @@ class ProjectPolicy < BasePolicy
unless project.feature_available?(:builds, user) && repository_enabled unless project.feature_available?(:builds, user) && repository_enabled
cannot!(*named_abilities(:build)) cannot!(*named_abilities(:build))
cannot!(*named_abilities(:pipeline)) cannot!(*named_abilities(:pipeline) - [:read_pipeline])
cannot!(*named_abilities(:pipeline_schedule)) cannot!(*named_abilities(:pipeline_schedule))
cannot!(*named_abilities(:environment)) cannot!(*named_abilities(:environment))
cannot!(*named_abilities(:deployment)) cannot!(*named_abilities(:deployment))
......
class BuildDetailsEntity < BuildEntity class BuildDetailsEntity < JobEntity
expose :coverage, :erased_at, :duration expose :coverage, :erased_at, :duration
expose :tag_list, as: :tags expose :tag_list, as: :tags
expose :user, using: UserEntity expose :user, using: UserEntity
......
class BuildSerializer < BaseSerializer class BuildSerializer < BaseSerializer
entity BuildEntity entity JobEntity
def represent_status(resource) def represent_status(resource)
data = represent(resource, { only: [:status] }) data = represent(resource, { only: [:status] })
......
...@@ -24,6 +24,6 @@ class DeploymentEntity < Grape::Entity ...@@ -24,6 +24,6 @@ class DeploymentEntity < Grape::Entity
expose :user, using: UserEntity expose :user, using: UserEntity
expose :commit, using: CommitEntity expose :commit, using: CommitEntity
expose :deployable, using: BuildEntity expose :deployable, using: JobEntity
expose :manual_actions, using: BuildEntity expose :manual_actions, using: JobEntity
end end
class BuildEntity < Grape::Entity class JobEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :id expose :id
expose :name expose :name
expose :build_path do |build| expose :build_path do |build|
path_to(:namespace_project_job, build) build.target_url || path_to(:namespace_project_job, build)
end end
expose :retry_path, if: -> (*) { retryable? } do |build| expose :retry_path, if: -> (*) { retryable? } do |build|
......
...@@ -4,7 +4,7 @@ class JobGroupEntity < Grape::Entity ...@@ -4,7 +4,7 @@ class JobGroupEntity < Grape::Entity
expose :name expose :name
expose :size expose :size
expose :detailed_status, as: :status, with: StatusEntity expose :detailed_status, as: :status, with: StatusEntity
expose :jobs, with: BuildEntity expose :jobs, with: JobEntity
private private
......
...@@ -101,12 +101,12 @@ class GitPushService < BaseService ...@@ -101,12 +101,12 @@ class GitPushService < BaseService
UpdateMergeRequestsWorker UpdateMergeRequestsWorker
.perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref]) .perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref])
SystemHookPushWorker.perform_async(build_push_data.dup, :push_hooks)
EventCreateService.new.push(@project, current_user, build_push_data) EventCreateService.new.push(@project, current_user, build_push_data)
Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute(:push)
SystemHookPushWorker.perform_async(build_push_data.dup, :push_hooks)
@project.execute_hooks(build_push_data.dup, :push_hooks) @project.execute_hooks(build_push_data.dup, :push_hooks)
@project.execute_services(build_push_data.dup, :push_hooks) @project.execute_services(build_push_data.dup, :push_hooks)
Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute(:push)
if push_remove_branch? if push_remove_branch?
AfterBranchDeleteService AfterBranchDeleteService
......
...@@ -8,10 +8,12 @@ class GitTagPushService < BaseService ...@@ -8,10 +8,12 @@ class GitTagPushService < BaseService
@push_data = build_push_data @push_data = build_push_data
EventCreateService.new.push(project, current_user, @push_data) EventCreateService.new.push(project, current_user, @push_data)
Ci::CreatePipelineService.new(project, current_user, @push_data).execute(:push)
SystemHooksService.new.execute_hooks(build_system_push_data.dup, :tag_push_hooks) SystemHooksService.new.execute_hooks(build_system_push_data.dup, :tag_push_hooks)
project.execute_hooks(@push_data.dup, :tag_push_hooks) project.execute_hooks(@push_data.dup, :tag_push_hooks)
project.execute_services(@push_data.dup, :tag_push_hooks) project.execute_services(@push_data.dup, :tag_push_hooks)
Ci::CreatePipelineService.new(project, current_user, @push_data).execute(:push)
ProjectCacheWorker.perform_async(project.id, [], [:commit_count, :repository_size]) ProjectCacheWorker.perform_async(project.id, [], [:commit_count, :repository_size])
true true
......
---
title: Fix support for external CI services
merge_request: 11176
author:
...@@ -3,6 +3,10 @@ module Gitlab ...@@ -3,6 +3,10 @@ module Gitlab
module Status module Status
module External module External
module Common module Common
def label
subject.description
end
def has_details? def has_details?
subject.target_url.present? && subject.target_url.present? &&
can?(user, :read_commit_status, subject) can?(user, :read_commit_status, subject)
......
...@@ -5,9 +5,12 @@ describe Projects::PipelinesController do ...@@ -5,9 +5,12 @@ describe Projects::PipelinesController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:empty_project, :public) } let(:project) { create(:empty_project, :public) }
let(:feature) { ProjectFeature::DISABLED }
before do before do
project.add_developer(user) project.add_developer(user)
project.project_feature.update(
builds_access_level: feature)
sign_in(user) sign_in(user)
end end
...@@ -153,16 +156,26 @@ describe Projects::PipelinesController do ...@@ -153,16 +156,26 @@ describe Projects::PipelinesController do
format: :json format: :json
end end
it 'retries a pipeline without returning any content' do context 'when builds are enabled' do
expect(response).to have_http_status(:no_content) let(:feature) { ProjectFeature::ENABLED }
expect(build.reload).to be_retried
it 'retries a pipeline without returning any content' do
expect(response).to have_http_status(:no_content)
expect(build.reload).to be_retried
end
end
context 'when builds are disabled' do
it 'fails to retry pipeline' do
expect(response).to have_http_status(:not_found)
end
end end
end end
describe 'POST cancel.json' do describe 'POST cancel.json' do
let!(:pipeline) { create(:ci_pipeline, project: project) } let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, :running, pipeline: pipeline) } let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
before do before do
post :cancel, namespace_id: project.namespace, post :cancel, namespace_id: project.namespace,
project_id: project, project_id: project,
...@@ -170,9 +183,19 @@ describe Projects::PipelinesController do ...@@ -170,9 +183,19 @@ describe Projects::PipelinesController do
format: :json format: :json
end end
it 'cancels a pipeline without returning any content' do context 'when builds are enabled' do
expect(response).to have_http_status(:no_content) let(:feature) { ProjectFeature::ENABLED }
expect(pipeline.reload).to be_canceled
it 'cancels a pipeline without returning any content' do
expect(response).to have_http_status(:no_content)
expect(pipeline.reload).to be_canceled
end
end
context 'when builds are disabled' do
it 'fails to retry pipeline' do
expect(response).to have_http_status(:not_found)
end
end end
end end
end end
...@@ -68,9 +68,12 @@ describe 'Edit Project Settings', feature: true do ...@@ -68,9 +68,12 @@ describe 'Edit Project Settings', feature: true do
end end
describe 'project features visibility pages' do describe 'project features visibility pages' do
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:job) { create(:ci_build, pipeline: pipeline) }
let(:tools) do let(:tools) do
{ {
builds: namespace_project_pipelines_path(project.namespace, project), builds: namespace_project_job_path(project.namespace, project, job),
issues: namespace_project_issues_path(project.namespace, project), issues: namespace_project_issues_path(project.namespace, project),
wiki: namespace_project_wiki_path(project.namespace, project, :home), wiki: namespace_project_wiki_path(project.namespace, project, :home),
snippets: namespace_project_snippets_path(project.namespace, project), snippets: namespace_project_snippets_path(project.namespace, project),
......
...@@ -300,4 +300,37 @@ describe ProjectsHelper do ...@@ -300,4 +300,37 @@ describe ProjectsHelper do
expect(helper.send(:visibility_select_options, project, Gitlab::VisibilityLevel::PRIVATE)).to include('Private') expect(helper.send(:visibility_select_options, project, Gitlab::VisibilityLevel::PRIVATE)).to include('Private')
end end
end end
describe '#get_project_nav_tabs' do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
before do
allow(helper).to receive(:can?) { true }
end
subject do
helper.send(:get_project_nav_tabs, project, user)
end
context 'when builds feature is enabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(true)
end
it "does include pipelines tab" do
is_expected.to include(:pipelines)
end
end
context 'when builds feature is disabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(false)
end
it "do not include pipelines tab" do
is_expected.not_to include(:pipelines)
end
end
end
end end
...@@ -4,9 +4,10 @@ describe Gitlab::Ci::Status::External::Common do ...@@ -4,9 +4,10 @@ describe Gitlab::Ci::Status::External::Common do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { external_status.project } let(:project) { external_status.project }
let(:external_target_url) { 'http://example.gitlab.com/status' } let(:external_target_url) { 'http://example.gitlab.com/status' }
let(:external_description) { 'my description' }
let(:external_status) do let(:external_status) do
create(:generic_commit_status, target_url: external_target_url) create(:generic_commit_status, target_url: external_target_url, description: external_description)
end end
subject do subject do
...@@ -15,6 +16,12 @@ describe Gitlab::Ci::Status::External::Common do ...@@ -15,6 +16,12 @@ describe Gitlab::Ci::Status::External::Common do
.extend(described_class) .extend(described_class)
end end
describe '#label' do
it 'returns description' do
expect(subject.label).to eq external_description
end
end
describe '#has_action?' do describe '#has_action?' do
it { is_expected.not_to have_action } it { is_expected.not_to have_action }
end end
......
...@@ -139,6 +139,18 @@ describe ProjectPolicy, models: true do ...@@ -139,6 +139,18 @@ describe ProjectPolicy, models: true do
is_expected.not_to include(:read_build, :read_pipeline) is_expected.not_to include(:read_build, :read_pipeline)
end end
end end
context 'when builds are disabled' do
before do
project.project_feature.update(
builds_access_level: ProjectFeature::DISABLED)
end
it do
is_expected.not_to include(:read_build)
is_expected.to include(:read_pipeline)
end
end
end end
context 'reporter' do context 'reporter' do
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe BuildDetailsEntity do describe BuildDetailsEntity do
set(:user) { create(:admin) } set(:user) { create(:admin) }
it 'inherits from BuildEntity' do it 'inherits from JobEntity' do
expect(described_class).to be < BuildEntity expect(described_class).to be < JobEntity
end end
describe '#as_json' do describe '#as_json' do
......
require 'spec_helper' require 'spec_helper'
describe BuildEntity do describe JobEntity do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:build) { create(:ci_build) } let(:job) { create(:ci_build) }
let(:project) { build.project } let(:project) { job.project }
let(:request) { double('request') } let(:request) { double('request') }
before do before do
...@@ -12,12 +12,12 @@ describe BuildEntity do ...@@ -12,12 +12,12 @@ describe BuildEntity do
end end
let(:entity) do let(:entity) do
described_class.new(build, request: request) described_class.new(job, request: request)
end end
subject { entity.as_json } subject { entity.as_json }
it 'contains paths to build page action' do it 'contains paths to job page action' do
expect(subject).to include(:build_path) expect(subject).to include(:build_path)
end end
...@@ -27,7 +27,7 @@ describe BuildEntity do ...@@ -27,7 +27,7 @@ describe BuildEntity do
end end
it 'contains whether it is playable' do it 'contains whether it is playable' do
expect(subject[:playable]).to eq build.playable? expect(subject[:playable]).to eq job.playable?
end end
it 'contains timestamps' do it 'contains timestamps' do
...@@ -39,9 +39,9 @@ describe BuildEntity do ...@@ -39,9 +39,9 @@ describe BuildEntity do
expect(subject[:status]).to include :icon, :favicon, :text, :label expect(subject[:status]).to include :icon, :favicon, :text, :label
end end
context 'when build is retryable' do context 'when job is retryable' do
before do before do
build.update(status: :failed) job.update(status: :failed)
end end
it 'contains cancel path' do it 'contains cancel path' do
...@@ -49,9 +49,9 @@ describe BuildEntity do ...@@ -49,9 +49,9 @@ describe BuildEntity do
end end
end end
context 'when build is cancelable' do context 'when job is cancelable' do
before do before do
build.update(status: :running) job.update(status: :running)
end end
it 'contains cancel path' do it 'contains cancel path' do
...@@ -59,7 +59,7 @@ describe BuildEntity do ...@@ -59,7 +59,7 @@ describe BuildEntity do
end end
end end
context 'when build is a regular build' do context 'when job is a regular job' do
it 'does not contain path to play action' do it 'does not contain path to play action' do
expect(subject).not_to include(:play_path) expect(subject).not_to include(:play_path)
end end
...@@ -69,8 +69,8 @@ describe BuildEntity do ...@@ -69,8 +69,8 @@ describe BuildEntity do
end end
end end
context 'when build is a manual action' do context 'when job is a manual action' do
let(:build) { create(:ci_build, :manual) } let(:job) { create(:ci_build, :manual) }
context 'when user is allowed to trigger action' do context 'when user is allowed to trigger action' do
before do before do
...@@ -99,4 +99,25 @@ describe BuildEntity do ...@@ -99,4 +99,25 @@ describe BuildEntity do
end end
end end
end end
context 'when job is generic commit status' do
let(:job) { create(:generic_commit_status, target_url: 'http://google.com') }
it 'contains paths to target action' do
expect(subject).to include(:build_path)
end
it 'does not contain paths to other action paths' do
expect(subject).not_to include(:retry_path, :cancel_path, :play_path)
end
it 'contains timestamps' do
expect(subject).to include(:created_at, :updated_at)
end
it 'contains details' do
expect(subject).to include :status
expect(subject[:status]).to include :icon, :favicon, :text, :label
end
end
end end
...@@ -91,6 +91,20 @@ describe PipelineDetailsEntity do ...@@ -91,6 +91,20 @@ describe PipelineDetailsEntity do
end end
end end
context 'when pipeline has commit statuses' do
let(:pipeline) { create(:ci_empty_pipeline) }
before do
create(:generic_commit_status, pipeline: pipeline)
end
it 'contains stages' do
expect(subject).to include(:details)
expect(subject[:details]).to include(:stages)
expect(subject[:details][:stages].first).to include(name: 'external')
end
end
context 'when pipeline has YAML errors' do context 'when pipeline has YAML errors' do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, config: { rspec: { invalid: :value } }) create(:ci_pipeline, config: { rspec: { invalid: :value } })
......
...@@ -54,6 +54,17 @@ describe StageEntity do ...@@ -54,6 +54,17 @@ describe StageEntity do
it 'exposes the group key' do it 'exposes the group key' do
expect(subject).to include :groups expect(subject).to include :groups
end end
context 'and contains commit status' do
before do
create(:generic_commit_status, pipeline: pipeline, stage: 'test')
end
it 'contains commit status' do
groups = subject[:groups].map { |group| group[:name] }
expect(groups).to include('generic')
end
end
end end
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