statusz 0.0.2 → 0.0.3
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.
- data/README.md +30 -12
- data/lib/statusz/version.rb +1 -1
- data/lib/statusz.erb +17 -15
- data/lib/statusz.rb +25 -33
- data/statusz.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Usage
|
|
27
27
|
``` ruby
|
28
28
|
# Somewhere in your deploy scripts, probably where you stage the files before you rsync them:
|
29
29
|
require "statusz"
|
30
|
-
Statusz.
|
30
|
+
Statusz.write_file("#{your_staging_root}/statusz.html")
|
31
31
|
```
|
32
32
|
|
33
33
|
Now you can serve up the file from your webserver however you like. If you have a public folder, you can drop
|
@@ -40,28 +40,47 @@ get "/statusz" do
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
-
If you want statusz to write a plain text file instead of an html file, you can do that:
|
43
|
+
If you want statusz to write a plain text file or json instead of an html file, you can do that:
|
44
44
|
|
45
45
|
``` ruby
|
46
|
-
Statusz.
|
46
|
+
Statusz.write_file("statusz.txt", :format => :text)
|
47
47
|
```
|
48
48
|
|
49
49
|
If you want statusz to only write some of the fields (skip `commit_search` to save space -- this field
|
50
50
|
contains every sha in your repo, so it can be kind of large):
|
51
51
|
|
52
52
|
``` ruby
|
53
|
-
Statusz.
|
53
|
+
Statusz.write_file("statusz.html", :fields => ["latest commit", "date", "git user info"])
|
54
54
|
```
|
55
55
|
|
56
56
|
Here are the possible fields -- by default, statusz will write them all:
|
57
57
|
|
58
|
-
* `
|
59
|
-
* `
|
60
|
-
* `
|
61
|
-
* `date` -- Timestamp
|
62
|
-
* `
|
63
|
-
* `
|
64
|
-
* `
|
58
|
+
* `"git directory"` -- The name of the directory at the git root
|
59
|
+
* `"latest commit"` -- The sha of the latest commit
|
60
|
+
* `"current branch"` -- The name of the branch, if any, from which the deploy is being run
|
61
|
+
* `"date"` -- Timestamp
|
62
|
+
* `"current user on deploy host"` -- The output of `whoami`
|
63
|
+
* `"git user info"` -- The user name and email in git
|
64
|
+
* `"all commits"` -- A list of all commits. In the html version, it's a search box.
|
65
|
+
|
66
|
+
Finally, statusz can write out extra arbitrary fields if you want. Just attach a hash of objects that have
|
67
|
+
meaningful `to_s` representations:
|
68
|
+
|
69
|
+
``` ruby
|
70
|
+
Statusz.write_file("statusz.html", :extra_fields => { "database host" => "dbslave3.example.com" })
|
71
|
+
```
|
72
|
+
|
73
|
+
Options
|
74
|
+
-------
|
75
|
+
|
76
|
+
The only method provided by statusz is `Statusz.write_file(filename = "./statusz.html", options)`. Here is a
|
77
|
+
full list of possible `options`:
|
78
|
+
|
79
|
+
* `:format` -- one of `:html`, `:text`, `:json` (defaults to `:html`).
|
80
|
+
* `:fields` -- an array; some subset of `["git directory", "latest commit", "current branch", "date", "current
|
81
|
+
user on deploy host", "git user info", "all commits"]` (defaults to the whole thing).
|
82
|
+
* `:extra_fields` -- a hash of arbitrary keys and values that will be stringified. You can override values in
|
83
|
+
`:fields` if you wish.
|
65
84
|
|
66
85
|
Screenshot
|
67
86
|
----------
|
@@ -72,4 +91,3 @@ TODO
|
|
72
91
|
----
|
73
92
|
|
74
93
|
* Call via command-line script? Useful if doing a non-ruby deploy.
|
75
|
-
* Other formats? (JSON?)
|
data/lib/statusz/version.rb
CHANGED
data/lib/statusz.erb
CHANGED
@@ -129,22 +129,24 @@
|
|
129
129
|
<% end %>
|
130
130
|
</table>
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
<% if html_values["all commits"] %>
|
133
|
+
<script type="text/javascript">
|
134
|
+
allCommits = [<%= html_values["all commits"].map { |sha| %Q{"#{sha}"} }.join(",") %>]
|
135
|
+
</script>
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
137
|
+
<table id="commit_search">
|
138
|
+
<tr>
|
139
|
+
<td>search for a commit:</td>
|
140
|
+
<td>
|
141
|
+
<input name="sha" onkeyup="commitSearch(this, event);" size="40" type="text" value="" />
|
142
|
+
</td>
|
143
|
+
</tr>
|
144
|
+
<tr>
|
145
|
+
<td>matches:</td>
|
146
|
+
<td id="search_results"></td>
|
147
|
+
</tr>
|
148
|
+
</table>
|
149
|
+
<% end %>
|
148
150
|
</div>
|
149
151
|
</body>
|
150
152
|
</html>
|
data/lib/statusz.rb
CHANGED
@@ -1,58 +1,50 @@
|
|
1
1
|
require "cgi"
|
2
2
|
require "erb"
|
3
3
|
require "time"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module Statusz
|
6
|
-
ALL_FIELDS = %w(git_directory latest_sha current_branch date username git_user_info commit_search)
|
7
|
-
|
8
7
|
FIELD_TO_SCRAPING_PROC = {
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
8
|
+
"git directory" => Proc.new { `git rev-parse --show-toplevel`.strip.rpartition("/").last },
|
9
|
+
"latest commit" => Proc.new { `git log --pretty=%H -n 1`.strip },
|
10
|
+
"current branch" => Proc.new do
|
12
11
|
branch = `git symbolic-ref HEAD 2> /dev/null`.strip.sub(%r{^refs/heads/}, "")
|
13
12
|
$?.to_i.zero? ? branch : "<no branch>"
|
14
13
|
end,
|
15
14
|
"date" => Proc.new { Time.now.strftime("%Y-%m-%d %H:%M:%S %z") },
|
16
|
-
"
|
17
|
-
"
|
15
|
+
"current user on deploy host" => Proc.new { `whoami`.strip },
|
16
|
+
"git user info" => Proc.new do
|
18
17
|
"#{`git config --get user.name`.strip} <#{`git config --get user.email`.strip}>"
|
19
18
|
end,
|
20
|
-
"
|
21
|
-
}
|
22
|
-
|
23
|
-
FIELD_TO_HEADER_NAME = {
|
24
|
-
"git_directory" => "git directory",
|
25
|
-
"latest_sha" => "latest commit",
|
26
|
-
"current_branch" => "current branch",
|
27
|
-
"date" => "date",
|
28
|
-
"username" => "current user on deploy host",
|
29
|
-
"git_user_info" => "git user info",
|
30
|
-
"commit_search" => "all commits"
|
19
|
+
"all commits" => Proc.new { `git log --pretty=%H`.strip }
|
31
20
|
}
|
32
21
|
|
33
|
-
def self.
|
22
|
+
def self.write_file(filename = "./statusz.html", options = {})
|
34
23
|
options[:format] ||= :html
|
35
|
-
raise "Bad format: #{options[:format]}" unless [:html, :text].include? options[:format]
|
36
|
-
options[:fields] ||=
|
37
|
-
bad_options = options[:fields] -
|
24
|
+
raise "Bad format: #{options[:format]}" unless [:html, :text, :json].include? options[:format]
|
25
|
+
options[:fields] ||= FIELD_TO_SCRAPING_PROC.keys
|
26
|
+
bad_options = options[:fields] - FIELD_TO_SCRAPING_PROC.keys
|
38
27
|
raise "Bad options: #{bad_options.inspect}" unless bad_options.empty?
|
28
|
+
extra_fields = options[:extra_fields] || {}
|
29
|
+
unless extra_fields.is_a? Hash
|
30
|
+
raise "Extra fields should be a hash, but #{extra_fields.inspect} (#{extra_fields.class}) was given."
|
31
|
+
end
|
39
32
|
|
40
33
|
results = {}
|
41
|
-
options[:fields].each
|
34
|
+
options[:fields].each do |field|
|
35
|
+
results[field] = FIELD_TO_SCRAPING_PROC[field].call
|
36
|
+
end
|
37
|
+
extra_fields.each { |field, value| results[field.to_s] = value.to_s }
|
42
38
|
|
43
39
|
case options[:format]
|
44
40
|
when :text
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
output = sections.join("\n\n")
|
41
|
+
output = results.map { |name, value| "#{name}:\n#{value}" }.join("\n\n")
|
42
|
+
when :json
|
43
|
+
output = results.to_json
|
49
44
|
when :html
|
50
|
-
html_values =
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
pair = { FIELD_TO_HEADER_NAME[field] => CGI.escapeHTML(FIELD_TO_SCRAPING_PROC[field].call) }
|
55
|
-
end
|
45
|
+
html_values = results.reduce({}) do |hash, field_and_value|
|
46
|
+
field, value = field_and_value
|
47
|
+
pair = (field == "all commits") ? { field => value.split("\n") } : { field => CGI.escapeHTML(value) }
|
56
48
|
hash.merge pair
|
57
49
|
end
|
58
50
|
output = ERB.new(File.read(File.join(File.dirname(__FILE__), "statusz.erb"))).result(binding)
|
data/statusz.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["cespare@gmail.com"]
|
7
7
|
gem.description = "statusz is a gem that writes out git metadata at deploy time."
|
8
8
|
gem.summary = "statusz is a gem that writes out git metadata at deploy time."
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/ooyala/statusz"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statusz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,7 +27,7 @@ files:
|
|
27
27
|
- lib/statusz.rb
|
28
28
|
- lib/statusz/version.rb
|
29
29
|
- statusz.gemspec
|
30
|
-
homepage:
|
30
|
+
homepage: https://github.com/ooyala/statusz
|
31
31
|
licenses: []
|
32
32
|
post_install_message:
|
33
33
|
rdoc_options: []
|