rack-git_sha 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/rack/git_sha/version.rb +5 -0
- data/lib/rack/git_sha.rb +46 -0
- data/lib/rack-git_sha.rb +1 -0
- data/rack-git_sha.gemspec +20 -0
- data/spec/fixtures/REVISION +1 -0
- data/spec/rack-git_sha_spec.rb +53 -0
- data/spec/spec_helper.rb +15 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Chris Mytton
|
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,29 @@
|
|
1
|
+
# Rack::GitSha
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rack-git_sha'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rack-git_sha
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rack/git_sha.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rack/git_sha/version'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class GitSha
|
6
|
+
def initialize(root = Dir.pwd)
|
7
|
+
@root = Pathname.new(root)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
if revision_file.exist?
|
12
|
+
ok revision_file.read
|
13
|
+
elsif git_repository?
|
14
|
+
ok git_current_commit_sha
|
15
|
+
else
|
16
|
+
not_found 'Could not determine SHA'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def revision_file
|
23
|
+
@root.join('REVISION')
|
24
|
+
end
|
25
|
+
|
26
|
+
def git_repository?
|
27
|
+
@root.join('.git').directory?
|
28
|
+
end
|
29
|
+
|
30
|
+
def git_current_commit_sha
|
31
|
+
`git rev-parse HEAD`
|
32
|
+
end
|
33
|
+
|
34
|
+
def ok(response)
|
35
|
+
[200, headers, [response]]
|
36
|
+
end
|
37
|
+
|
38
|
+
def not_found(response)
|
39
|
+
[404, headers, [response]]
|
40
|
+
end
|
41
|
+
|
42
|
+
def headers
|
43
|
+
{'Content-Type' => 'text/plain'}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rack-git_sha.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/git_sha'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rack/git_sha/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chris Mytton"]
|
6
|
+
gem.email = ["self@hecticjeff.net"]
|
7
|
+
gem.description = %q{Serve up the current git commit SHA from rack}
|
8
|
+
gem.summary = %q{Tiny rack application that serves up the currently deployed git commit SHA}
|
9
|
+
gem.homepage = "https://github.com/hecticjeff/rack-git_sha"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "rack-git_sha"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rack::GitSha::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.8.0'
|
19
|
+
gem.add_development_dependency 'rack-test', '~> 0.6.1'
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
git-sha-goes-here
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::GitSha do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
describe "GET /" do
|
7
|
+
context "with no path" do
|
8
|
+
def app
|
9
|
+
Rack::GitSha.new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
get '/'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is successful" do
|
17
|
+
last_response.status.should == 200
|
18
|
+
end
|
19
|
+
|
20
|
+
it "serves the current git commit sha" do
|
21
|
+
last_response.body.should == `git rev-parse HEAD`
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with path" do
|
25
|
+
def app
|
26
|
+
Rack::GitSha.new File.expand_path('../fixtures', __FILE__)
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
get '/'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "uses the REVISION file" do
|
34
|
+
last_response.body.should == "git-sha-goes-here\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with path that isn't git root or have REVISION file" do
|
39
|
+
def app
|
40
|
+
Rack::GitSha.new File.dirname(__FILE__)
|
41
|
+
end
|
42
|
+
|
43
|
+
before do
|
44
|
+
get '/'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns a 404" do
|
48
|
+
last_response.status.should == 404
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'rack/test'
|
9
|
+
require 'rack/git_sha'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-git_sha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Mytton
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70309363854700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70309363854700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
requirement: &70309363854180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.6.1
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70309363854180
|
36
|
+
description: Serve up the current git commit SHA from rack
|
37
|
+
email:
|
38
|
+
- self@hecticjeff.net
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/rack-git_sha.rb
|
49
|
+
- lib/rack/git_sha.rb
|
50
|
+
- lib/rack/git_sha/version.rb
|
51
|
+
- rack-git_sha.gemspec
|
52
|
+
- spec/fixtures/REVISION
|
53
|
+
- spec/rack-git_sha_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
homepage: https://github.com/hecticjeff/rack-git_sha
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.15
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Tiny rack application that serves up the currently deployed git commit SHA
|
79
|
+
test_files:
|
80
|
+
- spec/fixtures/REVISION
|
81
|
+
- spec/rack-git_sha_spec.rb
|
82
|
+
- spec/spec_helper.rb
|