twigg-gerrit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ff29dfdbc080f961f71a24c20859f54626df8ce
4
- data.tar.gz: 82cb20f98939bfa5661d10d92e0d96c45048090c
3
+ metadata.gz: cf14f92aa02f165e411ca70ce8c8a77caa19588b
4
+ data.tar.gz: 727c1956048043d911964ecef08d480bfa905940
5
5
  SHA512:
6
- metadata.gz: 089b2d2dfdd246cafc3da1d707ff3d091a9441d1554a8a787bca00c92ed80c0486648c084e4a0f3615408b397065a278440caadf80e3f958fff8b3423beb7d90
7
- data.tar.gz: 9c17dc46598d22256d377366bb9258abc4fc9e41a3470a9eb936915c7fa8191e8ffb3729fb19a56fe68de6de3e9af95827b39126440a7d249912e7f304f05c90
6
+ metadata.gz: 890728614db3b7c7fd8211104bd1c55c7ec1376e436e6ae677df13aab412b3a2afab4d022ab3a2e5247b885b39b062a421eefd4acdf524ab75b2c08a7d392c37
7
+ data.tar.gz: fe4215bbed06466daa0a0d6ff51df22318b6b21d5f4ae1894738c90f345a93d30403a3f1e2f9ae3202406b9e9107748510587a7f1f59264c8ee389bea7650a76
@@ -4,5 +4,6 @@ module Twigg
4
4
  autoload :Author, 'twigg-gerrit/gerrit/author'
5
5
  autoload :Change, 'twigg-gerrit/gerrit/change'
6
6
  autoload :DB, 'twigg-gerrit/gerrit/db'
7
+ autoload :Tag, 'twigg-gerrit/gerrit/tag'
7
8
  end
8
9
  end
@@ -1,33 +1,41 @@
1
1
  module Twigg
2
2
  module Gerrit
3
- # Tag-related stats.
3
+ # Stats for "@" tags.
4
4
  class Tag
5
5
  class << self
6
+ # Returns a hash of "@" tag stats for the last `days` days.
7
+ #
8
+ # Within the hash there are 3 key-value pairs:
9
+ #
10
+ # - :from: a hash of "from" authors; each author has its own hash of
11
+ # tags and counts
12
+ # - :to: a hash of "to" authors; again with a subhash for each author
13
+ # - :global: a hash of all tags and their counts
14
+ #
6
15
  def stats(days: 7)
7
- # TODO: produce per author (to/from) and global stats
8
- (change_messages(days) + comment_messages(days)).each do |result|
9
- tags = tags_from_result(result)
10
- =begin
11
- {
12
- greg: {
13
- given: {
14
- tag: count
15
- },
16
- received: {
17
- tag: count
18
- }
19
- }
20
-
21
- // global stats
22
- nil: {
23
- tag: count
24
- }
25
- =end
16
+ {
17
+ from: Hash.new { |h, k| h[k] = Hash.new(0) },
18
+ to: Hash.new { |h, k| h[k] = Hash.new(0) },
19
+ global: Hash.new(0),
20
+ }.tap do |stats|
21
+ (change_messages(days) + comment_messages(days)).each do |result|
22
+ tags_from_result(result[:message]).each do |tag, count|
23
+ [
24
+ stats[:from][result[:from_full_name]],
25
+ stats[:to][result[:to_full_name]],
26
+ stats[:global],
27
+ ].each do |hash|
28
+ hash[tag] += count
29
+ end
30
+ end
31
+ end
26
32
  end
27
33
  end
28
34
 
29
35
  private
30
36
 
37
+ # Return all comment messages containing "@" tags within the last `days`
38
+ # days.
31
39
  def comment_messages(days)
32
40
  DB[<<-SQL, days].all
33
41
  SELECT message,
@@ -45,6 +53,8 @@ module Twigg
45
53
  SQL
46
54
  end
47
55
 
56
+ # Return all change messages containing "@" tags within the last `days`
57
+ # days.
48
58
  def change_messages(days)
49
59
  DB[<<-SQL, days].all
50
60
  SELECT message,
@@ -62,8 +72,14 @@ module Twigg
62
72
  SQL
63
73
  end
64
74
 
65
- def tags_from_result(result)
66
- result[:message].scan(/(?<=@)\w+/).map(&:downcase)
75
+ # Given a string, `text`, extract "@" tags.
76
+ #
77
+ # Returns a hash where the keys are tag names and the values are counts
78
+ # that indicate the number of times a tag appeared in `text`.
79
+ def tags_from_result(text)
80
+ tags = text.scan(/(?<=@)\w+/).map(&:downcase)
81
+
82
+ tags.each_with_object(Hash.new(0)) { |tag, memo| memo[tag] += 1 }
67
83
  end
68
84
  end
69
85
  end
@@ -1,5 +1,5 @@
1
1
  module Twigg
2
2
  module Gerrit
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twigg-gerrit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.1
61
+ version: 0.0.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.1
68
+ version: 0.0.2
69
69
  description: Twigg provides stats for activity in Git repositories. This is the adapter
70
70
  that enables Twigg to work with Gerrit installations.
71
71
  email: