twigg 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twigg/cacher.rb +85 -0
- data/lib/twigg/command/stats.rb +1 -0
- data/lib/twigg/commit.rb +1 -1
- data/lib/twigg/commit_set.rb +2 -0
- data/lib/twigg/config.rb +7 -4
- data/lib/twigg/dependency.rb +2 -0
- data/lib/twigg/repo.rb +2 -4
- data/lib/twigg/settings.rb +8 -0
- data/lib/twigg/version.rb +1 -1
- data/lib/twigg.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08f8b0a5dc7eaafda3901ab196d782d98f6aecba
|
4
|
+
data.tar.gz: 5b7524480befd14000a0571316787ba5b4ba6194
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e0219ae5d8e788b11db183b962889e1ec6153a01f519bbf82a304e1ac5d6e61ad4ad46ee3d9a3ac9e4afab08b49930e20762f11e530ecba01b3e22ee0c4781e
|
7
|
+
data.tar.gz: f50671909a2c1f24da4ee39ea5317a71f93e5d7c80cf64216971b3dd222701c0c3c70208334d62f8a99265cb9bc378aa55906dafa2afa1a20d9732db95366d53
|
data/lib/twigg/cacher.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Twigg
|
4
|
+
# The Cacher module is an abstraction around caching that offers two public
|
5
|
+
# methods, {Twigg::Cacher.get} and {Twigg::Cacher.set}.
|
6
|
+
#
|
7
|
+
# If the twigg-cache gem is installed and enabled, delegates the storing of
|
8
|
+
# cached items to Memcached. In the absence of the gem, every cache lookup is
|
9
|
+
# treated as a miss.
|
10
|
+
module Cacher
|
11
|
+
# Dummy Memcached client that always misses.
|
12
|
+
class DummyClient
|
13
|
+
def get(key); end
|
14
|
+
def set(key); end
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
include Dependency # for with_dependency
|
19
|
+
|
20
|
+
# Gets stored value for `key`; in the event of a cache miss, yields to
|
21
|
+
# `block`, and caches and returns the result. `*args`, if present, are
|
22
|
+
# hashed and appended to key to permit the results of different calls to
|
23
|
+
# the same method to be conveniently stored and retrieved independently.
|
24
|
+
#
|
25
|
+
# Note: if a `nil` or `false` value is ever stored in the cache, this
|
26
|
+
# method will consider any lookup of the corresponding key to be a miss,
|
27
|
+
# because we employ a simply truthiness check to determine presence.
|
28
|
+
def get(key, *args, &block)
|
29
|
+
raise ArgumentError, 'block required by not given' unless block_given?
|
30
|
+
digest = hashed_key_and_args(key, *args)
|
31
|
+
client.get(digest) || set(key, *args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Stores the result of yielding to `block` in the cache, with `key` as
|
35
|
+
# key, and returns the result.
|
36
|
+
#
|
37
|
+
# As with {get}, any `*args`, if present, are hashed and appended to the
|
38
|
+
# key to premit the results of different calls to the same method to be
|
39
|
+
# conveniently stored and retrieved independently.
|
40
|
+
def set(key, *args, &block)
|
41
|
+
digest = hashed_key_and_args(key, *args)
|
42
|
+
yield.tap { |result| client.set(digest, result) }
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def client
|
48
|
+
@client ||= (caching? ? Cache::Client.new : DummyClient.new)
|
49
|
+
end
|
50
|
+
|
51
|
+
def caching?
|
52
|
+
return false unless Config.cache.enabled # don't want to load the gem
|
53
|
+
return true if defined?(Twigg::Cache) # gem was already loaded
|
54
|
+
with_dependency('twigg-cache') { true } # will die if can't load
|
55
|
+
end
|
56
|
+
|
57
|
+
# Produces a composite cache key based on `key` and a digest of `args`.
|
58
|
+
#
|
59
|
+
# If `args` contains non-shallow objects such as hashes or arrays, uses
|
60
|
+
# recursion to incorporate the contents of those objects in the digest.
|
61
|
+
#
|
62
|
+
# Will raise an exception if `args` or any object encontered via recursion
|
63
|
+
# is not a "simple" object (Hash, Array, String, NilClas, Numeric, or
|
64
|
+
# Symbol).
|
65
|
+
def hashed_key_and_args(key, *args)
|
66
|
+
base = args.inject('') do |memo, arg|
|
67
|
+
memo << (':' + arg.class.to_s + ':') << case arg
|
68
|
+
when Array
|
69
|
+
hashed_key_and_args(key, *arg)
|
70
|
+
when Hash
|
71
|
+
hashed_key_and_args(key, *arg.to_a)
|
72
|
+
when NilClass,Numeric, String, Symbol
|
73
|
+
arg.to_s
|
74
|
+
else
|
75
|
+
raise ArgumentError, 'can only compute digest for primitive objects'
|
76
|
+
end
|
77
|
+
|
78
|
+
Digest::SHA1::hexdigest(memo)
|
79
|
+
end
|
80
|
+
|
81
|
+
key + ':' + base
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/twigg/command/stats.rb
CHANGED
data/lib/twigg/commit.rb
CHANGED
@@ -34,7 +34,7 @@ module Twigg
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def filtered_commit_message
|
37
|
-
@filtered_commit_message ||= @body.
|
37
|
+
@filtered_commit_message ||= @body.reject do |line|
|
38
38
|
line =~ /^[a-z-]+: /i # filter out Change-Id:, Signed-off-by: etc
|
39
39
|
end.concat([@subject]).join("\n").chomp
|
40
40
|
end
|
data/lib/twigg/commit_set.rb
CHANGED
data/lib/twigg/config.rb
CHANGED
@@ -39,8 +39,9 @@ module Twigg
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def initialize
|
43
|
-
@settings = Settings.new(
|
42
|
+
def initialize(twiggrc: nil)
|
43
|
+
@settings = Settings.new(config_from_file(twiggrc) ||
|
44
|
+
config_from_argv ||
|
44
45
|
config_from_env ||
|
45
46
|
config_from_home)
|
46
47
|
end
|
@@ -53,6 +54,8 @@ module Twigg
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def config_from_file(path)
|
57
|
+
return unless path
|
58
|
+
|
56
59
|
YAML.load_file(path).tap do |contents|
|
57
60
|
if File.world_readable?(path)
|
58
61
|
warn "#{path} is world-readable"
|
@@ -77,11 +80,11 @@ module Twigg
|
|
77
80
|
# twigg-app.gemspec), which means that this happens before the
|
78
81
|
# Twigg::Command.run method gets a chance to set things up properly.
|
79
82
|
path = consume_option(%w[-c --config], ARGV)
|
80
|
-
config_from_file(path)
|
83
|
+
config_from_file(path)
|
81
84
|
end
|
82
85
|
|
83
86
|
def config_from_env
|
84
|
-
config_from_file(ENV['TWIGGRC'])
|
87
|
+
config_from_file(ENV['TWIGGRC'])
|
85
88
|
end
|
86
89
|
|
87
90
|
TWIGGRC = '.twiggrc'
|
data/lib/twigg/dependency.rb
CHANGED
data/lib/twigg/repo.rb
CHANGED
@@ -100,25 +100,23 @@ module Twigg
|
|
100
100
|
loop do
|
101
101
|
begin
|
102
102
|
commit = { repo: self }
|
103
|
+
commit[:body] = []
|
104
|
+
commit[:stat] = Hash.new(0)
|
103
105
|
commit[:commit] = lines.next.chomp
|
104
106
|
commit[:author] = lines.next.chomp
|
105
107
|
commit[:date] = Time.at(lines.next.chomp.to_i).to_date
|
106
108
|
commit[:subject] = lines.next.chomp rescue ''
|
107
109
|
|
108
|
-
commit[:body] = []
|
109
110
|
while lines.peek =~ /^ {4}(.*)$/ && lines.next
|
110
111
|
commit[:body] << $~[1]
|
111
112
|
end
|
112
|
-
commit[:body] = commit[:body].join("\n")
|
113
113
|
lines.next if lines.peek == "\n" # blank separator line
|
114
114
|
|
115
|
-
commit[:stat] = Hash.new(0)
|
116
115
|
while lines.peek =~ /^(\d+|-)\t(\d+|-)\t.+$/ && lines.next
|
117
116
|
commit[:stat][:additions] += $~[1].to_i
|
118
117
|
commit[:stat][:deletions] += $~[2].to_i
|
119
118
|
end
|
120
119
|
lines.next if lines.peek == "\n" # blank separator line
|
121
|
-
|
122
120
|
rescue StopIteration
|
123
121
|
break # end of output
|
124
122
|
ensure
|
data/lib/twigg/settings.rb
CHANGED
@@ -30,6 +30,14 @@ module Twigg
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
namespace :cache do
|
34
|
+
setting :enabled, default: false
|
35
|
+
setting :expiry, default: 3600 # 1 hour
|
36
|
+
setting :host, default: 'localhost'
|
37
|
+
setting :namespace, default: 'twigg'
|
38
|
+
setting :port, default: 11211
|
39
|
+
end
|
40
|
+
|
33
41
|
setting :default_days, default: 7
|
34
42
|
|
35
43
|
namespace :gerrit do
|
data/lib/twigg/version.rb
CHANGED
data/lib/twigg.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twigg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
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-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- bin/twigg
|
92
92
|
- files/github.pem
|
93
|
+
- lib/twigg/cacher.rb
|
93
94
|
- lib/twigg/command/git.rb
|
94
95
|
- lib/twigg/command/git_host.rb
|
95
96
|
- lib/twigg/command/git_hub.rb
|