Commit f95cfdbc authored by Marc Shaw's avatar Marc Shaw

Track when a merge request is created from an issue

MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/53808
Issue: gitlab.com/gitlab-org/gitlab/-/issues/299264
parent dd1a6d26
......@@ -25,6 +25,7 @@ module MergeRequests
new_merge_request = create(merge_request)
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)
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 @@
category: code_review
aggregation: weekly
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
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_DESC_ACTION = 'i_code_review_edit_mr_desc'
MR_CREATE_FROM_ISSUE_ACTION = 'i_code_review_user_create_mr_from_issue'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -148,6 +149,10 @@ module Gitlab
track_unique_action_by_user(MR_TASK_ITEM_STATUS_CHANGED_ACTION, user)
end
def track_mr_create_from_issue(user:)
track_unique_action_by_user(MR_CREATE_FROM_ISSUE_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -276,4 +276,12 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_APPROVAL_RULE_DELETED_USERS_ACTION }
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
......@@ -52,6 +52,14 @@ RSpec.describe MergeRequests::CreateFromIssueService do
service.execute
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
expect_next_instance_of(MergeRequest) do |instance|
expect(instance).to receive(:valid?).at_least(:once).and_return(false)
......@@ -62,6 +70,17 @@ RSpec.describe MergeRequests::CreateFromIssueService do
service.execute
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
expect { service.execute }.to change(target_project.merge_requests, :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