diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-06 16:03:32 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-06 16:03:32 +0300 |
commit | 81a0cc251bb5dc6e66b03b8bb224f2779e15a851 (patch) | |
tree | ee8c5a968ef23c07e7dcc0271c999854061766c6 /app | |
parent | dbd245c8bdd753b0ebe20bea9aba2bb112c3e281 (diff) | |
parent | 50776d2d298c3b6c98e2531f116ca43ba10dcda4 (diff) |
Merge branch 'expose-merge-request-entity-for-pipelines' into 'master'
Expose merge request entity for pipelines
See merge request gitlab-org/gitlab-ce!25679
Diffstat (limited to 'app')
-rw-r--r-- | app/presenters/merge_request_presenter.rb | 6 | ||||
-rw-r--r-- | app/serializers/merge_request_for_pipeline_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/pipeline_entity.rb | 10 | ||||
-rw-r--r-- | app/serializers/pipeline_serializer.rb | 1 |
4 files changed, 34 insertions, 0 deletions
diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb index c59e73f824c..af164858408 100644 --- a/app/presenters/merge_request_presenter.rb +++ b/app/presenters/merge_request_presenter.rb @@ -98,6 +98,12 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end end + def target_branch_path + if target_branch_exists? + project_branch_path(project, target_branch) + end + end + def source_branch_path if source_branch_exists? project_branch_path(source_project, source_branch) diff --git a/app/serializers/merge_request_for_pipeline_entity.rb b/app/serializers/merge_request_for_pipeline_entity.rb new file mode 100644 index 00000000000..7779ddfd65a --- /dev/null +++ b/app/serializers/merge_request_for_pipeline_entity.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class MergeRequestForPipelineEntity < Grape::Entity + include RequestAwareEntity + + expose :iid + + expose :path do |merge_request| + project_merge_request_path(merge_request.project, merge_request) + end + + expose :title + expose :source_branch + expose :source_branch_path + expose :target_branch + expose :target_branch_path +end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index c2990cb5159..5ac1e590d39 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -28,6 +28,7 @@ class PipelineEntity < Grape::Entity expose :can_retry?, as: :retryable expose :can_cancel?, as: :cancelable expose :failure_reason?, as: :failure_reason + expose :detached_merge_request_pipeline?, as: :detached end expose :details do @@ -36,6 +37,10 @@ class PipelineEntity < Grape::Entity expose :finished_at end + expose :merge_request, if: -> (*) { has_presentable_merge_request? }, with: MergeRequestForPipelineEntity do |pipeline| + pipeline.merge_request.present(current_user: request.current_user) + end + expose :ref do expose :name do |pipeline| pipeline.ref @@ -81,6 +86,11 @@ class PipelineEntity < Grape::Entity pipeline.cancelable? end + def has_presentable_merge_request? + pipeline.triggered_by_merge_request? && + can?(request.current_user, :read_merge_request, pipeline.merge_request) + end + def detailed_status pipeline.detailed_status(request.current_user) end diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index 7451433a841..dbbeca9431d 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -15,6 +15,7 @@ class PipelineSerializer < BaseSerializer :manual_actions, :scheduled_actions, :artifacts, + :merge_request, { pending_builds: :project, project: [:route, { namespace: :route }], |