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 ...@@ -23,6 +23,7 @@ module EE
super super
sync_code_owner_approval_rules if project.feature_available?(:code_owners) sync_code_owner_approval_rules if project.feature_available?(:code_owners)
track_onboarding_progress
protected_branch protected_branch
end end
...@@ -58,6 +59,12 @@ module EE ...@@ -58,6 +59,12 @@ module EE
.preload_source_project .preload_source_project
.select(&:source_project) .select(&:source_project)
end 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 end
end end
...@@ -33,7 +33,7 @@ RSpec.describe ProtectedBranches::CreateService do ...@@ -33,7 +33,7 @@ RSpec.describe ProtectedBranches::CreateService do
params[:code_owner_approval_required] = true params[:code_owner_approval_required] = true
end 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 { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(ProtectedBranch.last.code_owner_approval_required).to be_falsy expect(ProtectedBranch.last.code_owner_approval_required).to be_falsy
end end
...@@ -42,20 +42,33 @@ RSpec.describe ProtectedBranches::CreateService do ...@@ -42,20 +42,33 @@ RSpec.describe ProtectedBranches::CreateService do
context "when available" do context "when available" do
before do before do
stub_licensed_features(code_owner_approval_required: true) stub_licensed_features(code_owner_approval_required: true)
params[:code_owner_approval_required] = code_owner_approval_required
end end
it "sets code_owner_approval_required to true when param is true" do context "when code_owner_approval_required param is true" do
params[:code_owner_approval_required] = true let(:code_owner_approval_required) { true }
expect { service.execute }.to change(ProtectedBranch, :count).by(1) it "sets code_owner_approval_required to true", :aggregate_failures do
expect(ProtectedBranch.last.code_owner_approval_required).to be_truthy expect { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(ProtectedBranch.last.code_owner_approval_required).to be_truthy
end
it_behaves_like 'records an onboarding progress action', :code_owners_enabled do
let(:namespace) { target_project.namespace }
subject { service.execute }
end
end end
it "sets code_owner_approval_required to false when param is false" do context "when code_owner_approval_required param is false" do
params[:code_owner_approval_required] = false let(:code_owner_approval_required) { false }
expect { service.execute }.to change(ProtectedBranch, :count).by(1) it "sets code_owner_approval_required to false", :aggregate_failures do
expect(ProtectedBranch.last.code_owner_approval_required).to be_falsy 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 end
end end
...@@ -69,7 +82,7 @@ RSpec.describe ProtectedBranches::CreateService do ...@@ -69,7 +82,7 @@ RSpec.describe ProtectedBranches::CreateService do
) )
end 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(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original
expect { service.execute }.to change(ProtectedBranch, :count).by(1) expect { service.execute }.to change(ProtectedBranch, :count).by(1)
end end
...@@ -80,7 +93,7 @@ RSpec.describe ProtectedBranches::CreateService do ...@@ -80,7 +93,7 @@ RSpec.describe ProtectedBranches::CreateService do
params[:name] = wildcard params[:name] = wildcard
end 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(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original
expect { service.execute }.to change(ProtectedBranch, :count).by(1) expect { service.execute }.to change(ProtectedBranch, :count).by(1)
end 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