Commit 479ac8aa authored by Igor Drozdov's avatar Igor Drozdov

Move merge-request merge_pipeline to cached_widget

Since we already have expiration mechanism for pipelines
What about moving them into cached_widget.json
parent 7b72698a
......@@ -50,6 +50,14 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity
MergeRequests::PipelineEntity.represent(merge_request.actual_head_pipeline, options)
end
expose :merge_pipeline, if: ->(mr, _) {
Feature.enabled?(:merge_request_cached_merge_pipeline_serializer, mr.project, default_enabled: :yaml) &&
mr.merged? &&
can?(request.current_user, :read_pipeline, mr.target_project)
} do |merge_request, options|
MergeRequests::PipelineEntity.represent(merge_request.merge_pipeline, options)
end
# Paths
#
expose :target_branch_commits_path do |merge_request|
......
......@@ -19,7 +19,11 @@ class MergeRequestPollWidgetEntity < Grape::Entity
# User entities
expose :merge_user, using: UserEntity
expose :merge_pipeline, if: ->(mr, _) { mr.merged? && can?(request.current_user, :read_pipeline, mr.target_project)} do |merge_request, options|
expose :merge_pipeline, if: ->(mr, _) {
Feature.disabled?(:merge_request_cached_merge_pipeline_serializer, mr.project, default_enabled: :yaml) &&
mr.merged? &&
can?(request.current_user, :read_pipeline, mr.target_project)
} do |merge_request, options|
MergeRequests::PipelineEntity.represent(merge_request.merge_pipeline, options)
end
......
---
name: merge_request_cached_merge_pipeline_serializer
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57827
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/326317
milestone: '13.11'
type: development
group: group::source code
default_enabled: false
......@@ -268,4 +268,49 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do
end
end
end
describe 'merge_pipeline' do
it 'returns nil' do
expect(subject[:merge_pipeline]).to be_nil
end
context 'when is merged' do
let(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) }
let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) }
before do
project.add_maintainer(user)
end
it 'returns merge_pipeline' do
pipeline.reload
pipeline_payload =
MergeRequests::PipelineEntity
.represent(pipeline, request: request)
.as_json
expect(subject[:merge_pipeline]).to eq(pipeline_payload)
end
context 'when user cannot read pipelines on target project' do
before do
project.add_guest(user)
end
it 'returns nil' do
expect(subject[:merge_pipeline]).to be_nil
end
end
context 'when merge_request_cached_merge_pipeline_serializer is disabled' do
before do
stub_feature_flags(merge_request_cached_merge_pipeline_serializer: false)
end
it 'returns nil' do
expect(subject[:merge_pipeline]).to be_nil
end
end
end
end
end
......@@ -6,9 +6,9 @@ RSpec.describe MergeRequestPollWidgetEntity do
include ProjectForksHelper
using RSpec::Parameterized::TableSyntax
let(:project) { create :project, :repository }
let(:resource) { create(:merge_request, source_project: project, target_project: project) }
let(:user) { create(:user) }
let_it_be(:project) { create :project, :repository }
let_it_be(:resource) { create(:merge_request, source_project: project, target_project: project) }
let_it_be(:user) { create(:user) }
let(:request) { double('request', current_user: user, project: project) }
......@@ -22,20 +22,33 @@ RSpec.describe MergeRequestPollWidgetEntity do
end
describe 'merge_pipeline' do
before do
stub_feature_flags(merge_request_cached_merge_pipeline_serializer: false)
end
it 'returns nil' do
expect(subject[:merge_pipeline]).to be_nil
end
context 'when is merged' do
let(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) }
let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) }
let_it_be(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) }
let_it_be(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) }
before do
project.add_maintainer(user)
end
context 'when user cannot read pipelines on target project' do
before do
project.team.truncate
end
it 'returns nil' do
expect(subject[:merge_pipeline]).to be_nil
end
end
it 'returns merge_pipeline' do
pipeline.reload
pipeline_payload =
MergeRequests::PipelineEntity
.represent(pipeline, request: request)
......@@ -44,9 +57,9 @@ RSpec.describe MergeRequestPollWidgetEntity do
expect(subject[:merge_pipeline]).to eq(pipeline_payload)
end
context 'when user cannot read pipelines on target project' do
context 'when merge_request_cached_merge_pipeline_serializer is enabled' do
before do
project.add_guest(user)
stub_feature_flags(merge_request_cached_merge_pipeline_serializer: true)
end
it 'returns nil' 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