Commit b4dbe6a7 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'nicolasdular/code-owner-progress-action' into 'master'

Record onboarding action for code owners

See merge request gitlab-org/gitlab!51925
parents 775b9b19 81e84425
......@@ -23,6 +23,7 @@ module EE
super
sync_code_owner_approval_rules if project.feature_available?(:code_owners)
track_onboarding_progress
protected_branch
end
......@@ -58,6 +59,12 @@ module EE
.preload_source_project
.select(&:source_project)
end
def track_onboarding_progress
return unless protected_branch.code_owner_approval_required
OnboardingProgressService.new(project.namespace).execute(action: :code_owners_enabled)
end
end
end
end
......@@ -33,7 +33,7 @@ RSpec.describe ProtectedBranches::CreateService do
params[:code_owner_approval_required] = true
end
it "ignores incoming params and sets code_owner_approval_required to false" do
it "ignores incoming params and sets code_owner_approval_required to false", :aggregate_failures do
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(ProtectedBranch.last.code_owner_approval_required).to be_falsy
end
......@@ -42,21 +42,34 @@ RSpec.describe ProtectedBranches::CreateService do
context "when available" do
before do
stub_licensed_features(code_owner_approval_required: true)
params[:code_owner_approval_required] = code_owner_approval_required
end
it "sets code_owner_approval_required to true when param is true" do
params[:code_owner_approval_required] = true
context "when code_owner_approval_required param is true" do
let(:code_owner_approval_required) { true }
it "sets code_owner_approval_required to true", :aggregate_failures do
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(ProtectedBranch.last.code_owner_approval_required).to be_truthy
end
it "sets code_owner_approval_required to false when param is false" do
params[:code_owner_approval_required] = false
it_behaves_like 'records an onboarding progress action', :code_owners_enabled do
let(:namespace) { target_project.namespace }
subject { service.execute }
end
end
context "when code_owner_approval_required param is false" do
let(:code_owner_approval_required) { false }
it "sets code_owner_approval_required to false", :aggregate_failures do
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(ProtectedBranch.last.code_owner_approval_required).to be_falsy
end
it_behaves_like 'does not record an onboarding progress action'
end
end
end
......@@ -69,7 +82,7 @@ RSpec.describe ProtectedBranches::CreateService do
)
end
it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs" do
it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs", :aggregate_failures do
expect(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
end
......@@ -80,7 +93,7 @@ RSpec.describe ProtectedBranches::CreateService do
params[:name] = wildcard
end
it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs for #{wildcard}" do
it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs for #{wildcard}", :aggregate_failures do
expect(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
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