Commit 7276a4f9 authored by Kerri Miller's avatar Kerri Miller Committed by Markus Koller

Track WIP/Draft change events with usage counters [RUN ALL RSPEC] [RUN AS-IF-FOSS]

parent 32de17b6
......@@ -101,8 +101,30 @@ module MergeRequests
%w(title description).each do |action|
next unless @issuable_changes.key?(action)
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
# Track edits to title or description
#
merge_request_activity_counter
.public_send("track_#{action}_edit_action".to_sym, user: current_user) # rubocop:disable GitlabSecurity/PublicSend
# Track changes to Draft/WIP status
#
if action == "title"
old_title, new_title = @issuable_changes["title"]
old_title_wip = MergeRequest.work_in_progress?(old_title)
new_title_wip = MergeRequest.work_in_progress?(new_title)
if !old_title_wip && new_title_wip
# Marked as Draft/WIP
#
merge_request_activity_counter
.track_marked_as_draft_action(user: current_user)
elsif old_title_wip && !new_title_wip
# Unmarked as Draft/WIP
#
merge_request_activity_counter
.track_unmarked_as_draft_action(user: current_user)
end
end
end
end
......
---
name: usage_data_i_code_review_user_marked_as_draft
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/301223
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_unmarked_as_draft
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/301223
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
......@@ -119,6 +119,16 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_assigned
- name: i_code_review_user_marked_as_draft
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_marked_as_draft
- name: i_code_review_user_unmarked_as_draft
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_unmarked_as_draft
- name: i_code_review_user_review_requested
redis_slot: code_review
category: code_review
......
......@@ -22,6 +22,8 @@ module Gitlab
MR_REMOVE_MULTILINE_COMMENT_ACTION = 'i_code_review_user_remove_multiline_mr_comment'
MR_ADD_SUGGESTION_ACTION = 'i_code_review_user_add_suggestion'
MR_APPLY_SUGGESTION_ACTION = 'i_code_review_user_apply_suggestion'
MR_MARKED_AS_DRAFT_ACTION = 'i_code_review_user_marked_as_draft'
MR_UNMARKED_AS_DRAFT_ACTION = 'i_code_review_user_unmarked_as_draft'
MR_RESOLVE_THREAD_ACTION = 'i_code_review_user_resolve_thread'
MR_UNRESOLVE_THREAD_ACTION = 'i_code_review_user_unresolve_thread'
MR_ASSIGNED_USERS_ACTION = 'i_code_review_user_assigned'
......@@ -101,6 +103,14 @@ module Gitlab
track_unique_action_by_user(MR_ADD_SUGGESTION_ACTION, user)
end
def track_marked_as_draft_action(user:)
track_unique_action_by_user(MR_MARKED_AS_DRAFT_ACTION, user)
end
def track_unmarked_as_draft_action(user:)
track_unique_action_by_user(MR_UNMARKED_AS_DRAFT_ACTION, user)
end
def track_apply_suggestion_action(user:)
track_unique_action_by_user(MR_APPLY_SUGGESTION_ACTION, user)
end
......
......@@ -21,6 +21,14 @@ FactoryBot.define do
merge_status { "can_be_merged" }
trait :draft_merge_request do
title { generate(:draft_title) }
end
trait :wip_merge_request do
title { generate(:wip_title) }
end
trait :jira_title do
title { generate(:jira_title) }
end
......
......@@ -15,6 +15,8 @@ FactoryBot.define do
sequence(:sha) { |n| Digest::SHA1.hexdigest("commit-like-#{n}") }
sequence(:oid) { |n| Digest::SHA2.hexdigest("oid-like-#{n}") }
sequence(:variable) { |n| "var#{n}" }
sequence(:draft_title) { |n| "Draft: #{n}" }
sequence(:wip_title) { |n| "WIP: #{n}" }
sequence(:jira_title) { |n| "[PROJ-#{n}]: fix bug" }
sequence(:jira_branch) { |n| "feature/PROJ-#{n}" }
end
......@@ -221,6 +221,22 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
end
end
describe '.track_marked_as_draft_action' do
subject { described_class.track_marked_as_draft_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_MARKED_AS_DRAFT_ACTION }
end
end
describe '.track_unmarked_as_draft_action' do
subject { described_class.track_unmarked_as_draft_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_UNMARKED_AS_DRAFT_ACTION }
end
end
describe '.track_users_review_requested' do
subject { described_class.track_users_review_requested(users: [user]) }
......
......@@ -1316,7 +1316,16 @@ RSpec.describe API::MergeRequests do
end
context 'Work in Progress' do
let!(:merge_request_wip) { create(:merge_request, author: user, assignees: [user], source_project: project, target_project: project, title: "WIP: Test", created_at: base_time + 1.second) }
let!(:merge_request_wip) do
create(:merge_request,
author: user,
assignees: [user],
source_project: project,
target_project: project,
title: "WIP: Test",
created_at: base_time + 1.second
)
end
it "returns merge request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.iid}", user)
......
......@@ -89,6 +89,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
context 'usage counters' do
let(:merge_request2) { create(:merge_request) }
let(:draft_merge_request) { create(:merge_request, :draft_merge_request)}
it 'update as expected' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
......@@ -98,6 +99,24 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request2)
end
it 'tracks Draft/WIP marking' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_marked_as_draft_action).once.with(user: user)
opts[:title] = "WIP: #{opts[:title]}"
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request2)
end
it 'tracks Draft/WIP un-marking' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unmarked_as_draft_action).once.with(user: user)
opts[:title] = "Non-draft/wip title string"
MergeRequests::UpdateService.new(project, user, opts).execute(draft_merge_request)
end
end
context 'updating milestone' 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