statusz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/lib/statusz/version.rb +3 -0
- data/lib/statusz.erb +150 -0
- data/lib/statusz.rb +62 -0
- data/statusz.gemspec +17 -0
- metadata +53 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ooyala, Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
statusz
|
2
|
+
=======
|
3
|
+
|
4
|
+
statusz is a Ruby tool to write out git information when you deploy. It is useful if your project
|
5
|
+
meets the following criteria:
|
6
|
+
|
7
|
+
* It lives in git (required)
|
8
|
+
* It uses some kind of ruby-based deployment system (not strictly necessary, because you can call statusz via
|
9
|
+
the command-line if you want, but this still requires Ruby to run).
|
10
|
+
* It is a web server that can serve up web pages (also not necessary; if this isn't the case, statusz can
|
11
|
+
write out a plain text file for you instead).
|
12
|
+
|
13
|
+
statusz helps you quickly tell what version of the code is actually running on your server, and who most
|
14
|
+
recently deployed it. It's particularly useful in environments where developers deploy the code.
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
18
|
+
|
19
|
+
gem install statusz
|
20
|
+
|
21
|
+
statusz requires Ruby -- it's tested with 1.9.2, but probably works with 1.8.7 and 1.9.3 and many other
|
22
|
+
versions as well.
|
23
|
+
|
24
|
+
Usage
|
25
|
+
-----
|
data/Rakefile
ADDED
data/lib/statusz.erb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
|
5
|
+
<title>statusz</title>
|
6
|
+
|
7
|
+
<style type="text/css">
|
8
|
+
* {
|
9
|
+
margin: 0;
|
10
|
+
padding: 0;
|
11
|
+
}
|
12
|
+
*:focus { outline: none; }
|
13
|
+
body {
|
14
|
+
text-align: center;
|
15
|
+
background-color: #ddd;
|
16
|
+
color: #555;
|
17
|
+
font: 16px Arial, "Helvetica Neue", Helvetica, sans-serif;
|
18
|
+
}
|
19
|
+
h1 {
|
20
|
+
font-size: 40px;
|
21
|
+
font-weight: normal;
|
22
|
+
text-align: center;
|
23
|
+
margin: 20px 0;
|
24
|
+
}
|
25
|
+
#wrapper {
|
26
|
+
background-color: #f8f8f8;
|
27
|
+
width: 650px;
|
28
|
+
margin: 20px auto;
|
29
|
+
border: 3px dashed #555;
|
30
|
+
padding: 10px 20px;
|
31
|
+
}
|
32
|
+
#fields {
|
33
|
+
width: 100%;
|
34
|
+
border-collapse: collapse;
|
35
|
+
}
|
36
|
+
#fields tr {
|
37
|
+
height: 20px;
|
38
|
+
border-bottom: 1px solid transparent
|
39
|
+
}
|
40
|
+
#fields tr:hover { border-bottom-color: #555; }
|
41
|
+
#fields td { padding: 4px; }
|
42
|
+
#fields td:first-child {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
}
|
46
|
+
#fields td:last-child {
|
47
|
+
text-align: right;
|
48
|
+
font: 14px Consolas, "Lucida Console", Monaco, monospace;
|
49
|
+
}
|
50
|
+
#all_commits { display: none; }
|
51
|
+
#commit_search { margin: 20px auto; }
|
52
|
+
#commit_search td:first-child {
|
53
|
+
padding-right: 10px;
|
54
|
+
text-align: left;
|
55
|
+
font-weight: bold;
|
56
|
+
}
|
57
|
+
#commit_search tr:last-child {
|
58
|
+
vertical-align: top;
|
59
|
+
display: none;
|
60
|
+
}
|
61
|
+
#commit_search tr:last-child > td { padding-top: 5px; }
|
62
|
+
#commit_search input {
|
63
|
+
font: 14px Consolas, "Lucida Console", Monaco, monospace;
|
64
|
+
border: 1px solid #555;
|
65
|
+
padding: 2px;
|
66
|
+
background-color: transparent;
|
67
|
+
}
|
68
|
+
#search_results {
|
69
|
+
padding-left: 4px;
|
70
|
+
text-align: left;
|
71
|
+
}
|
72
|
+
#search_results > .sha { font: 14px/20px Consolas, "Lucida Console", Monaco, monospace; }
|
73
|
+
</style>
|
74
|
+
|
75
|
+
<script type="text/javascript">
|
76
|
+
function commitSearch(field, e) {
|
77
|
+
var text = $(field).val();
|
78
|
+
var $resultsContainer = $("#search_results");
|
79
|
+
$resultsContainer.empty();
|
80
|
+
if (text == "") {
|
81
|
+
$("#commit_search tr:last-child").hide();
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
if (!/^[a-f0-9]{0,40}$/.test(text)) {
|
85
|
+
$resultsContainer.text("No match.");
|
86
|
+
$("#commit_search tr:last-child").show();
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
var matches = [];
|
90
|
+
for (var i = 0; i < allCommits.length; i++) {
|
91
|
+
var sha = allCommits[i];
|
92
|
+
if (sha.indexOf(text) == 0) {
|
93
|
+
matches.push(sha);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
if (matches.length == 0) {
|
97
|
+
$resultsContainer.text("No match.");
|
98
|
+
$("#commit_search tr:last-child").show();
|
99
|
+
return;
|
100
|
+
} else {
|
101
|
+
for (var i = 0; i < matches.length; i++) {
|
102
|
+
if (i >= 10) {
|
103
|
+
$resultsContainer.append("<div>… (" + (matches.length - 10) + " more hidden results)</div>");
|
104
|
+
break;
|
105
|
+
}
|
106
|
+
$resultsContainer.append("<div class='sha'>" + matches[i] + "</div>");
|
107
|
+
}
|
108
|
+
$("#commit_search tr:last-child").show();
|
109
|
+
}
|
110
|
+
}
|
111
|
+
</script>
|
112
|
+
</head>
|
113
|
+
|
114
|
+
<body>
|
115
|
+
<div id="wrapper">
|
116
|
+
<h1>statusz</h1>
|
117
|
+
|
118
|
+
<table id="fields">
|
119
|
+
<% commit_search = false %>
|
120
|
+
<% html_values.each do |field, value| %>
|
121
|
+
<% if field == "all commits" %>
|
122
|
+
<% commit_search = true %>
|
123
|
+
<% next %>
|
124
|
+
<% end %>
|
125
|
+
<tr>
|
126
|
+
<td><%= field %></td>
|
127
|
+
<td><%= value %></td>
|
128
|
+
</tr>
|
129
|
+
<% end %>
|
130
|
+
</table>
|
131
|
+
|
132
|
+
<script type="text/javascript">
|
133
|
+
allCommits = [<%= html_values["all commits"].map { |sha| %Q{"#{sha}"} }.join(",") %>]
|
134
|
+
</script>
|
135
|
+
|
136
|
+
<table id="commit_search">
|
137
|
+
<tr>
|
138
|
+
<td>search for a commit:</td>
|
139
|
+
<td>
|
140
|
+
<input name="sha" onkeyup="commitSearch(this, event);" size="40" type="text" value="" />
|
141
|
+
</td>
|
142
|
+
</tr>
|
143
|
+
<tr>
|
144
|
+
<td>matches:</td>
|
145
|
+
<td id="search_results"></td>
|
146
|
+
</tr>
|
147
|
+
</table>
|
148
|
+
</div>
|
149
|
+
</body>
|
150
|
+
</html>
|
data/lib/statusz.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
module Statusz
|
5
|
+
ALL_FIELDS = %w(git_directory latest_sha current_branch date username git_user_info commit_search)
|
6
|
+
|
7
|
+
FIELD_TO_SCRAPING_PROC = {
|
8
|
+
"git_directory" => Proc.new { `git rev-parse --show-toplevel`.strip.rpartition("/").last },
|
9
|
+
"latest_sha" => Proc.new { `git log --pretty=%H -n 1`.strip },
|
10
|
+
"current_branch" => Proc.new do
|
11
|
+
branch = `git symbolic-ref HEAD 2> /dev/null`.strip.sub(%r{^refs/heads/}, "")
|
12
|
+
$?.to_i.zero? ? branch : "<no branch>"
|
13
|
+
end,
|
14
|
+
"date" => Proc.new { Time.now.strftime("%Y-%m-%d %H:%M:%S %z") },
|
15
|
+
"username" => Proc.new { `whoami`.strip },
|
16
|
+
"git_user_info" => Proc.new do
|
17
|
+
"#{`git config --get user.name`.strip} <#{`git config --get user.email`.strip}>"
|
18
|
+
end,
|
19
|
+
"commit_search" => Proc.new { `git log --pretty=%H`.strip }
|
20
|
+
}
|
21
|
+
|
22
|
+
FIELD_TO_HEADER_NAME = {
|
23
|
+
"git_directory" => "git directory",
|
24
|
+
"latest_sha" => "latest commit",
|
25
|
+
"current_branch" => "current branch",
|
26
|
+
"date" => "date",
|
27
|
+
"username" => "current user on deploy host",
|
28
|
+
"git_user_info" => "git user info",
|
29
|
+
"commit_search" => "all commits"
|
30
|
+
}
|
31
|
+
|
32
|
+
def self.write_git_metadata(filename = "./statusz.html", options = {})
|
33
|
+
options[:format] ||= :html
|
34
|
+
raise "Bad format: #{options[:format]}" unless [:html, :text].include? options[:format]
|
35
|
+
options[:fields] ||= ALL_FIELDS
|
36
|
+
bad_options = options[:fields] - ALL_FIELDS
|
37
|
+
raise "Bad options: #{bad_options.inspect}" unless bad_options.empty?
|
38
|
+
|
39
|
+
results = {}
|
40
|
+
options[:fields].each { |field| results[field] = FIELD_TO_SCRAPING_PROC[field].call }
|
41
|
+
|
42
|
+
case options[:format]
|
43
|
+
when :text
|
44
|
+
sections = options[:fields].map do |field|
|
45
|
+
"#{FIELD_TO_HEADER_NAME[field]}:\n#{results[field]}"
|
46
|
+
end
|
47
|
+
output = sections.join("\n\n")
|
48
|
+
when :html
|
49
|
+
html_values = options[:fields].reduce({}) do |hash, field|
|
50
|
+
if field == "commit_search"
|
51
|
+
pair = { FIELD_TO_HEADER_NAME[field] => FIELD_TO_SCRAPING_PROC[field].call.split("\n") }
|
52
|
+
else
|
53
|
+
pair = { FIELD_TO_HEADER_NAME[field] => FIELD_TO_SCRAPING_PROC[field].call }
|
54
|
+
end
|
55
|
+
hash.merge pair
|
56
|
+
end
|
57
|
+
output = ERB.new(File.read(File.join(File.dirname(__FILE__), "statusz.erb"))).result(binding)
|
58
|
+
end
|
59
|
+
|
60
|
+
File.open(filename, "w") { |file| file.puts output }
|
61
|
+
end
|
62
|
+
end
|
data/statusz.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/statusz/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Caleb Spare"]
|
6
|
+
gem.email = ["cespare@gmail.com"]
|
7
|
+
gem.description = "statusz is a gem that writes out git metadata at deploy time."
|
8
|
+
gem.summary = "statusz is a gem that writes out git metadata at deploy time."
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "statusz"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Statusz::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: statusz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Caleb Spare
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-06 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: statusz is a gem that writes out git metadata at deploy time.
|
15
|
+
email:
|
16
|
+
- cespare@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/statusz.erb
|
26
|
+
- lib/statusz.rb
|
27
|
+
- lib/statusz/version.rb
|
28
|
+
- statusz.gemspec
|
29
|
+
homepage: ''
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.10
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: statusz is a gem that writes out git metadata at deploy time.
|
53
|
+
test_files: []
|