barkeep 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 PatientsLikeMe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,92 @@
1
+ = Barkeep
2
+
3
+ Barkeep is an extensible developer's status bar to track your current deployed
4
+ commit and more. Barkeep sits at the bottom of your app and shows information
5
+ you deem useful.
6
+
7
+ Here's an example of Barkeep running with some default panes:
8
+
9
+ http://i.imgur.com/0TTHX.png
10
+
11
+ == Install
12
+
13
+ * Install and require gem (add it to your Gemfile or your environment.rb file).
14
+ * include Barkeep in your ApplicationHelper, i.e.
15
+
16
+ module ApplicationHelper
17
+ include Barkeep
18
+ ...
19
+ end
20
+
21
+ * add the barkeep styles in your layout header, i.e
22
+
23
+ <%= barkeep_styles unless %W(test production).include?(Rails.env) %>
24
+
25
+ * call render_barkeep from your layout or footer, i.e.
26
+
27
+ <%= render_barkeep unless %W(test production).include?(Rails.env) %>
28
+
29
+ * Create a config file in config/barkeep.json (see example below)
30
+
31
+ == Config
32
+
33
+ Configuration is specified in a config/barkeep.json
34
+
35
+ You want to specify some panes and a github url. Here is a config with all the
36
+ default panes:
37
+
38
+ {
39
+ "panes" : [
40
+ "branch_info",
41
+ "commit_sha_info",
42
+ "commit_author_info",
43
+ "commit_date_info",
44
+ "rpm_request_info"
45
+ ],
46
+ "github_url" : "https://github.com/USER_OR_ORGANIZATION/PROJECT_NAME"
47
+ }
48
+
49
+ Panes are rendered in the order specified in the array. You can specify as
50
+ many panes as you wish.
51
+
52
+ Panes are assumed to either be methods accessible in the context of your
53
+ ApplicationHelper. Alternatively, you can specify a partial as a pane using
54
+ the format "partial path/to/your/partial"
55
+
56
+ == Custom Styling
57
+
58
+ Barkeep comes with some basic styling that has worked well for us. You are
59
+ encouraged to modify it to suit your needs. The easiest way to do this is to
60
+ call barkeep_styles as normal, view source, and extract the css (search for
61
+ barkeep). You can then pull it in to your main stylesheet or Sass-ify it, etc.
62
+
63
+ Once you've setup your own styles, you probably won't want to call
64
+ barkeep_styles anymore.
65
+
66
+ == Included panes
67
+
68
+ * branch_info: shows the current branch and links to the branch on github
69
+ * commit_sha_info: shows the current commit sha and links to the commit on
70
+ github (useful when testing on stage for knowing what is depolyed)
71
+ * commit_author_info: show the author of the current commit
72
+ * commit_date_info: show the date of the current commit (hover for full
73
+ timestamp)
74
+ * rpm_request_info: if you're using the newrelic gem in development mode, this
75
+ provides a link to the development newerelic index and a link to the current
76
+ request profiled in newrelic
77
+
78
+ == Contributing to Barkeep
79
+
80
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
81
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
82
+ * Fork the project
83
+ * Start a feature/bugfix branch
84
+ * Commit and push until you are happy with your contribution
85
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
86
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
87
+
88
+ == Copyright
89
+
90
+ Copyright (c) 2011 PatientsLikeMe. See LICENSE.txt for
91
+ further details.
92
+
data/lib/barkeep.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'json'
2
+ require 'grit_wrapper'
3
+
4
+ module Barkeep
5
+ def barkeep_styles
6
+ content_tag(:style, File.read(File.expand_path(File.dirname(__FILE__) + "/default.css")))
7
+ end
8
+
9
+ def render_barkeep
10
+ return unless grit_info.repository?
11
+
12
+ content_tag(:dl, :id => 'barkeep') do
13
+ barkeep_config['panes'].map do |name|
14
+ if name =~ /^(p|partial) (.*)/
15
+ render :partial => $2
16
+ else
17
+ send(name)
18
+ end
19
+ end <<
20
+ content_tag(:dd, :class => 'close') do
21
+ content_tag(:a, "&times;", :href => '#', :onclick => "c = document.getElementById('barkeep'); c.parentNode.removeChild(c); return false", :title => 'Close me!')
22
+ end
23
+ end
24
+ end
25
+
26
+ def barkeep_config
27
+ @@barkeep_config ||= JSON.parse(File.read("#{Rails.root}/config/barkeep.json"))
28
+ end
29
+
30
+ def branch_info
31
+ content_tag(:dt, 'Branch:') +
32
+ content_tag(:dd, content_tag(:a, grit_info[:branch], branch_link_attributes))
33
+ end
34
+
35
+ def commit_sha_info
36
+ content_tag(:dt, 'Commit:') +
37
+ content_tag(:dd, content_tag(:a, grit_info[:commit].try(:slice, 0,8), commit_link_attributes))
38
+ end
39
+
40
+ def commit_author_info
41
+ content_tag(:dt, 'Who:') + content_tag(:dd, grit_info[:last_author])
42
+ end
43
+
44
+ def commit_date_info
45
+ content_tag(:dt, 'When:') + content_tag(:dd, grit_info[:date].try(:to_s, :short), :title => grit_info[:date].to_s)
46
+ end
47
+
48
+ def rpm_request_info
49
+ if rpm_enabled?
50
+ content_tag(:dt, link_to('RPM', '/newrelic', :target => 'blank') + ':') <<
51
+ content_tag(:dd, link_to('request', rpm_url, :target => 'blank'))
52
+ end
53
+ end
54
+
55
+ def github_url
56
+ barkeep_config['github_url']
57
+ end
58
+
59
+ def grit_info
60
+ GritWrapper.instance
61
+ end
62
+
63
+ def branch_link_attributes
64
+ {
65
+ :href => "#{github_url}/tree/#{grit_info[:branch]}",
66
+ :title => grit_info[:message]
67
+ }
68
+ end
69
+
70
+ def commit_link_attributes
71
+ {
72
+ :href => "#{github_url}/commit/#{grit_info[:commit]}",
73
+ :title => "committed #{grit_info[:date]}"
74
+ }
75
+ end
76
+
77
+ def rpm_enabled?
78
+ if defined?(NewRelic)
79
+ if defined?(NewRelic::Control)
80
+ !NewRelic::Control.instance['skip_developer_route']
81
+ else
82
+ !NewRelic::Config.instance['skip_developer_route']
83
+ end
84
+ end
85
+ end
86
+
87
+ def rpm_url
88
+ rpm_id = NewRelic::Agent.instance.transaction_sampler.current_sample_id
89
+ "/newrelic/show_sample_detail/#{rpm_id}"
90
+ end
91
+ end
data/lib/default.css ADDED
@@ -0,0 +1,11 @@
1
+ #barkeep { margin: 0; padding: 0; background: #ffffcc; border: 1px solid #cccccc; bottom: 0; font-size: 11px; left: 0; position: fixed; -moz-opacity: 0.7; -khtml-opacity: 0.7; -o-opacity: 0.7; -webkit-opacity: 0.7; opacity: 0.7; *filter: alpha(opacity=70); width: 100%; z-index: 5000; }
2
+ * html #barkeep { postion: absolute; width: 99%; }
3
+ #barkeep dt, #barkeep dd { display: inline-block; list-style-type: none; margin: 0; font-size: 100%; font-family: Helvetica, Monaco, "Gill Sans", monospace; line-height: 2; padding: 0 0.5em 0 0.5em; }
4
+ * html #barkeep dt, * html #barkeep dd { zoom: 1; display: inline; }
5
+ html[lang~=en] #barkeep dt, html[lang~=en] #barkeep dd { display: inline; }
6
+ html[lang~=EN] #barkeep dt, html[lang~=EN] #barkeep dd { display: -moz-inline-box; display: inline-block; }
7
+ #barkeep dt { border-left: 1px solid #cccccc; }
8
+ #barkeep dd { color: black; }
9
+ #barkeep dd.close { position: absolute; right: 0; top: 0; }
10
+ #barkeep form { margin: 0; }
11
+ #barkeep select { font-family: Helvetica, Monaco, "Gill Sans", monospace; }
@@ -0,0 +1,51 @@
1
+ require 'grit'
2
+
3
+ # A singleton refreshes on every request in development but
4
+ # caches in environments where class caching is enabled.
5
+ require 'singleton'
6
+
7
+ class GritWrapper
8
+ include Singleton
9
+
10
+ def repository
11
+ @repository ||= Grit::Repo.new(Rails.root)
12
+ rescue Grit::InvalidGitRepositoryError
13
+ # not in a directory that contains .git
14
+ @repository = :invalid
15
+ end
16
+
17
+ def repository?
18
+ !repository.nil? && repository != :invalid
19
+ end
20
+
21
+ def head
22
+ @head ||= repository.head
23
+ end
24
+
25
+ def last_commit_hash
26
+ @last_commit_hash ||= head.commit.to_s
27
+ end
28
+
29
+ def last_commit
30
+ @last_commit ||= repository.commit(last_commit_hash)
31
+ end
32
+
33
+ def to_hash
34
+ return {
35
+ :branch => 'Not currently on a branch.',
36
+ :commit => (File.read(Rails.root + "/REVISION").strip rescue nil)
37
+ } if head.nil?
38
+
39
+ @hash ||= {
40
+ :branch => head.name,
41
+ :commit => last_commit_hash,
42
+ :last_author => last_commit.try(:author),
43
+ :message => last_commit.try(:message),
44
+ :date => last_commit.try(:authored_date)
45
+ }
46
+ end
47
+
48
+ def [](key)
49
+ to_hash[key]
50
+ end
51
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'mocha'
13
+ require 'active_support'
14
+ require 'action_pack'
15
+ require 'action_view'
16
+
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+ require 'barkeep'
20
+
21
+ class Test::Unit::TestCase
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestBarkeep < Test::Unit::TestCase
4
+ include ActionView::Helpers
5
+ include Barkeep
6
+
7
+ attr_accessor :output_buffer
8
+
9
+ should "render a style tag filled with css" do
10
+ css = File.read(File.expand_path(File.dirname(__FILE__) + "/../lib/default.css"))
11
+ assert_equal "<style>#{css}</style>", barkeep_styles
12
+ end
13
+
14
+ should "render the barkeep bar" do
15
+ stubs(:barkeep_config => {'github_url' => 'http://github.com/project_name', 'panes' => ['branch_info', 'commit_sha_info']})
16
+ GritWrapper.instance.stubs(:repository? => true, :to_hash => {:branch => 'new_branch', :commit => 'abcdef'})
17
+ expected = %(
18
+ <dl id="barkeep">
19
+ <dt>Branch:</dt>
20
+ <dd><a href="http://github.com/project_name/tree/new_branch">new_branch</a></dd>
21
+ <dt>Commit:</dt>
22
+ <dd><a href="http://github.com/project_name/commit/abcdef" title="committed ">abcdef</a></dd>
23
+ <dd class="close"><a href="#" onclick="c = document.getElementById('barkeep'); c.parentNode.removeChild(c); return false" title="Close me!">&times;</a></dd>
24
+ </dl>
25
+ )
26
+ assert_equal expected.gsub(/\n\s+/, ''), render_barkeep
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barkeep
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - PatientsLikeMe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-20 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: grit
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
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
81
+ - !ruby/object:Gem::Dependency
82
+ name: mocha
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 35
90
+ segments:
91
+ - 0
92
+ - 9
93
+ - 12
94
+ version: 0.9.12
95
+ type: :development
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: shoulda
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :development
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ prerelease: false
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 23
120
+ segments:
121
+ - 1
122
+ - 0
123
+ - 0
124
+ version: 1.0.0
125
+ type: :development
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: jeweler
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ hash: 7
136
+ segments:
137
+ - 1
138
+ - 5
139
+ - 2
140
+ version: 1.5.2
141
+ type: :development
142
+ version_requirements: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ name: rcov
145
+ prerelease: false
146
+ requirement: &id009 !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ type: :development
156
+ version_requirements: *id009
157
+ description: an extensible developer's status bar to track your current deployed commit & more
158
+ email: open_source@patientslikeme.com
159
+ executables: []
160
+
161
+ extensions: []
162
+
163
+ extra_rdoc_files:
164
+ - LICENSE.txt
165
+ - README.rdoc
166
+ files:
167
+ - lib/barkeep.rb
168
+ - lib/default.css
169
+ - lib/grit_wrapper.rb
170
+ - LICENSE.txt
171
+ - README.rdoc
172
+ - test/helper.rb
173
+ - test/test_barkeep.rb
174
+ has_rdoc: true
175
+ homepage: https://github.com/patientslikeme/barkeep
176
+ licenses:
177
+ - MIT
178
+ post_install_message:
179
+ rdoc_options: []
180
+
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ hash: 3
198
+ segments:
199
+ - 0
200
+ version: "0"
201
+ requirements: []
202
+
203
+ rubyforge_project:
204
+ rubygems_version: 1.6.2
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: an extensible developer's status bar to track your current deployed commit & more
208
+ test_files:
209
+ - test/helper.rb
210
+ - test/test_barkeep.rb