diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/pipeline.rb | 7 | ||||
-rw-r--r-- | app/models/ci/sources/pipeline.rb | 14 | ||||
-rw-r--r-- | app/serializers/pipeline_details_entity.rb | 3 | ||||
-rw-r--r-- | app/serializers/triggered_pipeline_entity.rb | 30 | ||||
-rw-r--r-- | app/workers/expire_pipeline_cache_worker.rb | 14 |
5 files changed, 64 insertions, 4 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 425ca9278eb..d7c0a6dbb3e 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -11,6 +11,13 @@ module Ci belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' belongs_to :pipeline_schedule, class_name: 'Ci::PipelineSchedule' + has_one :source_pipeline, class_name: Ci::Sources::Pipeline + + has_many :sourced_pipelines, class_name: Ci::Sources::Pipeline, foreign_key: :source_pipeline_id + + has_one :triggered_by_pipeline, through: :source_pipeline, source: :source_pipeline + has_many :triggered_pipelines, through: :sourced_pipelines, source: :pipeline + has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' diff --git a/app/models/ci/sources/pipeline.rb b/app/models/ci/sources/pipeline.rb new file mode 100644 index 00000000000..718a163d70f --- /dev/null +++ b/app/models/ci/sources/pipeline.rb @@ -0,0 +1,14 @@ +module Ci + module Sources + class Pipeline < ActiveRecord::Base + self.table_name = "ci_sources_pipelines" + + belongs_to :project, class_name: Project + belongs_to :pipeline, class_name: Ci::Pipeline + + belongs_to :source_project, class_name: Project, foreign_key: :source_project_id + belongs_to :source_job, class_name: Ci::Build, foreign_key: :source_job_id + belongs_to :source_pipeline, class_name: Ci::Pipeline, foreign_key: :source_pipeline_id + end + end +end diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb index d58572a5f87..577b0555c92 100644 --- a/app/serializers/pipeline_details_entity.rb +++ b/app/serializers/pipeline_details_entity.rb @@ -4,4 +4,7 @@ class PipelineDetailsEntity < PipelineEntity expose :artifacts, using: BuildArtifactEntity expose :manual_actions, using: BuildActionEntity end + + expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity + expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity end diff --git a/app/serializers/triggered_pipeline_entity.rb b/app/serializers/triggered_pipeline_entity.rb new file mode 100644 index 00000000000..23f2c7f125f --- /dev/null +++ b/app/serializers/triggered_pipeline_entity.rb @@ -0,0 +1,30 @@ +class TriggeredPipelineEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :user, using: UserEntity + expose :active?, as: :active + expose :coverage + expose :source + + expose :path do |pipeline| + namespace_project_pipeline_path( + pipeline.project.namespace, + pipeline.project, + pipeline) + end + + expose :details do + expose :detailed_status, as: :status, with: StatusEntity + end + + expose :project, using: ProjectEntity + + private + + alias_method :pipeline, :object + + def detailed_status + pipeline.detailed_status(request.current_user) + end +end diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb index d760f5b140f..0f1c66a3776 100644 --- a/app/workers/expire_pipeline_cache_worker.rb +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -10,13 +10,19 @@ class ExpirePipelineCacheWorker store = Gitlab::EtagCaching::Store.new store.touch(project_pipelines_path(project)) - store.touch(project_pipeline_path(project, pipeline)) + store.touch(project_pipeline_path(pipeline)) store.touch(commit_pipelines_path(project, pipeline.commit)) if pipeline.commit store.touch(new_merge_request_pipelines_path(project)) each_pipelines_merge_request_path(project, pipeline) do |path| store.touch(path) end + store.touch(project_pipeline_path(pipeline.triggered_by_pipeline)) if pipeline.triggered_by_pipeline + + pipeline.triggered_pipelines.each do |triggered| + store.touch(project_pipeline_path(triggered)) + end + Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) end @@ -29,10 +35,10 @@ class ExpirePipelineCacheWorker format: :json) end - def project_pipeline_path(project, pipeline) + def project_pipeline_path(pipeline) Gitlab::Routing.url_helpers.namespace_project_pipeline_path( - project.namespace, - project, + pipeline.project.namespace, + pipeline.project, pipeline, format: :json) end |