Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7276a4f9
Commit
7276a4f9
authored
Feb 11, 2021
by
Kerri Miller
Committed by
Markus Koller
Feb 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track WIP/Draft change events with usage counters [RUN ALL RSPEC] [RUN AS-IF-FOSS]
parent
32de17b6
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
114 additions
and
2 deletions
+114
-2
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+23
-1
config/feature_flags/development/usage_data_i_code_review_user_marked_as_draft.yml
...lopment/usage_data_i_code_review_user_marked_as_draft.yml
+8
-0
config/feature_flags/development/usage_data_i_code_review_user_unmarked_as_draft.yml
...pment/usage_data_i_code_review_user_unmarked_as_draft.yml
+8
-0
lib/gitlab/usage_data_counters/known_events/code_review_events.yml
...b/usage_data_counters/known_events/code_review_events.yml
+10
-0
lib/gitlab/usage_data_counters/merge_request_activity_unique_counter.rb
...ge_data_counters/merge_request_activity_unique_counter.rb
+10
-0
spec/factories/merge_requests.rb
spec/factories/merge_requests.rb
+8
-0
spec/factories/sequences.rb
spec/factories/sequences.rb
+2
-0
spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb
...ta_counters/merge_request_activity_unique_counter_spec.rb
+16
-0
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+10
-1
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+19
-0
No files found.
app/services/merge_requests/update_service.rb
View file @
7276a4f9
...
...
@@ -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
...
...
config/feature_flags/development/usage_data_i_code_review_user_marked_as_draft.yml
0 → 100644
View file @
7276a4f9
---
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
config/feature_flags/development/usage_data_i_code_review_user_unmarked_as_draft.yml
0 → 100644
View file @
7276a4f9
---
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
lib/gitlab/usage_data_counters/known_events/code_review_events.yml
View file @
7276a4f9
...
...
@@ -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
...
...
lib/gitlab/usage_data_counters/merge_request_activity_unique_counter.rb
View file @
7276a4f9
...
...
@@ -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
...
...
spec/factories/merge_requests.rb
View file @
7276a4f9
...
...
@@ -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
...
...
spec/factories/sequences.rb
View file @
7276a4f9
...
...
@@ -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
spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb
View file @
7276a4f9
...
...
@@ -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
])
}
...
...
spec/requests/api/merge_requests_spec.rb
View file @
7276a4f9
...
...
@@ -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
)
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
7276a4f9
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment