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
class NoteCounter < BaseCounter
KNOWN_EVENTS = %w[create].freeze
PREFIX = 'note'
COUNTABLE_TYPES = %w[Snippet].freeze
COUNTABLE_TYPES = %w[Snippet Commit MergeRequest].freeze
class << self
def redis_key(event, noteable_type)
......@@ -24,9 +24,9 @@ module Gitlab::UsageDataCounters
end
def totals
{
snippet_comment: read(:create, 'Snippet')
}
COUNTABLE_TYPES.map do |countable_type|
[:"#{countable_type.underscore}_comment", read(:create, countable_type)]
end.to_h
end
private
......
......@@ -26,16 +26,22 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
end
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
let(:combinations) do
[
[:create, 'Snippet', 3]
[:create, 'Snippet', 3],
[:create, 'MergeRequest', 4],
[:create, 'Commit', 5]
]
end
let(:expected_totals) do
{ snippet_comment: 3 }
{ snippet_comment: 3,
merge_request_comment: 4,
commit_comment: 5 }
end
before do
......@@ -59,12 +65,16 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
where(:event, :noteable_type, :expected_count, :should_raise) do
:create | 'Snippet' | 1 | false
:wibble | 'Snippet' | 0 | true
:create | 'MergeRequest' | 1 | false
:wibble | 'MergeRequest' | 0 | true
:create | 'Commit' | 1 | false
:wibble | 'Commit' | 0 | true
:create | 'Issue' | 0 | false
:wibble | 'Issue' | 0 | false
end
with_them do
it "handles event" do
it 'handles event' do
if should_raise
expect { described_class.count(event, noteable_type) }.to raise_error(unknown_event_error)
else
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::UsageData do
......@@ -34,7 +36,7 @@ describe Gitlab::UsageData do
subject { described_class.data }
it "gathers usage data" do
it 'gathers usage data' do
expect(subject.keys).to include(*%i(
active_user_count
counts
......@@ -66,6 +68,8 @@ describe Gitlab::UsageData do
snippet_create: a_kind_of(Integer),
snippet_update: 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_update: a_kind_of(Integer),
wiki_pages_delete: a_kind_of(Integer),
......@@ -78,7 +82,7 @@ describe Gitlab::UsageData do
)
end
it "gathers usage counts" do
it 'gathers usage counts' do
expected_keys = %i(
assignee_lists
boards
......@@ -248,7 +252,7 @@ describe Gitlab::UsageData do
describe '#license_usage_data' do
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[:version]).to eq(Gitlab::VERSION)
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