Commit bf47d897 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'nicolasdular/onboarding-progress-auto-closed-issue' into 'master'

Record onboarding for issues closed by MRs

See merge request gitlab-org/gitlab!51903
parents 2e4e1f87 227d4c25
...@@ -39,7 +39,10 @@ module Issues ...@@ -39,7 +39,10 @@ module Issues
issue.update_project_counter_caches issue.update_project_counter_caches
track_incident_action(current_user, issue, :incident_closed) track_incident_action(current_user, issue, :incident_closed)
store_first_mentioned_in_commit_at(issue, closed_via) if closed_via.is_a?(MergeRequest) if closed_via.is_a?(MergeRequest)
store_first_mentioned_in_commit_at(issue, closed_via)
OnboardingProgressService.new(project.namespace).execute(action: :issue_auto_closed)
end
delete_milestone_closed_issue_counter_cache(issue.milestone) delete_milestone_closed_issue_counter_cache(issue.milestone)
end end
......
...@@ -112,10 +112,14 @@ RSpec.describe Issues::CloseService do ...@@ -112,10 +112,14 @@ RSpec.describe Issues::CloseService do
end end
context "closed by a merge request", :sidekiq_might_not_need_inline do context "closed by a merge request", :sidekiq_might_not_need_inline do
it 'mentions closure via a merge request' do subject(:close_issue) do
perform_enqueued_jobs do perform_enqueued_jobs do
described_class.new(project, user).close_issue(issue, closed_via: closing_merge_request) described_class.new(project, user).close_issue(issue, closed_via: closing_merge_request)
end end
end
it 'mentions closure via a merge request' do
close_issue
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
...@@ -124,12 +128,15 @@ RSpec.describe Issues::CloseService do ...@@ -124,12 +128,15 @@ RSpec.describe Issues::CloseService do
expect(email.body.parts.map(&:body)).to all(include(closing_merge_request.to_reference)) expect(email.body.parts.map(&:body)).to all(include(closing_merge_request.to_reference))
end end
it_behaves_like 'records an onboarding progress action', :issue_auto_closed do
let(:namespace) { project.namespace }
end
context 'when user cannot read merge request' do context 'when user cannot read merge request' do
it 'does not mention merge request' do it 'does not mention merge request' do
project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED) project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED)
perform_enqueued_jobs do
described_class.new(project, user).close_issue(issue, closed_via: closing_merge_request) close_issue
end
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
body_text = email.body.parts.map(&:body).join(" ") body_text = email.body.parts.map(&:body).join(" ")
...@@ -141,13 +148,11 @@ RSpec.describe Issues::CloseService do ...@@ -141,13 +148,11 @@ RSpec.describe Issues::CloseService do
end end
context 'updating `metrics.first_mentioned_in_commit_at`' do context 'updating `metrics.first_mentioned_in_commit_at`' do
subject { described_class.new(project, user).close_issue(issue, closed_via: closing_merge_request) }
context 'when `metrics.first_mentioned_in_commit_at` is not set' do context 'when `metrics.first_mentioned_in_commit_at` is not set' do
it 'uses the first commit authored timestamp' do it 'uses the first commit authored timestamp' do
expected = closing_merge_request.commits.first.authored_date expected = closing_merge_request.commits.first.authored_date
subject close_issue
expect(issue.metrics.first_mentioned_in_commit_at).to eq(expected) expect(issue.metrics.first_mentioned_in_commit_at).to eq(expected)
end end
...@@ -159,7 +164,7 @@ RSpec.describe Issues::CloseService do ...@@ -159,7 +164,7 @@ RSpec.describe Issues::CloseService do
end end
it 'does not update the metrics' do it 'does not update the metrics' do
expect { subject }.not_to change { issue.metrics.first_mentioned_in_commit_at } expect { close_issue }.not_to change { issue.metrics.first_mentioned_in_commit_at }
end end
end end
...@@ -167,7 +172,7 @@ RSpec.describe Issues::CloseService do ...@@ -167,7 +172,7 @@ RSpec.describe Issues::CloseService do
let(:closing_merge_request) { create(:merge_request, :without_diffs, source_project: project) } let(:closing_merge_request) { create(:merge_request, :without_diffs, source_project: project) }
it 'does not update the metrics' do it 'does not update the metrics' do
subject close_issue
expect(issue.metrics.first_mentioned_in_commit_at).to be_nil expect(issue.metrics.first_mentioned_in_commit_at).to be_nil
end end
...@@ -206,7 +211,7 @@ RSpec.describe Issues::CloseService do ...@@ -206,7 +211,7 @@ RSpec.describe Issues::CloseService do
end end
context "valid params" do context "valid params" do
def close_issue subject(:close_issue) do
perform_enqueued_jobs do perform_enqueued_jobs do
described_class.new(project, user).close_issue(issue) described_class.new(project, user).close_issue(issue)
end end
...@@ -290,6 +295,8 @@ RSpec.describe Issues::CloseService do ...@@ -290,6 +295,8 @@ RSpec.describe Issues::CloseService do
close_issue close_issue
end end
it_behaves_like 'does not record an onboarding progress action'
end end
context 'when issue is not confidential' do context 'when issue is not confidential' 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