barkeep 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -6
- data/lib/barkeep.rb +41 -26
- data/lib/grit_wrapper.rb +7 -6
- data/test/helper.rb +0 -3
- data/test/test_barkeep.rb +6 -3
- metadata +18 -50
data/README.rdoc
CHANGED
@@ -11,20 +11,26 @@ http://i.imgur.com/0TTHX.png
|
|
11
11
|
== Install
|
12
12
|
|
13
13
|
* Install and require gem (add it to your Gemfile or your environment.rb file).
|
14
|
-
* include Barkeep in your ApplicationHelper, i.e.
|
14
|
+
* in Rails, include Barkeep in your ApplicationHelper, i.e.
|
15
15
|
|
16
16
|
module ApplicationHelper
|
17
17
|
include Barkeep
|
18
18
|
...
|
19
19
|
end
|
20
20
|
|
21
|
+
* in Sinatra, include Barkeep as a helper in your main app file, i.e.
|
22
|
+
|
23
|
+
helpers Barkeep
|
24
|
+
|
21
25
|
* add the barkeep styles in your layout header, i.e
|
22
26
|
|
23
|
-
<%= barkeep_styles
|
27
|
+
<%= barkeep_styles %>
|
24
28
|
|
25
29
|
* call render_barkeep from your layout or footer, i.e.
|
26
30
|
|
27
|
-
<%= render_barkeep
|
31
|
+
<%= render_barkeep %>
|
32
|
+
|
33
|
+
* These two methods will return an empty string unless the app is running under one of the environments specified in your config file
|
28
34
|
|
29
35
|
* Create a config file in config/barkeep.json (see example below)
|
30
36
|
|
@@ -32,8 +38,8 @@ http://i.imgur.com/0TTHX.png
|
|
32
38
|
|
33
39
|
Configuration is specified in a config/barkeep.json
|
34
40
|
|
35
|
-
You want to specify some panes
|
36
|
-
default panes:
|
41
|
+
You want to specify some panes, a github url, and the environments in which you
|
42
|
+
want to render Barkeep. Here is a config with all the default panes:
|
37
43
|
|
38
44
|
{
|
39
45
|
"panes" : [
|
@@ -43,7 +49,8 @@ default panes:
|
|
43
49
|
"commit_date_info",
|
44
50
|
"rpm_request_info"
|
45
51
|
],
|
46
|
-
"github_url" : "https://github.com/USER_OR_ORGANIZATION/PROJECT_NAME"
|
52
|
+
"github_url" : "https://github.com/USER_OR_ORGANIZATION/PROJECT_NAME",
|
53
|
+
"environments" : ["development", "stage"]
|
47
54
|
}
|
48
55
|
|
49
56
|
Panes are rendered in the order specified in the array. You can specify as
|
data/lib/barkeep.rb
CHANGED
@@ -2,53 +2,65 @@ require 'json'
|
|
2
2
|
require 'grit_wrapper'
|
3
3
|
|
4
4
|
module Barkeep
|
5
|
+
def load_barkeep?
|
6
|
+
if defined?(Rails)
|
7
|
+
this_env = Rails.env
|
8
|
+
elsif defined?(Sinatra)
|
9
|
+
this_env = Sinatra::Application.settings.environment
|
10
|
+
end
|
11
|
+
barkeep_config['environments'].include?(this_env.to_s)
|
12
|
+
end
|
13
|
+
|
5
14
|
def barkeep_styles
|
6
|
-
|
15
|
+
return unless load_barkeep?
|
16
|
+
%(<style>#{File.read(File.expand_path(File.dirname(__FILE__) + "/default.css"))}</style>)
|
7
17
|
end
|
8
18
|
|
9
19
|
def render_barkeep
|
10
|
-
return unless grit_info.repository?
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
return unless load_barkeep? && grit_info.repository?
|
21
|
+
|
22
|
+
%(
|
23
|
+
<dl id="barkeep">
|
24
|
+
#{
|
25
|
+
barkeep_config['panes'].map do |name|
|
26
|
+
if name =~ /^(p|partial) (.*)/
|
27
|
+
render :partial => $2
|
28
|
+
else
|
29
|
+
send(name)
|
30
|
+
end
|
31
|
+
end.join('')
|
32
|
+
}
|
33
|
+
<dd class="close">
|
34
|
+
<a href="#" onclick="c = document.getElementById('barkeep'); c.parentNode.removeChild(c); return false" title="Close me!">×</a>
|
35
|
+
</dd>
|
36
|
+
</dl>
|
37
|
+
)
|
24
38
|
end
|
25
39
|
|
26
40
|
def barkeep_config
|
27
|
-
@@barkeep_config ||= JSON.parse(File.read("
|
41
|
+
@@barkeep_config ||= JSON.parse(File.read("config/barkeep.json"))
|
28
42
|
end
|
29
43
|
|
30
44
|
def branch_info
|
31
|
-
|
32
|
-
content_tag(:dd, content_tag(:a, grit_info[:branch], branch_link_attributes))
|
45
|
+
%(<dt>Branch:</dt><dd><a href="#{branch_link_attributes[:href]}">#{grit_info[:branch]}</a></dd>)
|
33
46
|
end
|
34
47
|
|
35
48
|
def commit_sha_info
|
36
|
-
|
37
|
-
content_tag(:dd, content_tag(:a, grit_info[:commit].try(:slice, 0,8), commit_link_attributes))
|
49
|
+
%(<dt>Commit:</dt><dd><a href="#{commit_link_attributes[:href]}" title="#{commit_link_attributes[:title]}">#{(grit_info[:commit] || "").slice(0,8)}</a></dd>)
|
38
50
|
end
|
39
51
|
|
40
52
|
def commit_author_info
|
41
|
-
|
53
|
+
%(<dt>Who:</dt><dd>#{grit_info[:last_author]}</dd>)
|
42
54
|
end
|
43
55
|
|
44
56
|
def commit_date_info
|
45
|
-
|
57
|
+
short_date = (grit_info[:date].respond_to?(:strftime) ? grit_info[:date].strftime("%d %B, %H:%M") : short_date.to_s)
|
58
|
+
%(<dt>When:</dt><dd title="#{grit_info[:date].to_s}">#{short_date}</dd>)
|
46
59
|
end
|
47
60
|
|
48
61
|
def rpm_request_info
|
49
62
|
if rpm_enabled?
|
50
|
-
|
51
|
-
content_tag(:dd, link_to('request', rpm_url, :target => 'blank'))
|
63
|
+
%(<dt><a href="/newrelic">RPM:</a></dt><dd><a href="#{rpm_url}">request</a></dd>)
|
52
64
|
end
|
53
65
|
end
|
54
66
|
|
@@ -84,8 +96,11 @@ module Barkeep
|
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
99
|
+
def rpm_sample_id
|
100
|
+
NewRelic::Agent.instance.transaction_sampler.current_sample_id
|
101
|
+
end
|
102
|
+
|
87
103
|
def rpm_url
|
88
|
-
|
89
|
-
"/newrelic/show_sample_detail/#{rpm_id}"
|
104
|
+
"/newrelic/show_sample_detail/#{rpm_sample_id}"
|
90
105
|
end
|
91
106
|
end
|
data/lib/grit_wrapper.rb
CHANGED
@@ -3,12 +3,13 @@ require 'grit'
|
|
3
3
|
# A singleton refreshes on every request in development but
|
4
4
|
# caches in environments where class caching is enabled.
|
5
5
|
require 'singleton'
|
6
|
+
require 'ostruct'
|
6
7
|
|
7
8
|
class GritWrapper
|
8
9
|
include Singleton
|
9
10
|
|
10
11
|
def repository
|
11
|
-
@repository ||= Grit::Repo.new(
|
12
|
+
@repository ||= Grit::Repo.new('.')
|
12
13
|
rescue Grit::InvalidGitRepositoryError
|
13
14
|
# not in a directory that contains .git
|
14
15
|
@repository = :invalid
|
@@ -27,21 +28,21 @@ class GritWrapper
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def last_commit
|
30
|
-
@last_commit ||= repository.commit(last_commit_hash)
|
31
|
+
@last_commit ||= repository.commit(last_commit_hash) || OpenStruct.new
|
31
32
|
end
|
32
33
|
|
33
34
|
def to_hash
|
34
35
|
return {
|
35
36
|
:branch => 'Not currently on a branch.',
|
36
|
-
:commit => (File.read(
|
37
|
+
:commit => (File.read("REVISION").strip rescue nil)
|
37
38
|
} if head.nil?
|
38
39
|
|
39
40
|
@hash ||= {
|
40
41
|
:branch => head.name,
|
41
42
|
:commit => last_commit_hash,
|
42
|
-
:last_author => last_commit.
|
43
|
-
:message => last_commit.
|
44
|
-
:date => last_commit.
|
43
|
+
:last_author => last_commit.author,
|
44
|
+
:message => last_commit.message,
|
45
|
+
:date => last_commit.authored_date
|
45
46
|
}
|
46
47
|
end
|
47
48
|
|
data/test/helper.rb
CHANGED
@@ -10,9 +10,6 @@ end
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'shoulda'
|
12
12
|
require 'mocha'
|
13
|
-
require 'active_support'
|
14
|
-
require 'action_pack'
|
15
|
-
require 'action_view'
|
16
13
|
|
17
14
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
15
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
data/test/test_barkeep.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestBarkeep < Test::Unit::TestCase
|
4
|
-
include ActionView::Helpers
|
5
4
|
include Barkeep
|
6
5
|
|
7
6
|
attr_accessor :output_buffer
|
8
7
|
|
8
|
+
def setup
|
9
|
+
stubs(:load_barkeep? => true)
|
10
|
+
end
|
11
|
+
|
9
12
|
should "render a style tag filled with css" do
|
10
13
|
css = File.read(File.expand_path(File.dirname(__FILE__) + "/../lib/default.css"))
|
11
14
|
assert_equal "<style>#{css}</style>", barkeep_styles
|
12
15
|
end
|
13
16
|
|
14
17
|
should "render the barkeep bar" do
|
15
|
-
stubs(:barkeep_config => {'github_url' => 'http://github.com/project_name', 'panes' => ['branch_info', 'commit_sha_info']})
|
18
|
+
stubs(:barkeep_config => {'github_url' => 'http://github.com/project_name', 'panes' => ['branch_info', 'commit_sha_info'], 'environments' => ['development']})
|
16
19
|
GritWrapper.instance.stubs(:repository? => true, :to_hash => {:branch => 'new_branch', :commit => 'abcdef'})
|
17
20
|
expected = %(
|
18
21
|
<dl id="barkeep">
|
@@ -23,6 +26,6 @@ class TestBarkeep < Test::Unit::TestCase
|
|
23
26
|
<dd class="close"><a href="#" onclick="c = document.getElementById('barkeep'); c.parentNode.removeChild(c); return false" title="Close me!">×</a></dd>
|
24
27
|
</dl>
|
25
28
|
)
|
26
|
-
assert_equal expected.gsub(/\
|
29
|
+
assert_equal expected.gsub(/\s+/, ''), render_barkeep.gsub(/\s+/, '')
|
27
30
|
end
|
28
31
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barkeep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- PatientsLikeMe
|
@@ -15,13 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: grit
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
@@ -31,11 +31,11 @@ dependencies:
|
|
31
31
|
- 0
|
32
32
|
version: "0"
|
33
33
|
type: :runtime
|
34
|
-
|
34
|
+
requirement: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: json
|
37
37
|
prerelease: false
|
38
|
-
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
@@ -45,43 +45,11 @@ dependencies:
|
|
45
45
|
- 0
|
46
46
|
version: "0"
|
47
47
|
type: :runtime
|
48
|
-
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: activesupport
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - "="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
hash: 21
|
58
|
-
segments:
|
59
|
-
- 2
|
60
|
-
- 3
|
61
|
-
- 11
|
62
|
-
version: 2.3.11
|
63
|
-
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: actionpack
|
67
|
-
prerelease: false
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - "="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
hash: 21
|
74
|
-
segments:
|
75
|
-
- 2
|
76
|
-
- 3
|
77
|
-
- 11
|
78
|
-
version: 2.3.11
|
79
|
-
type: :development
|
80
|
-
version_requirements: *id004
|
48
|
+
requirement: *id002
|
81
49
|
- !ruby/object:Gem::Dependency
|
82
50
|
name: mocha
|
83
51
|
prerelease: false
|
84
|
-
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
85
53
|
none: false
|
86
54
|
requirements:
|
87
55
|
- - ">="
|
@@ -93,11 +61,11 @@ dependencies:
|
|
93
61
|
- 12
|
94
62
|
version: 0.9.12
|
95
63
|
type: :development
|
96
|
-
|
64
|
+
requirement: *id003
|
97
65
|
- !ruby/object:Gem::Dependency
|
98
66
|
name: shoulda
|
99
67
|
prerelease: false
|
100
|
-
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
101
69
|
none: false
|
102
70
|
requirements:
|
103
71
|
- - ">="
|
@@ -107,11 +75,11 @@ dependencies:
|
|
107
75
|
- 0
|
108
76
|
version: "0"
|
109
77
|
type: :development
|
110
|
-
|
78
|
+
requirement: *id004
|
111
79
|
- !ruby/object:Gem::Dependency
|
112
80
|
name: bundler
|
113
81
|
prerelease: false
|
114
|
-
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
115
83
|
none: false
|
116
84
|
requirements:
|
117
85
|
- - ~>
|
@@ -123,11 +91,11 @@ dependencies:
|
|
123
91
|
- 0
|
124
92
|
version: 1.0.0
|
125
93
|
type: :development
|
126
|
-
|
94
|
+
requirement: *id005
|
127
95
|
- !ruby/object:Gem::Dependency
|
128
96
|
name: jeweler
|
129
97
|
prerelease: false
|
130
|
-
|
98
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
131
99
|
none: false
|
132
100
|
requirements:
|
133
101
|
- - ~>
|
@@ -139,11 +107,11 @@ dependencies:
|
|
139
107
|
- 2
|
140
108
|
version: 1.5.2
|
141
109
|
type: :development
|
142
|
-
|
110
|
+
requirement: *id006
|
143
111
|
- !ruby/object:Gem::Dependency
|
144
112
|
name: rcov
|
145
113
|
prerelease: false
|
146
|
-
|
114
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
147
115
|
none: false
|
148
116
|
requirements:
|
149
117
|
- - ">="
|
@@ -153,7 +121,7 @@ dependencies:
|
|
153
121
|
- 0
|
154
122
|
version: "0"
|
155
123
|
type: :development
|
156
|
-
|
124
|
+
requirement: *id007
|
157
125
|
description: an extensible developer's status bar to track your current deployed commit & more
|
158
126
|
email: open_source@patientslikeme.com
|
159
127
|
executables: []
|