Commit 011c5ceb authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-mr-commit-note-counter' into 'master'

Count notes for commits and merge requests

See merge request gitlab-org/gitlab-ce!31912
parents 31b508e8 71691d93
---
title: Count comments on commits and merge requests
merge_request: 31912
author:
type: other
...@@ -4,7 +4,7 @@ module Gitlab::UsageDataCounters ...@@ -4,7 +4,7 @@ module Gitlab::UsageDataCounters
class NoteCounter < BaseCounter class NoteCounter < BaseCounter
KNOWN_EVENTS = %w[create].freeze KNOWN_EVENTS = %w[create].freeze
PREFIX = 'note' PREFIX = 'note'
COUNTABLE_TYPES = %w[Snippet].freeze COUNTABLE_TYPES = %w[Snippet Commit MergeRequest].freeze
class << self class << self
def redis_key(event, noteable_type) def redis_key(event, noteable_type)
...@@ -24,9 +24,9 @@ module Gitlab::UsageDataCounters ...@@ -24,9 +24,9 @@ module Gitlab::UsageDataCounters
end end
def totals def totals
{ COUNTABLE_TYPES.map do |countable_type|
snippet_comment: read(:create, 'Snippet') [:"#{countable_type.underscore}_comment", read(:create, countable_type)]
} end.to_h
end end
private private
......
...@@ -26,16 +26,22 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat ...@@ -26,16 +26,22 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
end end
it_behaves_like 'a note usage counter', :create, 'Snippet' it_behaves_like 'a note usage counter', :create, 'Snippet'
it_behaves_like 'a note usage counter', :create, 'MergeRequest'
it_behaves_like 'a note usage counter', :create, 'Commit'
describe '.totals' do describe '.totals' do
let(:combinations) do let(:combinations) do
[ [
[:create, 'Snippet', 3] [:create, 'Snippet', 3],
[:create, 'MergeRequest', 4],
[:create, 'Commit', 5]
] ]
end end
let(:expected_totals) do let(:expected_totals) do
{ snippet_comment: 3 } { snippet_comment: 3,
merge_request_comment: 4,
commit_comment: 5 }
end end
before do before do
...@@ -57,14 +63,18 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat ...@@ -57,14 +63,18 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
let(:unknown_event_error) { Gitlab::UsageDataCounters::BaseCounter::UnknownEvent } let(:unknown_event_error) { Gitlab::UsageDataCounters::BaseCounter::UnknownEvent }
where(:event, :noteable_type, :expected_count, :should_raise) do where(:event, :noteable_type, :expected_count, :should_raise) do
:create | 'Snippet' | 1 | false :create | 'Snippet' | 1 | false
:wibble | 'Snippet' | 0 | true :wibble | 'Snippet' | 0 | true
:create | 'Issue' | 0 | false :create | 'MergeRequest' | 1 | false
:wibble | 'Issue' | 0 | false :wibble | 'MergeRequest' | 0 | true
:create | 'Commit' | 1 | false
:wibble | 'Commit' | 0 | true
:create | 'Issue' | 0 | false
:wibble | 'Issue' | 0 | false
end end
with_them do with_them do
it "handles event" do it 'handles event' do
if should_raise if should_raise
expect { described_class.count(event, noteable_type) }.to raise_error(unknown_event_error) expect { described_class.count(event, noteable_type) }.to raise_error(unknown_event_error)
else else
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::UsageData do describe Gitlab::UsageData do
...@@ -34,7 +36,7 @@ describe Gitlab::UsageData do ...@@ -34,7 +36,7 @@ describe Gitlab::UsageData do
subject { described_class.data } subject { described_class.data }
it "gathers usage data" do it 'gathers usage data' do
expect(subject.keys).to include(*%i( expect(subject.keys).to include(*%i(
active_user_count active_user_count
counts counts
...@@ -66,6 +68,8 @@ describe Gitlab::UsageData do ...@@ -66,6 +68,8 @@ describe Gitlab::UsageData do
snippet_create: a_kind_of(Integer), snippet_create: a_kind_of(Integer),
snippet_update: a_kind_of(Integer), snippet_update: a_kind_of(Integer),
snippet_comment: a_kind_of(Integer), snippet_comment: a_kind_of(Integer),
merge_request_comment: a_kind_of(Integer),
commit_comment: a_kind_of(Integer),
wiki_pages_create: a_kind_of(Integer), wiki_pages_create: a_kind_of(Integer),
wiki_pages_update: a_kind_of(Integer), wiki_pages_update: a_kind_of(Integer),
wiki_pages_delete: a_kind_of(Integer), wiki_pages_delete: a_kind_of(Integer),
...@@ -78,7 +82,7 @@ describe Gitlab::UsageData do ...@@ -78,7 +82,7 @@ describe Gitlab::UsageData do
) )
end end
it "gathers usage counts" do it 'gathers usage counts' do
expected_keys = %i( expected_keys = %i(
assignee_lists assignee_lists
boards boards
...@@ -248,7 +252,7 @@ describe Gitlab::UsageData do ...@@ -248,7 +252,7 @@ describe Gitlab::UsageData do
describe '#license_usage_data' do describe '#license_usage_data' do
subject { described_class.license_usage_data } subject { described_class.license_usage_data }
it "gathers license data" do it 'gathers license data' do
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid) expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
expect(subject[:version]).to eq(Gitlab::VERSION) expect(subject[:version]).to eq(Gitlab::VERSION)
expect(subject[:installation_type]).to eq('gitlab-development-kit') expect(subject[:installation_type]).to eq('gitlab-development-kit')
......
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