Commit 23d2a594 authored by Kerri Miller's avatar Kerri Miller

Merge branch '299264-track-create-merge-request-from-issues' into 'master'

Resolve "Track Create merge request from issues" [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!53808
parents 2dba2182 f95cfdbc
...@@ -25,6 +25,7 @@ module MergeRequests ...@@ -25,6 +25,7 @@ module MergeRequests
new_merge_request = create(merge_request) new_merge_request = create(merge_request)
if new_merge_request.valid? if new_merge_request.valid?
merge_request_activity_counter.track_mr_create_from_issue(user: current_user)
SystemNoteService.new_merge_request(issue, project, current_user, new_merge_request) SystemNoteService.new_merge_request(issue, project, current_user, new_merge_request)
success(new_merge_request) success(new_merge_request)
......
---
title: Track when a merge request is created from an issue
merge_request: 53808
author:
type: other
---
name: usage_data_i_code_review_user_create_mr_from_issue
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53808
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
...@@ -159,3 +159,8 @@ ...@@ -159,3 +159,8 @@
category: code_review category: code_review
aggregation: weekly aggregation: weekly
feature_flag: usage_data_i_code_review_user_vs_code_api_request feature_flag: usage_data_i_code_review_user_vs_code_api_request
- name: i_code_review_user_create_mr_from_issue
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_create_mr_from_issue
...@@ -34,6 +34,7 @@ module Gitlab ...@@ -34,6 +34,7 @@ module Gitlab
MR_APPROVAL_RULE_DELETED_USERS_ACTION = 'i_code_review_user_approval_rule_deleted' MR_APPROVAL_RULE_DELETED_USERS_ACTION = 'i_code_review_user_approval_rule_deleted'
MR_EDIT_MR_TITLE_ACTION = 'i_code_review_edit_mr_title' MR_EDIT_MR_TITLE_ACTION = 'i_code_review_edit_mr_title'
MR_EDIT_MR_DESC_ACTION = 'i_code_review_edit_mr_desc' MR_EDIT_MR_DESC_ACTION = 'i_code_review_edit_mr_desc'
MR_CREATE_FROM_ISSUE_ACTION = 'i_code_review_user_create_mr_from_issue'
class << self class << self
def track_mr_diffs_action(merge_request:) def track_mr_diffs_action(merge_request:)
...@@ -148,6 +149,10 @@ module Gitlab ...@@ -148,6 +149,10 @@ module Gitlab
track_unique_action_by_user(MR_TASK_ITEM_STATUS_CHANGED_ACTION, user) track_unique_action_by_user(MR_TASK_ITEM_STATUS_CHANGED_ACTION, user)
end end
def track_mr_create_from_issue(user:)
track_unique_action_by_user(MR_CREATE_FROM_ISSUE_ACTION, user)
end
private private
def track_unique_action_by_merge_request(action, merge_request) def track_unique_action_by_merge_request(action, merge_request)
......
...@@ -276,4 +276,12 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl ...@@ -276,4 +276,12 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_APPROVAL_RULE_DELETED_USERS_ACTION } let(:action) { described_class::MR_APPROVAL_RULE_DELETED_USERS_ACTION }
end end
end end
describe '.track_mr_create_from_issue' do
subject { described_class.track_mr_create_from_issue(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_CREATE_FROM_ISSUE_ACTION }
end
end
end end
...@@ -52,6 +52,14 @@ RSpec.describe MergeRequests::CreateFromIssueService do ...@@ -52,6 +52,14 @@ RSpec.describe MergeRequests::CreateFromIssueService do
service.execute service.execute
end end
it 'tracks the mr creation when the mr is valid' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_mr_create_from_issue)
.with(user: user)
service.execute
end
it 'creates the new_issue_branch system note when the branch could be created but the merge_request cannot be created', :sidekiq_might_not_need_inline do it 'creates the new_issue_branch system note when the branch could be created but the merge_request cannot be created', :sidekiq_might_not_need_inline do
expect_next_instance_of(MergeRequest) do |instance| expect_next_instance_of(MergeRequest) do |instance|
expect(instance).to receive(:valid?).at_least(:once).and_return(false) expect(instance).to receive(:valid?).at_least(:once).and_return(false)
...@@ -62,6 +70,17 @@ RSpec.describe MergeRequests::CreateFromIssueService do ...@@ -62,6 +70,17 @@ RSpec.describe MergeRequests::CreateFromIssueService do
service.execute service.execute
end end
it 'does not track the mr creation when the Mr is invalid' do
expect_next_instance_of(MergeRequest) do |instance|
expect(instance).to receive(:valid?).at_least(:once).and_return(false)
end
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_mr_create_from_issue)
service.execute
end
it 'creates a merge request', :sidekiq_might_not_need_inline do it 'creates a merge request', :sidekiq_might_not_need_inline do
expect { service.execute }.to change(target_project.merge_requests, :count).by(1) expect { service.execute }.to change(target_project.merge_requests, :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