Commit 0cef4a7c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '7861-cross-project-pipeline-dashboard-mvc-2' into 'master'

"Cross-Project Pipeline Dashboard MVC" backend

See merge request gitlab-org/gitlab-ee!9396
parents 39a8fe6f c9fdeaf7
...@@ -305,6 +305,7 @@ class Project < ActiveRecord::Base ...@@ -305,6 +305,7 @@ class Project < ActiveRecord::Base
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings
delegate :group_clusters_enabled?, to: :group, allow_nil: true delegate :group_clusters_enabled?, to: :group, allow_nil: true
delegate :root_ancestor, to: :namespace, allow_nil: true delegate :root_ancestor, to: :namespace, allow_nil: true
delegate :last_pipeline, to: :commit, allow_nil: true
# Validations # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
......
...@@ -5,24 +5,23 @@ class DashboardOperationsProjectEntity < Grape::Entity ...@@ -5,24 +5,23 @@ class DashboardOperationsProjectEntity < Grape::Entity
expose :project, merge: true, using: API::Entities::BasicProjectDetails expose :project, merge: true, using: API::Entities::BasicProjectDetails
expose :remove_path do |dashboard_project| expose :remove_path do |dashboard_project_object|
remove_operations_project_path(project_id: dashboard_project.project.id) remove_operations_project_path(project_id: dashboard_project_object.project.id)
end end
expose :last_deployment, if: -> (*) { last_deployment? } do |dashboard_project, options| expose :last_pipeline, if: -> (*) { last_pipeline } do |_, options|
new_request = EntityRequest.new( PipelineDetailsEntity.represent(last_pipeline, options.merge(request: new_request))
current_user: request.current_user, end
project: dashboard_project.project
)
DeploymentEntity.represent(dashboard_project.last_deployment, expose :last_deployment, if: -> (*) { last_deployment? } do |dashboard_project_object, options|
DeploymentEntity.represent(dashboard_project_object.last_deployment,
options.merge(request: new_request)) options.merge(request: new_request))
end end
expose :alert_count expose :alert_count
expose :alert_path, if: -> (*) { last_deployment? } do |dashboard_project| expose :alert_path, if: -> (*) { last_deployment? } do |dashboard_project_object|
project = dashboard_project.project project = dashboard_project_object.project
environment = dashboard_project.last_deployment.environment environment = dashboard_project_object.last_deployment.environment
metrics_project_environment_path(project, environment) metrics_project_environment_path(project, environment)
end end
...@@ -32,6 +31,17 @@ class DashboardOperationsProjectEntity < Grape::Entity ...@@ -32,6 +31,17 @@ class DashboardOperationsProjectEntity < Grape::Entity
alias_method :dashboard_project, :object alias_method :dashboard_project, :object
def new_request
EntityRequest.new(
current_user: request.current_user,
project: dashboard_project.project
)
end
def last_pipeline
dashboard_project.project.last_pipeline
end
def last_deployment? def last_deployment?
dashboard_project.last_deployment dashboard_project.last_deployment
end end
......
---
title: Add backend for cross-project pipeline dashboard MVC.
merge_request: 9396
author:
type: changed
# frozen_string_literal: true
require 'spec_helper'
describe DashboardOperationsProjectEntity do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:resource) { Dashboard::Operations::ListService::DashboardProject.new(project, nil, 0, nil) }
let(:request) { double('request', current_user: user) }
subject { described_class.new(resource, request: request).as_json }
it 'has all required fields' do
expect(subject).to include(:remove_path, :alert_count)
expect(subject.first).to include(:id)
end
it 'does not have optional fields' do
expect(subject).not_to include(:last_pipeline, :upstream_pipeline, :downstream_pipelines)
end
context 'when there is a pipeline' do
let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha) }
it 'has the last pipeline field' do
expect(subject).to include(:last_pipeline)
end
context 'when there is an upstream status' do
let(:bridge) { create(:ci_bridge, status: :pending) }
before do
create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge)
end
it 'has the triggered_by pipeline field' do
expect(subject[:last_pipeline]).to include(:triggered_by)
end
end
context 'when there is a downstream status' do
let(:build) { create(:ci_build, pipeline: pipeline) }
before do
create(:ci_sources_pipeline, source_job: build)
end
it 'has the triggered pipeline field' do
expect(subject[:last_pipeline]).to include(:triggered)
end
context 'when there are multiple downstream statuses' do
before do
create_list(:ci_sources_pipeline, 5, source_job: build)
end
it 'has the downstream pipeline field' do
expect(subject[:last_pipeline]).to include(:triggered)
expect(subject[:last_pipeline][:triggered].count).to eq(6)
end
end
end
context 'when there are both an upstream and downstream pipelines' do
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:bridge) { create(:ci_bridge, status: :pending) }
before do
create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge)
create_list(:ci_sources_pipeline, 5, source_job: build)
end
it 'has the upstream pipeline field' do
expect(subject[:last_pipeline]).to include(:triggered_by)
end
it 'has the downstream pipeline field' do
expect(subject[:last_pipeline]).to include(:triggered)
expect(subject[:last_pipeline][:triggered].count).to eq(5)
end
end
end
end
...@@ -516,6 +516,7 @@ describe Project do ...@@ -516,6 +516,7 @@ describe Project do
it { is_expected.to delegate_method(:name).to(:owner).with_prefix(true).with_arguments(allow_nil: true) } it { is_expected.to delegate_method(:name).to(:owner).with_prefix(true).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:group_clusters_enabled?).to(:group).with_arguments(allow_nil: true) } it { is_expected.to delegate_method(:group_clusters_enabled?).to(:group).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:root_ancestor).to(:namespace).with_arguments(allow_nil: true) } it { is_expected.to delegate_method(:root_ancestor).to(:namespace).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:last_pipeline).to(:commit).with_arguments(allow_nil: true) }
end end
describe '#to_reference_with_postfix' do describe '#to_reference_with_postfix' do
......
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